diff --git a/crates/rome_cli/src/traversal.rs b/crates/rome_cli/src/traversal.rs index ffa74bdf8c6..636140ceb08 100644 --- a/crates/rome_cli/src/traversal.rs +++ b/crates/rome_cli/src/traversal.rs @@ -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, }; @@ -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 diff --git a/crates/rome_cli/tests/main.rs b/crates/rome_cli/tests/main.rs index b4da331714b..9545bf50d51 100644 --- a/crates/rome_cli/tests/main.rs +++ b/crates/rome_cli/tests/main.rs @@ -540,6 +540,7 @@ mod check { mod ci { use super::*; + use crate::configs::{CONFIG_DISABLED_FORMATTER, CONFIG_LINTER_DISABLED}; use rome_fs::FileSystemExt; #[test] @@ -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 { diff --git a/crates/rome_cli/tests/snapshots/main_check/apply_noop.snap b/crates/rome_cli/tests/snapshots/main_check/apply_noop.snap index 2b9da6ddecf..d4f9f1a35c8 100644 --- a/crates/rome_cli/tests/snapshots/main_check/apply_noop.snap +++ b/crates/rome_cli/tests/snapshots/main_check/apply_noop.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 147 expression: content --- ## `fix.js` diff --git a/crates/rome_cli/tests/snapshots/main_check/apply_ok.snap b/crates/rome_cli/tests/snapshots/main_check/apply_ok.snap index 2b9da6ddecf..d4f9f1a35c8 100644 --- a/crates/rome_cli/tests/snapshots/main_check/apply_ok.snap +++ b/crates/rome_cli/tests/snapshots/main_check/apply_ok.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 147 expression: content --- ## `fix.js` diff --git a/crates/rome_cli/tests/snapshots/main_check/downgrade_severity.snap b/crates/rome_cli/tests/snapshots/main_check/downgrade_severity.snap index 7f47775cf2b..9855384667b 100644 --- a/crates/rome_cli/tests/snapshots/main_check/downgrade_severity.snap +++ b/crates/rome_cli/tests/snapshots/main_check/downgrade_severity.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 147 expression: content --- ## `rome.json` diff --git a/crates/rome_cli/tests/snapshots/main_check/lint_error.snap b/crates/rome_cli/tests/snapshots/main_check/lint_error.snap index f0f86a4aa06..b4ee7e844e7 100644 --- a/crates/rome_cli/tests/snapshots/main_check/lint_error.snap +++ b/crates/rome_cli/tests/snapshots/main_check/lint_error.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 147 expression: content --- ## `check.js` diff --git a/crates/rome_cli/tests/snapshots/main_check/maximum_diagnostics.snap b/crates/rome_cli/tests/snapshots/main_check/maximum_diagnostics.snap index af2a9a8dbba..fd8cd032d4a 100644 --- a/crates/rome_cli/tests/snapshots/main_check/maximum_diagnostics.snap +++ b/crates/rome_cli/tests/snapshots/main_check/maximum_diagnostics.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 147 expression: content --- ## `check.js` diff --git a/crates/rome_cli/tests/snapshots/main_check/no_lint_if_linter_is_disabled.snap b/crates/rome_cli/tests/snapshots/main_check/no_lint_if_linter_is_disabled.snap index 239cd4cc6ec..6b462baaded 100644 --- a/crates/rome_cli/tests/snapshots/main_check/no_lint_if_linter_is_disabled.snap +++ b/crates/rome_cli/tests/snapshots/main_check/no_lint_if_linter_is_disabled.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 148 expression: content --- ## `rome.json` diff --git a/crates/rome_cli/tests/snapshots/main_check/no_lint_if_linter_is_disabled_when_run_apply.snap b/crates/rome_cli/tests/snapshots/main_check/no_lint_if_linter_is_disabled_when_run_apply.snap index 239cd4cc6ec..6b462baaded 100644 --- a/crates/rome_cli/tests/snapshots/main_check/no_lint_if_linter_is_disabled_when_run_apply.snap +++ b/crates/rome_cli/tests/snapshots/main_check/no_lint_if_linter_is_disabled_when_run_apply.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 148 expression: content --- ## `rome.json` diff --git a/crates/rome_cli/tests/snapshots/main_check/parse_error.snap b/crates/rome_cli/tests/snapshots/main_check/parse_error.snap index c9711a091ee..46a4e1f195f 100644 --- a/crates/rome_cli/tests/snapshots/main_check/parse_error.snap +++ b/crates/rome_cli/tests/snapshots/main_check/parse_error.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 147 expression: content --- ## `check.js` diff --git a/crates/rome_cli/tests/snapshots/main_ci/ci_does_not_run_formatter.snap b/crates/rome_cli/tests/snapshots/main_ci/ci_does_not_run_formatter.snap new file mode 100644 index 00000000000..ad13a9742ad --- /dev/null +++ b/crates/rome_cli/tests/snapshots/main_ci/ci_does_not_run_formatter.snap @@ -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 + + diff --git a/crates/rome_cli/tests/snapshots/main_ci/ci_does_not_run_linter.snap b/crates/rome_cli/tests/snapshots/main_ci/ci_does_not_run_linter.snap new file mode 100644 index 00000000000..a0659a282a5 --- /dev/null +++ b/crates/rome_cli/tests/snapshots/main_ci/ci_does_not_run_linter.snap @@ -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 | } + +``` + + diff --git a/crates/rome_cli/tests/snapshots/main_ci/ci_lint_error.snap b/crates/rome_cli/tests/snapshots/main_ci/ci_lint_error.snap index f4c2df12003..f7c082c10fa 100644 --- a/crates/rome_cli/tests/snapshots/main_ci/ci_lint_error.snap +++ b/crates/rome_cli/tests/snapshots/main_ci/ci_lint_error.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 147 expression: content --- ## `ci.js` diff --git a/crates/rome_cli/tests/snapshots/main_ci/ci_parse_error.snap b/crates/rome_cli/tests/snapshots/main_ci/ci_parse_error.snap index 009e73f221e..7596ec854e4 100644 --- a/crates/rome_cli/tests/snapshots/main_ci/ci_parse_error.snap +++ b/crates/rome_cli/tests/snapshots/main_ci/ci_parse_error.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 147 expression: content --- ## `ci.js` diff --git a/crates/rome_cli/tests/snapshots/main_ci/formatting_error.snap b/crates/rome_cli/tests/snapshots/main_ci/formatting_error.snap index 8e13621c21b..c6e57063b43 100644 --- a/crates/rome_cli/tests/snapshots/main_ci/formatting_error.snap +++ b/crates/rome_cli/tests/snapshots/main_ci/formatting_error.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 147 expression: content --- ## `ci.js` diff --git a/crates/rome_cli/tests/snapshots/main_format/does_not_format_if_disabled.snap b/crates/rome_cli/tests/snapshots/main_format/does_not_format_if_disabled.snap index 9aa32a46856..a4a6f133801 100644 --- a/crates/rome_cli/tests/snapshots/main_format/does_not_format_if_disabled.snap +++ b/crates/rome_cli/tests/snapshots/main_format/does_not_format_if_disabled.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 147 expression: content --- ## `rome.json` diff --git a/crates/rome_cli/tests/snapshots/main_format/format_is_disabled.snap b/crates/rome_cli/tests/snapshots/main_format/format_is_disabled.snap index 46e7ba42783..d0cc3bc1a8f 100644 --- a/crates/rome_cli/tests/snapshots/main_format/format_is_disabled.snap +++ b/crates/rome_cli/tests/snapshots/main_format/format_is_disabled.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 148 expression: content --- ## `rome.json` diff --git a/crates/rome_cli/tests/snapshots/main_format/format_stdin_successfully.snap b/crates/rome_cli/tests/snapshots/main_format/format_stdin_successfully.snap index c802107e646..182693a0d97 100644 --- a/crates/rome_cli/tests/snapshots/main_format/format_stdin_successfully.snap +++ b/crates/rome_cli/tests/snapshots/main_format/format_stdin_successfully.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 147 expression: content --- # Input messages diff --git a/crates/rome_cli/tests/snapshots/main_format/formatter_lint_warning.snap b/crates/rome_cli/tests/snapshots/main_format/formatter_lint_warning.snap index 3d2cf29ee86..6efe4255d87 100644 --- a/crates/rome_cli/tests/snapshots/main_format/formatter_lint_warning.snap +++ b/crates/rome_cli/tests/snapshots/main_format/formatter_lint_warning.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 147 expression: content --- ## `format.js` diff --git a/crates/rome_cli/tests/snapshots/main_format/formatter_print.snap b/crates/rome_cli/tests/snapshots/main_format/formatter_print.snap index 3c4f9caf7a3..85a3c9d9f7e 100644 --- a/crates/rome_cli/tests/snapshots/main_format/formatter_print.snap +++ b/crates/rome_cli/tests/snapshots/main_format/formatter_print.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 147 expression: content --- ## `format.js` diff --git a/crates/rome_cli/tests/snapshots/main_init/creates_config_file.snap b/crates/rome_cli/tests/snapshots/main_init/creates_config_file.snap index aedd391f70c..bb5de1b7955 100644 --- a/crates/rome_cli/tests/snapshots/main_init/creates_config_file.snap +++ b/crates/rome_cli/tests/snapshots/main_init/creates_config_file.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 147 expression: content --- ## `rome.json` diff --git a/crates/rome_cli/tests/snapshots/main_reporter_json/reports_formatter_check_mode.snap b/crates/rome_cli/tests/snapshots/main_reporter_json/reports_formatter_check_mode.snap index 0aed631d285..496f2eef149 100644 --- a/crates/rome_cli/tests/snapshots/main_reporter_json/reports_formatter_check_mode.snap +++ b/crates/rome_cli/tests/snapshots/main_reporter_json/reports_formatter_check_mode.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 148 expression: content --- ## `format.js` diff --git a/crates/rome_cli/tests/snapshots/main_reporter_json/reports_formatter_write.snap b/crates/rome_cli/tests/snapshots/main_reporter_json/reports_formatter_write.snap index e7a09c9c439..7da4033d926 100644 --- a/crates/rome_cli/tests/snapshots/main_reporter_json/reports_formatter_write.snap +++ b/crates/rome_cli/tests/snapshots/main_reporter_json/reports_formatter_write.snap @@ -1,6 +1,5 @@ --- source: crates/rome_cli/tests/snap_test.rs -assertion_line: 148 expression: content --- ## `format.js`