From ae69645832ca808d88f0f0b4b09068dfdae8fb95 Mon Sep 17 00:00:00 2001 From: Ze-Zheng Wu Date: Wed, 3 Apr 2024 15:37:49 +0800 Subject: [PATCH] fix(cli): error count --- CHANGELOG.md | 4 ++++ crates/biome_cli/src/execute/process_file.rs | 7 ++---- .../src/execute/process_file/check.rs | 22 +++++++++---------- .../src/execute/process_file/lint.rs | 7 +----- ...extends_config_ok_formatter_no_linter.snap | 4 +--- ...xtends_config_ok_linter_not_formatter.snap | 4 +--- ...tends_resolves_when_using_config_path.snap | 4 +--- .../set_config_path.snap | 2 +- .../max_diagnostics_no_verbose.snap | 4 +--- .../max_diagnostics_verbose.snap | 4 +--- .../lint_astro_files.snap | 2 +- .../sorts_imports_check.snap | 4 +--- .../sorts_imports_check.snap | 4 +--- .../lint_vue_js_files.snap | 2 +- .../lint_vue_ts_files.snap | 2 +- .../sorts_imports_check.snap | 4 +--- .../main_commands_check/all_rules.snap | 4 +--- .../apply_bogus_argument.snap | 4 +--- .../apply_unsafe_with_error.snap | 6 ++--- .../main_commands_check/check_json_files.snap | 4 +--- .../config_recommended_group.snap | 4 +--- .../deprecated_suppression_comment.snap | 2 +- .../downgrade_severity.snap | 4 +--- .../ignore_configured_globals.snap | 4 +--- .../ignore_vcs_ignored_file.snap | 4 +--- .../ignore_vcs_ignored_file_via_cli.snap | 4 +--- .../ignore_vcs_os_independent_parse.snap | 4 +--- .../ignores_unknown_file.snap | 4 +--- .../main_commands_check/lint_error.snap | 4 +--- .../main_commands_check/max_diagnostics.snap | 4 +--- .../max_diagnostics_default.snap | 4 +--- .../maximum_diagnostics.snap | 4 +--- .../no_lint_if_linter_is_disabled.snap | 4 +--- .../main_commands_check/nursery_unstable.snap | 4 +--- .../main_commands_check/parse_error.snap | 4 +--- .../main_commands_check/print_verbose.snap | 4 +--- .../should_apply_correct_file_source.snap | 4 +--- ...disable_recommended_rules_for_a_group.snap | 4 +--- ...ould_not_enable_all_recommended_rules.snap | 4 +--- ...agnostics_for_files_ignored_by_linter.snap | 2 +- .../shows_organize_imports_diff_on_check.snap | 4 +--- .../suppression_syntax_error.snap | 4 +--- .../top_level_all_down_level_not_all.snap | 4 +--- .../top_level_not_all_down_level_all.snap | 4 +--- .../main_commands_check/upgrade_severity.snap | 4 +--- .../ci_does_not_run_linter.snap | 4 +--- .../ci_does_not_run_linter_via_cli.snap | 4 +--- .../ci_formatter_linter_organize_imports.snap | 4 +--- .../main_commands_ci/ci_lint_error.snap | 4 +--- .../main_commands_ci/ci_parse_error.snap | 4 +--- ..._runs_linter_not_formatter_issue_3495.snap | 4 +--- ...handles_ignored_and_not_ignored_files.snap | 4 +--- .../main_commands_ci/formatting_error.snap | 4 +--- .../ignore_vcs_ignored_file.snap | 4 +--- .../ignore_vcs_ignored_file_via_cli.snap | 4 +--- .../ignores_unknown_file.snap | 4 +--- .../main_commands_ci/max_diagnostics.snap | 4 +--- .../max_diagnostics_default.snap | 4 +--- .../main_commands_ci/print_verbose.snap | 4 +--- .../main_commands_lint/all_rules.snap | 4 +--- .../apply_bogus_argument.snap | 4 +--- .../apply_unsafe_with_error.snap | 6 ++--- .../main_commands_lint/check_json_files.snap | 4 +--- .../config_recommended_group.snap | 4 +--- ...l_disable_recommended_enable_specific.snap | 2 +- .../ignore_vcs_ignored_file.snap | 4 +--- .../ignore_vcs_ignored_file_via_cli.snap | 4 +--- .../include_files_in_subdir.snap | 4 +--- .../include_files_in_symlinked_subdir.snap | 4 +--- .../main_commands_lint/lint_error.snap | 4 +--- .../main_commands_lint/lint_syntax_rules.snap | 4 +--- .../main_commands_lint/max_diagnostics.snap | 4 +--- .../max_diagnostics_default.snap | 4 +--- .../maximum_diagnostics.snap | 4 +--- .../no_unused_dependencies.snap | 4 +--- .../main_commands_lint/nursery_unstable.snap | 4 +--- .../main_commands_lint/parse_error.snap | 4 +--- .../main_commands_lint/print_verbose.snap | 4 +--- ...disable_recommended_rules_for_a_group.snap | 4 +--- .../suppression_syntax_error.snap | 4 +--- .../top_level_not_all_down_level_all.snap | 4 +--- .../main_commands_lint/upgrade_severity.snap | 4 +--- .../main_configuration/override_globals.snap | 4 +--- .../src/content/docs/internals/changelog.md | 4 ++++ 84 files changed, 103 insertions(+), 247 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2774cb21fe5..f2fbdbe99f4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,10 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b ### CLI +#### Bug fixes + +- Fix the printed error count ([#2048](https://github.com/biomejs/biome/issues/2048)). Contributed by @Sec-ant + ### Configuration #### Bug fixes diff --git a/crates/biome_cli/src/execute/process_file.rs b/crates/biome_cli/src/execute/process_file.rs index 0b050defe528..2f86270836e1 100644 --- a/crates/biome_cli/src/execute/process_file.rs +++ b/crates/biome_cli/src/execute/process_file.rs @@ -63,11 +63,8 @@ pub(crate) enum Message { } impl Message { - pub(crate) const fn is_error(&self) -> bool { - matches!( - self, - Message::Diff { .. } | Message::Diagnostics { .. } | Message::Failure - ) + pub(crate) const fn is_failure(&self) -> bool { + matches!(self, Message::Failure) } } diff --git a/crates/biome_cli/src/execute/process_file/check.rs b/crates/biome_cli/src/execute/process_file/check.rs index 02567da8bff7..7978d987ccfb 100644 --- a/crates/biome_cli/src/execute/process_file/check.rs +++ b/crates/biome_cli/src/execute/process_file/check.rs @@ -11,7 +11,7 @@ pub(crate) fn check_file<'ctx>( path: &Path, file_features: &'ctx FileFeaturesResult, ) -> FileResult { - let mut has_errors = false; + let mut has_failures = false; let mut workspace_file = WorkspaceFile::new(ctx, path)?; let mut changed = false; tracing::info_span!("Process check", path =? workspace_file.path.display()).in_scope( @@ -24,15 +24,15 @@ pub(crate) fn check_file<'ctx>( changed = true } if let FileStatus::Message(msg) = status { - if msg.is_error() { - has_errors = true + if msg.is_failure() { + has_failures = true; } ctx.push_message(msg); } } Err(err) => { ctx.push_message(err); - has_errors = true; + has_failures = true; } } } @@ -44,15 +44,15 @@ pub(crate) fn check_file<'ctx>( changed = true } if let FileStatus::Message(msg) = status { - if msg.is_error() { - has_errors = true + if msg.is_failure() { + has_failures = true; } ctx.push_message(msg); } } Err(err) => { ctx.push_message(err); - has_errors = true; + has_failures = true; } } } @@ -65,20 +65,20 @@ pub(crate) fn check_file<'ctx>( changed = true } if let FileStatus::Message(msg) = status { - if msg.is_error() { - has_errors = true + if msg.is_failure() { + has_failures = true; } ctx.push_message(msg); } } Err(err) => { ctx.push_message(err); - has_errors = true; + has_failures = true; } } } - if has_errors { + if has_failures { Ok(FileStatus::Message(Message::Failure)) } else if changed { Ok(FileStatus::Changed) diff --git a/crates/biome_cli/src/execute/process_file/lint.rs b/crates/biome_cli/src/execute/process_file/lint.rs index a9aeed54b69f..7e6cd42b669e 100644 --- a/crates/biome_cli/src/execute/process_file/lint.rs +++ b/crates/biome_cli/src/execute/process_file/lint.rs @@ -19,7 +19,6 @@ pub(crate) fn lint_with_guard<'ctx>( ) -> FileResult { tracing::info_span!("Processes linting", path =? workspace_file.path.display()).in_scope( move || { - let mut errors = 0; let mut input = workspace_file.input()?; let mut changed = false; if let Some(fix_mode) = ctx.execution.as_fix_file_mode() { @@ -54,7 +53,6 @@ pub(crate) fn lint_with_guard<'ctx>( workspace_file.update_file(output)?; input = workspace_file.input()?; } - errors = fix_result.errors; } let max_diagnostics = ctx.remaining_diagnostics.load(Ordering::Relaxed); @@ -71,7 +69,6 @@ pub(crate) fn lint_with_guard<'ctx>( let no_diagnostics = pull_diagnostics_result.diagnostics.is_empty() && pull_diagnostics_result.skipped_diagnostics == 0; - errors += pull_diagnostics_result.errors; if !no_diagnostics { let input = match workspace_file.as_extension() { @@ -93,9 +90,7 @@ pub(crate) fn lint_with_guard<'ctx>( }); } - if errors > 0 { - Ok(FileStatus::Message(Message::Failure)) - } else if changed { + if changed { Ok(FileStatus::Changed) } else { Ok(FileStatus::Unchanged) diff --git a/crates/biome_cli/tests/snapshots/main_cases_config_extends/extends_config_ok_formatter_no_linter.snap b/crates/biome_cli/tests/snapshots/main_cases_config_extends/extends_config_ok_formatter_no_linter.snap index 91030867f644..2807dced706d 100644 --- a/crates/biome_cli/tests/snapshots/main_cases_config_extends/extends_config_ok_formatter_no_linter.snap +++ b/crates/biome_cli/tests/snapshots/main_cases_config_extends/extends_config_ok_formatter_no_linter.snap @@ -54,7 +54,5 @@ test.js format ━━━━━━━━━━━━━━━━━━━━━ ```block Checked 1 file in