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

fix(rome_cli): Fix max diagnostic counts #3869

Merged
merged 2 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/rome_cli/src/traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 5 additions & 21 deletions crates/rome_cli/tests/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ fn upgrade_severity() {

let messages = &console.out_buffer;

dbg!(&result);
assert_eq!(
messages
.iter()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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",
Expand All @@ -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());
}
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions crates/rome_cli/tests/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
45 changes: 41 additions & 4 deletions crates/rome_cli/tests/snap_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ no files were processed in the specified paths.
# Emitted Messages

```block
<TEMP_DIR>/rome_test_broken_symlink/broken_symlink internalError/fs ━━━━━━━━━━
<TEMP_DIR>/rome_test_broken_symlink/broken_symlink internalError/fs ━━━━━━━━━━━━━━━━━━━━

! Dereferenced symlink

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ no files were processed in the specified paths.
# Emitted Messages

```block
<TEMP_DIR>/rome_test_infinite_symlink_exapansion/prefix internalError/fs ━━━━━━━━━━
<TEMP_DIR>/rome_test_infinite_symlink_exapansion/prefix internalError/fs ━━━━━━━━━━━━━━━━━━━━

! Infinite symlink expansion

Expand All @@ -21,7 +21,7 @@ no files were processed in the specified paths.
```

```block
<TEMP_DIR>/rome_test_infinite_symlink_exapansion/prefix internalError/fs ━━━━━━━━━━
<TEMP_DIR>/rome_test_infinite_symlink_exapansion/prefix internalError/fs ━━━━━━━━━━━━━━━━━━━━

! Infinite symlink expansion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>
```


Loading