From a5168e0f9ef2632432a368c200b76f61fc165b35 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Sat, 26 Nov 2022 13:07:23 +0100 Subject: [PATCH 1/2] fix(rome_cli): Fix max diagnostic counts This PR fixes the max diagnostics count for the linter. The issue was that `process_file` reports a `Success` if a file has no diagnostic even if the file has skipped diagnostics. This PR changes `process_file` to return a `Message` if a file has reported diagnostics or any skipped diagnostics. --- crates/rome_cli/src/traversal.rs | 3 +- crates/rome_cli/tests/commands/check.rs | 16 +- crates/rome_cli/tests/commands/format.rs | 2 - .../main_commands_check/max_diagnostics.snap | 77 ++++++++- .../max_diagnostics_default.snap | 147 +++++++++++++++++- 5 files changed, 227 insertions(+), 18 deletions(-) diff --git a/crates/rome_cli/src/traversal.rs b/crates/rome_cli/src/traversal.rs index 96ec86314af..d143d9dbe79 100644 --- a/crates/rome_cli/src/traversal.rs +++ b/crates/rome_cli/src/traversal.rs @@ -840,7 +840,8 @@ fn process_file(ctx: &TraversalOptions, path: &Path, file_id: FileId) -> FileRes // In format mode the diagnostics have already been checked for errors // at this point, so they can just be dropped now since we don't want // to print syntax warnings for the format command - let result = if result.diagnostics.is_empty() || ctx.execution.is_format() { + let no_diagnostics = result.diagnostics.is_empty() && result.skipped_diagnostics == 0; + let result = if no_diagnostics || ctx.execution.is_format() { FileStatus::Success } else { FileStatus::Message(Message::Diagnostics { diff --git a/crates/rome_cli/tests/commands/check.rs b/crates/rome_cli/tests/commands/check.rs index b624a9d92ed..016a99c81d4 100644 --- a/crates/rome_cli/tests/commands/check.rs +++ b/crates/rome_cli/tests/commands/check.rs @@ -557,7 +557,6 @@ fn upgrade_severity() { let messages = &console.out_buffer; - dbg!(&result); assert_eq!( messages .iter() @@ -947,7 +946,8 @@ fn max_diagnostics_default() { let mut fs = MemoryFileSystem::default(); let mut console = BufferConsole::default(); - for i in 0..60 { + // Creates 40 diagnostics. + for i in 0..20 { let file_path = PathBuf::from(format!("src/file_{i}.js")); fs.insert(file_path, LINT_ERROR.as_bytes()); } @@ -981,11 +981,6 @@ fn max_diagnostics_default() { console.out_buffer = filtered_messages; - for i in 0..60 { - let file_path = format!("src/file_{i}.js"); - fs.remove(Path::new(&file_path)); - } - assert_cli_snapshot(SnapshotPayload::new( module_path!(), "max_diagnostics_default", @@ -1002,7 +997,7 @@ fn max_diagnostics() { let mut fs = MemoryFileSystem::default(); let mut console = BufferConsole::default(); - for i in 0..60 { + for i in 0..10 { let file_path = PathBuf::from(format!("src/file_{i}.js")); fs.insert(file_path, LINT_ERROR.as_bytes()); } @@ -1041,11 +1036,6 @@ fn max_diagnostics() { console.out_buffer = filtered_messages; - for i in 0..60 { - let file_path = format!("src/file_{i}.js"); - fs.remove(Path::new(&file_path)); - } - assert_cli_snapshot(SnapshotPayload::new( module_path!(), "max_diagnostics", diff --git a/crates/rome_cli/tests/commands/format.rs b/crates/rome_cli/tests/commands/format.rs index 6de7a461787..b351ca36e98 100644 --- a/crates/rome_cli/tests/commands/format.rs +++ b/crates/rome_cli/tests/commands/format.rs @@ -499,7 +499,6 @@ fn applies_custom_trailing_comma() { file.read_to_string(&mut content) .expect("failed to read file from memory FS"); - dbg!(&content); assert_eq!(content, APPLY_TRAILING_COMMA_AFTER); drop(file); @@ -572,7 +571,6 @@ fn with_semicolons_options() { file.read_to_string(&mut content) .expect("failed to read file from memory FS"); - dbg!(&content); assert_eq!(content, "statement()\n"); drop(file); diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics.snap b/crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics.snap index f286596fd06..c18936fd614 100644 --- a/crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics.snap +++ b/crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics.snap @@ -2,6 +2,76 @@ source: crates/rome_cli/tests/snap_test.rs expression: content --- +## `src/file_0.js` + +```js +for(;true;); + +``` + +## `src/file_1.js` + +```js +for(;true;); + +``` + +## `src/file_2.js` + +```js +for(;true;); + +``` + +## `src/file_3.js` + +```js +for(;true;); + +``` + +## `src/file_4.js` + +```js +for(;true;); + +``` + +## `src/file_5.js` + +```js +for(;true;); + +``` + +## `src/file_6.js` + +```js +for(;true;); + +``` + +## `src/file_7.js` + +```js +for(;true;); + +``` + +## `src/file_8.js` + +```js +for(;true;); + +``` + +## `src/file_9.js` + +```js +for(;true;); + +``` + # Termination Message ```block @@ -11,7 +81,12 @@ some errors were emitted while running checks # Emitted Messages ```block -Checked 60 file(s) in