fix(rome_cli): Fix max diagnostic counts
MODIFY
crates/rome_cli/src/traversal.rs
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 {

MODIFY
crates/rome_cli/tests/commands/check.rs
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()
@@ -729,10 +728,7 @@ fn fs_error_dereferenced_symlink() {
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
- #[cfg(target_family = "unix")]
- "fs_error_dereferenced_symlink_unix",
- #[cfg(target_os = "windows")]
- "fs_error_dereferenced_symlink_windows",
+ "fs_error_dereferenced_symlink",
fs,
console,
result,
@@ -790,10 +786,7 @@ fn fs_error_infinite_symlink_exapansion() {
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
- #[cfg(target_family = "unix")]
- "fs_error_infinite_symlink_exapansion_unix",
- #[cfg(target_os = "windows")]
- "fs_error_infinite_symlink_exapansion_windows",
+ "fs_error_infinite_symlink_expansion",
fs,
console,
result,
@@ -947,7 +940,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 +975,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 +991,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 +1030,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",

MODIFY
crates/rome_cli/tests/commands/format.rs
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);

MODIFY
crates/rome_cli/tests/snap_test.rs
crates/rome_cli/tests/snap_test.rs
@@ -128,10 +128,7 @@ fn redact_snapshot(input: &str) -> Cow<'_, str> {
replace(&mut output, &current_exe, "rome");
}
- // Replace the path to the temporary directory with "<TEMP_DIR>"
- let temp_dir = temp_dir().display().to_string();
- let temp_dir = temp_dir.trim_end_matches(MAIN_SEPARATOR);
- replace(&mut output, temp_dir, "<TEMP_DIR>");
+ output = replace_temp_dir(output);
// Normalize Windows-specific path separators to "/"
if cfg!(windows) {
@@ -173,6 +170,46 @@ fn redact_snapshot(input: &str) -> Cow<'_, str> {
output
}
+/// Replace the path to the temporary directory with "<TEMP_DIR>"
+/// And normalizes the count of `-` at the end of the diagnostic
+fn replace_temp_dir(input: Cow<str>) -> Cow<str> {
+ let mut result = String::new();
+ let mut rest = input.as_ref();
+
+ let temp_dir = temp_dir().display().to_string();
+ let temp_dir = temp_dir.trim_end_matches(MAIN_SEPARATOR);
+
+ while let Some(index) = rest.find(temp_dir) {
+ let (before, after) = rest.split_at(index);
+
+ result.push_str(before);
+ result.push_str("<TEMP_DIR>");
+
+ let after = after.split_at(temp_dir.len()).1;
+ let header_line = after.lines().next().unwrap();
+
+ match header_line.split_once('\u{2501}') {
+ Some((between_temp_and_line, _)) => {
+ // Diagnostic header line, normalize the horizontal line
+ result.push_str(between_temp_and_line);
+ result.push_str(&"\u{2501}".repeat(20));
+ rest = after.split_at(header_line.len()).1;
+ }
+ None => {
+ // Not a header line, only replace tempdir
+ rest = after;
+ }
+ }
+ }
+
+ if result.is_empty() {
+ input
+ } else {
+ result.push_str(rest);
+ Cow::Owned(result)
+ }
+}
+
fn replace(input: &mut Cow<str>, from: &str, to: &str) {
let mut rest = &**input;
let mut result = String::new();

MODIFY
crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics.snap
crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics.snap
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 <TIME>
+The number of diagnostics exceeds the number allowed by Rome.
+Diagnostics not shown: 10.
+```
+
+```block
+Checked 10 file(s) in <TIME>
```

MODIFY
crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics_default.snap
crates/rome_cli/tests/snapshots/main_commands_check/max_diagnostics_default.snap
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_10.js`
+
+```js
+for(;true;);
+
+```
+
+## `src/file_11.js`
+
+```js
+for(;true;);
+
+```
+
+## `src/file_12.js`
+
+```js
+for(;true;);
+
+```
+
+## `src/file_13.js`
+
+```js
+for(;true;);
+
+```
+
+## `src/file_14.js`
+
+```js
+for(;true;);
+
+```
+
+## `src/file_15.js`
+
+```js
+for(;true;);
+
+```
+
+## `src/file_16.js`
+
+```js
+for(;true;);
+
+```
+
+## `src/file_17.js`
+
+```js
+for(;true;);
+
+```
+
+## `src/file_18.js`
+
+```js
+for(;true;);
+
+```
+
+## `src/file_19.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 +151,12 @@ some errors were emitted while running checks
# Emitted Messages
```block
-Checked 60 file(s) in <TIME>
+The number of diagnostics exceeds the number allowed by Rome.
+Diagnostics not shown: 20.
+```
+
+```block
+Checked 20 file(s) in <TIME>
```

fix(rome_cli): Fix max diagnostic counts (#3869)