From dd5cc6894add644402f111281ee604c792f3b20f Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 16 Sep 2024 12:02:15 +0200 Subject: [PATCH] fix(cli): use correct list of evaluated paths (#3921) --- CHANGELOG.md | 26 ++++++++++---- .../src/execute/process_file/format.rs | 6 ++-- crates/biome_cli/src/execute/traverse.rs | 8 +++-- crates/biome_cli/src/reporter/terminal.rs | 8 ++--- crates/biome_cli/tests/commands/check.rs | 33 +++++++++++++++++ .../print_verbose_write.snap | 36 +++++++++++++++++++ 6 files changed, 100 insertions(+), 17 deletions(-) create mode 100644 crates/biome_cli/tests/snapshots/main_commands_check/print_verbose_write.snap diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c2baef6940d..e8aec848df12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,17 +11,13 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b ## Unreleased -## v1.9.1 (2024-09-15) - ### Analyzer ### CLI #### Bug fixes -- `useEditorConfig` now loads the editorconfig when running `biome ci` [#3864](https://github.com/biomejs/biome/issues/3864). Contributed by @dyc3 - -- Revert [#3731](https://github.com/biomejs/biome/pull/3731) to fix broken quick fixes and code actions. Contributed by @nhedger +- Fix [#3917](https://github.com/biomejs/biome/issues/3917), where the fixed files were incorrectly computed. Contributed by @ematipico ### Configuration @@ -33,6 +29,24 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b ### Linter +### Parser + +## v1.9.1 (2024-09-15) + +### CLI + +#### Bug fixes + +- `useEditorConfig` now loads the editorconfig when running `biome ci` [#3864](https://github.com/biomejs/biome/issues/3864). Contributed by @dyc3 + +### Editors + +#### Bug fixes + +- Revert [#3731](https://github.com/biomejs/biome/pull/3731) to fix broken quick fixes and code actions. Contributed by @nhedger + +### Linter + #### New Features - Add [nursery/noProcessEnv](https://biomejs.dev/linter/rules/no-process-env/). Contributed by @unvalley @@ -43,8 +57,6 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b - [noUndeclaredDependencies](https://biomejs.dev/linter/rules/no-undeclared-dependencies/) now ignores `@/` imports and recognizes type imports from Definitely Typed and `bun` imports. Contributed by @Conaclos -### Parser - ## v1.9.0 (2024-09-12) ### Analyzer diff --git a/crates/biome_cli/src/execute/process_file/format.rs b/crates/biome_cli/src/execute/process_file/format.rs index 306067d56769..c8fe35521f70 100644 --- a/crates/biome_cli/src/execute/process_file/format.rs +++ b/crates/biome_cli/src/execute/process_file/format.rs @@ -117,15 +117,15 @@ pub(crate) fn format_with_guard<'ctx>( if output != input { if should_write { workspace_file.update_file(output)?; + Ok(FileStatus::Changed) } else { - return Ok(FileStatus::Message(Message::Diff { + Ok(FileStatus::Message(Message::Diff { file_name: workspace_file.path.display().to_string(), old: input, new: output, diff_kind: DiffKind::Format, - })); + })) } - Ok(FileStatus::Changed) } else { Ok(FileStatus::Unchanged) } diff --git a/crates/biome_cli/src/execute/traverse.rs b/crates/biome_cli/src/execute/traverse.rs index 0d387c80e308..87e85afc4a3e 100644 --- a/crates/biome_cli/src/execute/traverse.rs +++ b/crates/biome_cli/src/execute/traverse.rs @@ -199,7 +199,7 @@ fn traverse_inputs( } })); - (start.elapsed(), dome.to_paths()) + (start.elapsed(), ctx.evaluated_paths()) } // struct DiagnosticsReporter<'ctx> {} @@ -568,8 +568,10 @@ pub(crate) struct TraversalOptions<'ctx, 'app> { impl<'ctx, 'app> TraversalOptions<'ctx, 'app> { pub(crate) fn increment_changed(&self, path: &BiomePath) { self.changed.fetch_add(1, Ordering::Relaxed); - let mut evaluated_paths = self.evaluated_paths.write().unwrap(); - evaluated_paths.replace(path.to_written()); + self.evaluated_paths + .write() + .unwrap() + .replace(path.to_written()); } pub(crate) fn increment_unchanged(&self) { self.unchanged.fetch_add(1, Ordering::Relaxed); diff --git a/crates/biome_cli/src/reporter/terminal.rs b/crates/biome_cli/src/reporter/terminal.rs index fd11ca9e75ab..42653361d2a0 100644 --- a/crates/biome_cli/src/reporter/terminal.rs +++ b/crates/biome_cli/src/reporter/terminal.rs @@ -37,7 +37,7 @@ impl Reporter for ConsoleReporter { )] struct EvaluatedPathsDiagnostic { #[advice] - list: ListAdvice, + advice: ListAdvice, } #[derive(Debug, Diagnostic)] @@ -48,7 +48,7 @@ struct EvaluatedPathsDiagnostic { )] struct FixedPathsDiagnostic { #[advice] - list: ListAdvice, + advice: ListAdvice, } pub(crate) struct ConsoleReporterVisitor<'a>(pub(crate) &'a mut dyn Console); @@ -82,7 +82,7 @@ impl<'a> ReporterVisitor for ConsoleReporterVisitor<'a> { fn report_handled_paths(&mut self, evaluated_paths: BTreeSet) -> io::Result<()> { let evaluated_paths_diagnostic = EvaluatedPathsDiagnostic { - list: ListAdvice { + advice: ListAdvice { list: evaluated_paths .iter() .map(|p| p.display().to_string()) @@ -91,7 +91,7 @@ impl<'a> ReporterVisitor for ConsoleReporterVisitor<'a> { }; let fixed_paths_diagnostic = FixedPathsDiagnostic { - list: ListAdvice { + advice: ListAdvice { list: evaluated_paths .iter() .filter(|p| p.was_written()) diff --git a/crates/biome_cli/tests/commands/check.rs b/crates/biome_cli/tests/commands/check.rs index cbad904e9c24..603627a9ff54 100644 --- a/crates/biome_cli/tests/commands/check.rs +++ b/crates/biome_cli/tests/commands/check.rs @@ -1436,6 +1436,39 @@ fn print_verbose() { )); } +#[test] +fn print_verbose_write() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path = Path::new("check.js"); + fs.insert(file_path.into(), LINT_ERROR.as_bytes()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from( + [ + ("check"), + ("--verbose"), + "--write", + file_path.as_os_str().to_str().unwrap(), + ] + .as_slice(), + ), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "print_verbose_write", + fs, + console, + result, + )); +} + #[test] fn unsupported_file() { let mut fs = MemoryFileSystem::default(); diff --git a/crates/biome_cli/tests/snapshots/main_commands_check/print_verbose_write.snap b/crates/biome_cli/tests/snapshots/main_commands_check/print_verbose_write.snap new file mode 100644 index 000000000000..1794f6ed470d --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_commands_check/print_verbose_write.snap @@ -0,0 +1,36 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +## `check.js` + +```js +while (true); + +``` + +# Emitted Messages + +```block +Checked 1 file in