Skip to content

Commit

Permalink
fix(rome_cli): do not pull diagnostics if linter is turned off (rome#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Sep 7, 2022
1 parent 6e717fd commit dcc1d72
Show file tree
Hide file tree
Showing 23 changed files with 132 additions and 21 deletions.
5 changes: 3 additions & 2 deletions crates/rome_cli/src/traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,10 @@ fn process_file(ctx: &TraversalOptions, path: &Path, file_id: FileId) -> FileRes
tracing::trace_span!("process_file", path = ?path).in_scope(move || {
let rome_path = RomePath::new(path, file_id);
let can_format = ctx.can_format(&rome_path);
let can_lint = ctx.can_lint(&rome_path);
let can_handle = match ctx.execution.traversal_mode() {
TraversalMode::Check { .. } => ctx.can_lint(&rome_path),
TraversalMode::CI { .. } => ctx.can_lint(&rome_path) || can_format,
TraversalMode::CI { .. } => can_lint || can_format,
TraversalMode::Format { .. } => can_format,
};

Expand Down Expand Up @@ -598,7 +599,7 @@ fn process_file(ctx: &TraversalOptions, path: &Path, file_id: FileId) -> FileRes
return Ok(FileStatus::Ignored);
}

let categories = if ctx.execution.is_format() {
let categories = if ctx.execution.is_format() || !can_lint {
RuleCategories::SYNTAX
} else {
RuleCategories::SYNTAX | RuleCategories::LINT
Expand Down
67 changes: 67 additions & 0 deletions crates/rome_cli/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ mod check {

mod ci {
use super::*;
use crate::configs::{CONFIG_DISABLED_FORMATTER, CONFIG_LINTER_DISABLED};
use rome_fs::FileSystemExt;

#[test]
Expand Down Expand Up @@ -642,6 +643,72 @@ mod ci {

assert_cli_snapshot(module_path!(), "ci_lint_error", fs, console);
}

#[test]
fn ci_does_not_run_formatter() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let file_path = Path::new("rome.json");
fs.insert(file_path.into(), CONFIG_DISABLED_FORMATTER.as_bytes());

let file_path = Path::new("file.js");
fs.insert(file_path.into(), UNFORMATTED.as_bytes());

let result = run_cli(
DynRef::Borrowed(&mut fs),
DynRef::Borrowed(&mut console),
Arguments::from_vec(vec![OsString::from("ci"), file_path.as_os_str().into()]),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

let mut file = fs
.open(file_path)
.expect("formatting target file was removed by the CLI");

let mut content = String::new();
file.read_to_string(&mut content)
.expect("failed to read file from memory FS");

assert_eq!(content, UNFORMATTED);

drop(file);
assert_cli_snapshot(module_path!(), "ci_does_not_run_formatter", fs, console);
}

#[test]
fn ci_does_not_run_linter() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let file_path = Path::new("rome.json");
fs.insert(file_path.into(), CONFIG_LINTER_DISABLED.as_bytes());

let file_path = Path::new("file.js");
fs.insert(file_path.into(), CUSTOM_FORMAT_BEFORE.as_bytes());

let result = run_cli(
DynRef::Borrowed(&mut fs),
DynRef::Borrowed(&mut console),
Arguments::from_vec(vec![OsString::from("ci"), file_path.as_os_str().into()]),
);

assert!(result.is_err(), "run_cli returned {result:?}");

let mut file = fs
.open(file_path)
.expect("formatting target file was removed by the CLI");

let mut content = String::new();
file.read_to_string(&mut content)
.expect("failed to read file from memory FS");

assert_eq!(content, CUSTOM_FORMAT_BEFORE);

drop(file);
assert_cli_snapshot(module_path!(), "ci_does_not_run_linter", fs, console);
}
}

mod format {
Expand Down
1 change: 0 additions & 1 deletion crates/rome_cli/tests/snapshots/main_check/apply_noop.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 147
expression: content
---
## `fix.js`
Expand Down
1 change: 0 additions & 1 deletion crates/rome_cli/tests/snapshots/main_check/apply_ok.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 147
expression: content
---
## `fix.js`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 147
expression: content
---
## `rome.json`
Expand Down
1 change: 0 additions & 1 deletion crates/rome_cli/tests/snapshots/main_check/lint_error.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 147
expression: content
---
## `check.js`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 147
expression: content
---
## `check.js`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 148
expression: content
---
## `rome.json`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 148
expression: content
---
## `rome.json`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 147
expression: content
---
## `check.js`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
source: crates/rome_cli/tests/snap_test.rs
expression: content
---
## `rome.json`

```json
{
"formatter": {
"enabled": false
}
}

```

## `file.js`

```js
statement( )
```

# Emitted Messages


Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
source: crates/rome_cli/tests/snap_test.rs
expression: content
---
## `rome.json`

```json
{
"linter": {
"enabled": false
}
}
```

## `file.js`

```js

function f() {
return { something }
}

```

# Emitted Messages

```block
file.js: error[CI]: File content differs from formatting output
| @@ -1,4 +1,3 @@
0 | -
1 0 | function f() {
2 | - return { something }
1 | + return { something };
3 2 | }
```


1 change: 0 additions & 1 deletion crates/rome_cli/tests/snapshots/main_ci/ci_lint_error.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 147
expression: content
---
## `ci.js`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 147
expression: content
---
## `ci.js`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 147
expression: content
---
## `ci.js`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 147
expression: content
---
## `rome.json`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 148
expression: content
---
## `rome.json`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 147
expression: content
---
# Input messages
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 147
expression: content
---
## `format.js`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 147
expression: content
---
## `format.js`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 147
expression: content
---
## `rome.json`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 148
expression: content
---
## `format.js`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 148
expression: content
---
## `format.js`
Expand Down

0 comments on commit dcc1d72

Please sign in to comment.