Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
feat(rome_cli): add --no-errors-on-unmatched optoin (#4622)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Jun 26, 2023
1 parent 6911d55 commit af25635
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 4 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions crates/rome_cli/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/rome_cli/src/execute/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
22 changes: 22 additions & 0 deletions crates/rome_cli/tests/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
));
}
22 changes: 22 additions & 0 deletions crates/rome_cli/tests/commands/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
));
}
22 changes: 22 additions & 0 deletions crates/rome_cli/tests/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
));
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Available options:
--max-diagnostics <NUMBER> 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 <PATH> A file name with its extension to pass when reading from standard
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
source: crates/rome_cli/tests/snap_test.rs
expression: content
---
# Emitted Messages

```block
Checked 0 file(s) in <TIME>
```


2 changes: 2 additions & 0 deletions crates/rome_cli/tests/snapshots/main_commands_ci/ci_help.snap
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Available options:
--max-diagnostics <NUMBER> 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
-h, --help Prints help information
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
source: crates/rome_cli/tests/snap_test.rs
expression: content
---
# Emitted Messages

```block
Checked 0 file(s) in <TIME>
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
source: crates/rome_cli/tests/snap_test.rs
expression: content
---
# Emitted Messages

```block
Compared 0 file(s) in <TIME>
```


Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Available options:
--max-diagnostics <NUMBER> 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
--write Writes formatted files to file system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ expression: content
Acts as a server for the Language Server Protocol over stdin/stdout
Usage: [--colors off|force] [--use-server] [--verbose] [--config-path PATH] [--max-diagnostics
NUMBER] [--skip-errors]
NUMBER] [--skip-errors] [--no-errors-on-unmatched]
Available options:
Global options applied to all commands
Expand All @@ -22,6 +22,8 @@ Available options:
--max-diagnostics <NUMBER> 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
-h, --help Prints help information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Available options:
--max-diagnostics <NUMBER> 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
--write Writes the new configuration file to disk
Expand Down

0 comments on commit af25635

Please sign in to comment.