diff --git a/CHANGELOG.md b/CHANGELOG.md index 56860554f3c..c48bd5d8596 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,13 +19,20 @@ - The command `rome check` now shows formatter diagnostics when checking the code. - Fix [#4556](https://github.com/rome/tools/issues/4556), which correctly handles new lines in the `.gitignore` file across OS. -- Add a new option to ignore unknown files. +- Add a new option to ignore unknown files `--files-ignore-unknown`: ```shell - rome format ./src --files-ignore-unknown=true + rome format ./src --files-ignore-unknown ``` Doing so, Rome won't emit diagnostics for files that doesn't know how to handle. +- Add a new option `--no-errors-on-unmatched`: + + ```shell + rome format ./src --no-errors-on-unmatched + ``` + + Rome won't exit with an error code in case no files were processed in the given paths. ### Configuration diff --git a/crates/rome_cli/src/cli_options.rs b/crates/rome_cli/src/cli_options.rs index 5bc02348768..0e8f0544b55 100644 --- a/crates/rome_cli/src/cli_options.rs +++ b/crates/rome_cli/src/cli_options.rs @@ -28,6 +28,10 @@ pub struct CliOptions { #[bpaf(long("skip-errors"), switch)] pub skip_errors: bool, + /// Silence errors that would be emitted in case no files were processed during the execution of the command. + #[bpaf(long("no-errors-on-unmatched"), switch)] + pub no_errors_on_unmatched: bool, + /// Reports information using the JSON format #[bpaf(long("json"), switch, hide_usage)] pub json: bool, diff --git a/crates/rome_cli/src/execute/traverse.rs b/crates/rome_cli/src/execute/traverse.rs index 73502179814..ca163d70633 100644 --- a/crates/rome_cli/src/execute/traverse.rs +++ b/crates/rome_cli/src/execute/traverse.rs @@ -202,7 +202,7 @@ pub(crate) fn traverse( } // Processing emitted error diagnostics, exit with a non-zero code - if count.saturating_sub(skipped) == 0 { + if count.saturating_sub(skipped) == 0 && !cli_options.no_errors_on_unmatched { Err(CliDiagnostic::no_files_processed()) } else if errors > 0 { if execution.is_check_apply() { diff --git a/crates/rome_cli/tests/commands/check.rs b/crates/rome_cli/tests/commands/check.rs index 2b23abba829..14416c0e0fb 100644 --- a/crates/rome_cli/tests/commands/check.rs +++ b/crates/rome_cli/tests/commands/check.rs @@ -2441,3 +2441,25 @@ fn check_json_files() { result, )); } + +#[test] +fn doesnt_error_if_no_files_were_processed() { + let mut console = BufferConsole::default(); + let mut fs = MemoryFileSystem::default(); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(&[("check"), "--no-errors-on-unmatched", ("file.js")]), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "doesnt_error_if_no_files_were_processed", + fs, + console, + result, + )); +} diff --git a/crates/rome_cli/tests/commands/ci.rs b/crates/rome_cli/tests/commands/ci.rs index 2419a88b2d3..608da1882cd 100644 --- a/crates/rome_cli/tests/commands/ci.rs +++ b/crates/rome_cli/tests/commands/ci.rs @@ -902,3 +902,25 @@ fn ignores_unknown_file() { result, )); } + +#[test] +fn doesnt_error_if_no_files_were_processed() { + let mut console = BufferConsole::default(); + let mut fs = MemoryFileSystem::default(); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(&[("ci"), "--no-errors-on-unmatched", ("file.js")]), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "doesnt_error_if_no_files_were_processed", + fs, + console, + result, + )); +} diff --git a/crates/rome_cli/tests/commands/format.rs b/crates/rome_cli/tests/commands/format.rs index 72ec82e9cd8..bb5eda0690e 100644 --- a/crates/rome_cli/tests/commands/format.rs +++ b/crates/rome_cli/tests/commands/format.rs @@ -1692,3 +1692,25 @@ fn ignores_unknown_file() { result, )); } + +#[test] +fn doesnt_error_if_no_files_were_processed() { + let mut console = BufferConsole::default(); + let mut fs = MemoryFileSystem::default(); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(&[("format"), "--no-errors-on-unmatched", ("file.js")]), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "doesnt_error_if_no_files_were_processed", + fs, + console, + result, + )); +} diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/check_help.snap b/crates/rome_cli/tests/snapshots/main_commands_check/check_help.snap index fb81d85ed2b..dfa29c3bb24 100644 --- a/crates/rome_cli/tests/snapshots/main_commands_check/check_help.snap +++ b/crates/rome_cli/tests/snapshots/main_commands_check/check_help.snap @@ -61,6 +61,8 @@ Available options: --max-diagnostics Cap the amount of diagnostics displayed (default: 20) --skip-errors Skip over files containing syntax errors instead of emitting an error diagnostic. + --no-errors-on-unmatched Silence errors that would be emitted in case no files were + processed during the execution of the command. --json Reports information using the JSON format --stdin-file-path A file name with its extension to pass when reading from standard diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/doesnt_error_if_no_files_were_processed.snap b/crates/rome_cli/tests/snapshots/main_commands_check/doesnt_error_if_no_files_were_processed.snap new file mode 100644 index 00000000000..a68ecdb62bd --- /dev/null +++ b/crates/rome_cli/tests/snapshots/main_commands_check/doesnt_error_if_no_files_were_processed.snap @@ -0,0 +1,11 @@ +--- +source: crates/rome_cli/tests/snap_test.rs +expression: content +--- +# Emitted Messages + +```block +Checked 0 file(s) in