From c55e14cc28131a28c43415471433d98bd0edba72 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 10 Jul 2023 08:18:36 +0100 Subject: [PATCH 1/3] feat(rome_cli): exit with error if there are warnings --- crates/rome_cli/src/cli_options.rs | 6 +- crates/rome_cli/src/diagnostics.rs | 86 +++++++++---------- crates/rome_cli/src/execute/mod.rs | 12 ++- crates/rome_cli/src/execute/traverse.rs | 35 ++++++-- crates/rome_cli/tests/commands/check.rs | 68 ++++++++++++++- crates/rome_cli/tests/commands/lint.rs | 57 ++++++++++++ ...extends_config_ok_formatter_no_linter.snap | 4 +- ...xtends_config_ok_linter_not_formatter.snap | 4 +- ...tends_resolves_when_using_config_path.snap | 4 +- .../main_commands_check/all_rules.snap | 4 +- .../apply_bogus_argument.snap | 2 +- .../apply_unsafe_with_error.snap | 2 +- .../main_commands_check/check_help.snap | 3 +- .../main_commands_check/check_json_files.snap | 4 +- .../config_recommended_group.snap | 4 +- .../deprecated_suppression_comment.snap | 4 +- .../does_error_with_only_warnings.snap | 65 ++++++++++++++ .../downgrade_severity.snap | 4 +- .../main_commands_check/file_too_large.snap | 4 +- .../file_too_large_cli_limit.snap | 4 +- .../file_too_large_config_limit.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 | 2 +- .../max_diagnostics_default.snap | 2 +- .../maximum_diagnostics.snap | 2 +- .../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 +- .../should_not_enable_nursery_rules.snap | 4 +- .../shows_organize_imports_diff_on_check.snap | 4 +- ..._organize_imports_diff_on_check_apply.snap | 2 +- .../suppression_syntax_error.snap | 2 +- .../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 +- .../snapshots/main_commands_ci/ci_help.snap | 3 +- .../main_commands_ci/ci_lint_error.snap | 4 +- .../main_commands_ci/ci_parse_error.snap | 4 +- ..._runs_linter_not_formatter_issue_3495.snap | 2 +- .../main_commands_ci/file_too_large.snap | 4 +- .../file_too_large_cli_limit.snap | 4 +- .../file_too_large_config_limit.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 | 2 +- .../max_diagnostics_default.snap | 2 +- .../main_commands_ci/print_verbose.snap | 4 +- .../main_commands_format/format_help.snap | 3 +- .../main_commands_lint/all_rules.snap | 4 +- .../apply_bogus_argument.snap | 4 +- .../apply_unsafe_with_error.snap | 4 +- .../main_commands_lint/check_help.snap | 3 +- .../main_commands_lint/check_json_files.snap | 4 +- .../config_recommended_group.snap | 4 +- .../does_error_with_only_warnings.snap | 65 ++++++++++++++ .../ignore_vcs_ignored_file.snap | 4 +- .../ignore_vcs_ignored_file_via_cli.snap | 4 +- .../main_commands_lint/lint_error.snap | 4 +- .../main_commands_lint/max_diagnostics.snap | 4 +- .../max_diagnostics_default.snap | 4 +- .../maximum_diagnostics.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 +- .../lsp_proxy_help.snap | 5 +- .../main_commands_migrate/migrate_help.snap | 3 +- 84 files changed, 478 insertions(+), 196 deletions(-) create mode 100644 crates/rome_cli/tests/snapshots/main_commands_check/does_error_with_only_warnings.snap create mode 100644 crates/rome_cli/tests/snapshots/main_commands_lint/does_error_with_only_warnings.snap diff --git a/crates/rome_cli/src/cli_options.rs b/crates/rome_cli/src/cli_options.rs index 0e8f0544b55..50b1c032402 100644 --- a/crates/rome_cli/src/cli_options.rs +++ b/crates/rome_cli/src/cli_options.rs @@ -20,7 +20,7 @@ pub struct CliOptions { #[bpaf(long("config-path"), argument("PATH"), optional)] pub config_path: Option, - /// Cap the amount of diagnostics displayed (default: 20) + /// Cap the amount of diagnostics displayed. #[bpaf(long("max-diagnostics"), argument("NUMBER"), optional)] pub max_diagnostics: Option, @@ -32,6 +32,10 @@ pub struct CliOptions { #[bpaf(long("no-errors-on-unmatched"), switch)] pub no_errors_on_unmatched: bool, + /// Tell Rome to exit with an error code if some diagnostics emit warnings. + #[bpaf(long("error-on-warnings"), switch)] + pub error_on_warnings: bool, + /// Reports information using the JSON format #[bpaf(long("json"), switch, hide_usage)] pub json: bool, diff --git a/crates/rome_cli/src/diagnostics.rs b/crates/rome_cli/src/diagnostics.rs index 0bfc04276f3..77e535f6015 100644 --- a/crates/rome_cli/src/diagnostics.rs +++ b/crates/rome_cli/src/diagnostics.rs @@ -1,4 +1,4 @@ -use rome_console::fmt::{Display, Formatter}; +use rome_console::fmt::Formatter; use rome_console::markup; use rome_diagnostics::adapters::{BpafError, IoError}; use rome_diagnostics::{ @@ -153,54 +153,13 @@ pub struct IncompatibleArguments { #[derive(Debug, Diagnostic)] #[diagnostic( severity = Error, - message( - description = "{action_kind}", - message({{self.action_kind}}) - ) )] pub struct CheckError { - action_kind: CheckActionKind, - #[category] category: &'static Category, -} -#[derive(Clone, Copy)] -pub enum CheckActionKind { - Check, - Apply, -} - -impl Debug for CheckActionKind { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self, f) - } -} - -impl Display for CheckActionKind { - fn fmt(&self, fmt: &mut Formatter) -> std::io::Result<()> { - match self { - CheckActionKind::Check => fmt.write_markup(markup! { - "Some errors were emitted while ""running checks" - }), - CheckActionKind::Apply => fmt.write_markup(markup! { - "Some errors were emitted while ""applying fixes" - }), - } - } -} - -impl std::fmt::Display for CheckActionKind { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - CheckActionKind::Check => { - write!(f, "Some errors were emitted while running checks") - } - CheckActionKind::Apply => { - write!(f, "Some errors were emitted while applying fixes") - } - } - } + #[message] + message: MessageAndDescription, } #[derive(Debug, Diagnostic)] @@ -406,16 +365,51 @@ impl CliDiagnostic { /// Emitted when errors were emitted while running `check` command pub fn check_error(category: &'static Category) -> Self { Self::CheckError(CheckError { - action_kind: CheckActionKind::Check, category, + message: MessageAndDescription::from( + markup! { + "Some ""errors"" were emitted while ""running checks""." + } + .to_owned(), + ), + }) + } + + /// Emitted when warnings were emitted while running `check` command + pub fn check_warnings(category: &'static Category) -> Self { + Self::CheckError(CheckError { + category, + message: MessageAndDescription::from( + markup! { + "Some ""warnings"" were emitted while ""running checks""." + } + .to_owned(), + ), }) } /// Emitted when errors were emitted while apply code fixes pub fn apply_error(category: &'static Category) -> Self { Self::CheckError(CheckError { - action_kind: CheckActionKind::Apply, category, + message: MessageAndDescription::from( + markup! { + "Some ""errors"" were emitted while ""applying fixes""." + } + .to_owned(), + ), + }) + } + /// Emitted when warnings were emitted while apply code fixes + pub fn apply_warnings(category: &'static Category) -> Self { + Self::CheckError(CheckError { + category, + message: MessageAndDescription::from( + markup! { + "Some ""warnings"" were emitted while ""running checks""." + } + .to_owned(), + ), }) } diff --git a/crates/rome_cli/src/execute/mod.rs b/crates/rome_cli/src/execute/mod.rs index ec7b64d9891..73a281e70e2 100644 --- a/crates/rome_cli/src/execute/mod.rs +++ b/crates/rome_cli/src/execute/mod.rs @@ -7,7 +7,7 @@ mod traverse; use crate::cli_options::CliOptions; use crate::execute::traverse::traverse; use crate::{CliDiagnostic, CliSession}; -use rome_diagnostics::MAXIMUM_DISPLAYABLE_DIAGNOSTICS; +use rome_diagnostics::{category, Category, MAXIMUM_DISPLAYABLE_DIAGNOSTICS}; use rome_fs::RomePath; use rome_service::workspace::{FeatureName, FixFileMode}; use std::ffi::OsString; @@ -145,6 +145,16 @@ impl Execution { } } + pub(crate) fn as_diagnostic_category(&self) -> &'static Category { + match self.traversal_mode { + TraversalMode::Check { .. } => category!("check"), + TraversalMode::Lint { .. } => category!("lint"), + TraversalMode::CI => category!("ci"), + TraversalMode::Format { .. } => category!("format"), + TraversalMode::Migrate { .. } => category!("migrate"), + } + } + pub(crate) const fn is_ci(&self) -> bool { matches!(self.traversal_mode, TraversalMode::CI { .. }) } diff --git a/crates/rome_cli/src/execute/traverse.rs b/crates/rome_cli/src/execute/traverse.rs index 34075ee2cef..51e029ec978 100644 --- a/crates/rome_cli/src/execute/traverse.rs +++ b/crates/rome_cli/src/execute/traverse.rs @@ -85,6 +85,7 @@ pub(crate) fn traverse( let remaining_diagnostics = AtomicU16::new(max_diagnostics); let mut errors: usize = 0; + let mut warnings: usize = 0; let mut report = Report::default(); let duration = thread::scope(|s| { @@ -102,6 +103,7 @@ pub(crate) fn traverse( errors: &mut errors, report: &mut report, verbose: cli_options.verbose, + warnings: &mut warnings, }); }) .expect("failed to spawn console thread"); @@ -201,19 +203,24 @@ pub(crate) fn traverse( }); } + let should_exit_on_warnings = warnings > 0 && cli_options.error_on_warnings; // Processing emitted error diagnostics, exit with a non-zero code if count.saturating_sub(skipped) == 0 && !cli_options.no_errors_on_unmatched { Err(CliDiagnostic::no_files_processed()) - } else if errors > 0 { - let category = if execution.is_ci() { - category!("ci") - } else { - category!("check") - }; - if execution.is_check_apply() { - Err(CliDiagnostic::apply_error(category)) + } else if errors > 0 || should_exit_on_warnings { + let category = execution.as_diagnostic_category(); + if should_exit_on_warnings { + if execution.is_check_apply() { + Err(CliDiagnostic::apply_warnings(category)) + } else { + Err(CliDiagnostic::check_warnings(category)) + } } else { - Err(CliDiagnostic::check_error(category)) + if execution.is_check_apply() { + Err(CliDiagnostic::apply_error(category)) + } else { + Err(CliDiagnostic::check_error(category)) + } } } else { Ok(()) @@ -266,6 +273,9 @@ struct ProcessMessagesOptions<'ctx> { /// Mutable reference to a boolean flag tracking whether the console thread /// printed any error-level message errors: &'ctx mut usize, + /// Mutable reference to a boolean flag tracking whether the console thread + /// printed any warnings-level message + warnings: &'ctx mut usize, /// Mutable handle to a [Report] instance the console thread should write /// stats into report: &'ctx mut Report, @@ -287,6 +297,7 @@ fn process_messages(options: ProcessMessagesOptions) { errors, report, verbose, + warnings, } = options; let mut paths: HashSet = HashSet::new(); @@ -345,6 +356,9 @@ fn process_messages(options: ProcessMessagesOptions) { Message::Error(mut err) => { let location = err.location(); + if err.severity() == Severity::Warning { + *warnings += 1; + } if let Some(Resource::File(file_path)) = location.resource.as_ref() { // Retrieves the file name from the file ID cache, if it's a miss // flush entries from the interner channel until it's found @@ -432,6 +446,9 @@ fn process_messages(options: ProcessMessagesOptions) { if severity == Severity::Error { *errors += 1; } + if severity == Severity::Warning { + *warnings += 1; + } let should_print = printed_diagnostics < max_diagnostics; if should_print { diff --git a/crates/rome_cli/tests/commands/check.rs b/crates/rome_cli/tests/commands/check.rs index 1ac6e50913c..06e94cf9933 100644 --- a/crates/rome_cli/tests/commands/check.rs +++ b/crates/rome_cli/tests/commands/check.rs @@ -1271,12 +1271,12 @@ fn max_diagnostics() { for msg in console.out_buffer { let MarkupBuf(nodes) = &msg.content; let is_diagnostic = nodes.iter().any(|node| { - dbg!(&node.content); node.content.contains("useWhile") || node.content.contains("useBlockStatements") || node.content.contains("noConstantCondition") || node.content.contains("format") || node.content.contains("lint") + || node.content.contains("check") || node.content.contains("Some errors were emitted while") }); @@ -2587,7 +2587,14 @@ A = 0; let result = run_cli( DynRef::Borrowed(&mut fs), &mut console, - Args::from([("check"), "--apply-unsafe", ("file.js")].as_slice()), + Args::from( + [ + ("check"), + "--apply-unsafe", + file_path.as_os_str().to_str().unwrap(), + ] + .as_slice(), + ), ); assert!(result.is_ok(), "run_cli returned {result:?}"); @@ -2600,3 +2607,60 @@ A = 0; result, )); } + +#[test] +fn does_error_with_only_warnings() { + let mut console = BufferConsole::default(); + let mut fs = MemoryFileSystem::default(); + + let file_path = Path::new("rome.json"); + fs.insert( + file_path.into(), + r#" +{ + "linter": { + "rules": { + "recommended": true, + "suspicious": { + "noClassAssign": "warn" + } + } + } +} + "# + .as_bytes(), + ); + + let file_path = Path::new("file.js"); + fs.insert( + file_path.into(), + r#"class A {}; +A = 0; +"# + .as_bytes(), + ); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from( + [ + ("check"), + "--apply-unsafe", + "--error-on-warnings", + file_path.as_os_str().to_str().unwrap(), + ] + .as_slice(), + ), + ); + + assert!(result.is_err(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "does_error_with_only_warnings", + fs, + console, + result, + )); +} diff --git a/crates/rome_cli/tests/commands/lint.rs b/crates/rome_cli/tests/commands/lint.rs index ff05cff7631..d3c7c15ff2a 100644 --- a/crates/rome_cli/tests/commands/lint.rs +++ b/crates/rome_cli/tests/commands/lint.rs @@ -2333,3 +2333,60 @@ A = 0; result, )); } + +#[test] +fn does_error_with_only_warnings() { + let mut console = BufferConsole::default(); + let mut fs = MemoryFileSystem::default(); + + let file_path = Path::new("rome.json"); + fs.insert( + file_path.into(), + r#" +{ + "linter": { + "rules": { + "recommended": true, + "suspicious": { + "noClassAssign": "warn" + } + } + } +} + "# + .as_bytes(), + ); + + let file_path = Path::new("file.js"); + fs.insert( + file_path.into(), + r#"class A {}; +A = 0; +"# + .as_bytes(), + ); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from( + [ + ("lint"), + "--apply-unsafe", + "--error-on-warnings", + file_path.as_os_str().to_str().unwrap(), + ] + .as_slice(), + ), + ); + + assert!(result.is_err(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "does_error_with_only_warnings", + fs, + console, + result, + )); +} diff --git a/crates/rome_cli/tests/snapshots/main_cases_config_extends/extends_config_ok_formatter_no_linter.snap b/crates/rome_cli/tests/snapshots/main_cases_config_extends/extends_config_ok_formatter_no_linter.snap index d5538d2b00e..a4410578531 100644 --- a/crates/rome_cli/tests/snapshots/main_cases_config_extends/extends_config_ok_formatter_no_linter.snap +++ b/crates/rome_cli/tests/snapshots/main_cases_config_extends/extends_config_ok_formatter_no_linter.snap @@ -31,7 +31,7 @@ debugger; console.log("string"); ```block check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Some errors were emitted while running checks + × Some errors were emitted while running checks. @@ -55,7 +55,7 @@ test.js format ━━━━━━━━━━━━━━━━━━━━━ ```block check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Some errors were emitted while running checks + × Some errors were emitted while running checks. ``` diff --git a/crates/rome_cli/tests/snapshots/main_cases_config_extends/extends_config_ok_linter_not_formatter.snap b/crates/rome_cli/tests/snapshots/main_cases_config_extends/extends_config_ok_linter_not_formatter.snap index 57ef49afb53..7e67701f825 100644 --- a/crates/rome_cli/tests/snapshots/main_cases_config_extends/extends_config_ok_linter_not_formatter.snap +++ b/crates/rome_cli/tests/snapshots/main_cases_config_extends/extends_config_ok_linter_not_formatter.snap @@ -41,7 +41,7 @@ debugger; console.log("string"); ```block check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Some errors were emitted while running checks + × Some errors were emitted while running checks. @@ -88,7 +88,7 @@ test.js format ━━━━━━━━━━━━━━━━━━━━━ ```block check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Some errors were emitted while running checks + × Some errors were emitted while running checks. ``` diff --git a/crates/rome_cli/tests/snapshots/main_cases_config_extends/extends_resolves_when_using_config_path.snap b/crates/rome_cli/tests/snapshots/main_cases_config_extends/extends_resolves_when_using_config_path.snap index 24408d76b99..07b2a17813e 100644 --- a/crates/rome_cli/tests/snapshots/main_cases_config_extends/extends_resolves_when_using_config_path.snap +++ b/crates/rome_cli/tests/snapshots/main_cases_config_extends/extends_resolves_when_using_config_path.snap @@ -31,7 +31,7 @@ debugger; console.log("string"); ```block check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Some errors were emitted while running checks + × Some errors were emitted while running checks. @@ -78,7 +78,7 @@ test.js format ━━━━━━━━━━━━━━━━━━━━━ ```block check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Some errors were emitted while running checks + × Some errors were emitted while running checks. ``` diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/all_rules.snap b/crates/rome_cli/tests/snapshots/main_commands_check/all_rules.snap index f2d42beb004..7bd0736d82a 100644 --- a/crates/rome_cli/tests/snapshots/main_commands_check/all_rules.snap +++ b/crates/rome_cli/tests/snapshots/main_commands_check/all_rules.snap @@ -25,7 +25,7 @@ expression: content ```block check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Some errors were emitted while running checks + × Some errors were emitted while running checks. @@ -73,7 +73,7 @@ fix.js format ━━━━━━━━━━━━━━━━━━━━━━ ```block check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Some errors were emitted while running checks + × Some errors were emitted while running checks. ``` diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/apply_bogus_argument.snap b/crates/rome_cli/tests/snapshots/main_commands_check/apply_bogus_argument.snap index ad9e7983726..a5af87113f2 100644 --- a/crates/rome_cli/tests/snapshots/main_commands_check/apply_bogus_argument.snap +++ b/crates/rome_cli/tests/snapshots/main_commands_check/apply_bogus_argument.snap @@ -13,7 +13,7 @@ function _13_1_3_fun(arguments) { } ```block check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Some errors were emitted while running checks + × Some errors were emitted while running checks. diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/apply_unsafe_with_error.snap b/crates/rome_cli/tests/snapshots/main_commands_check/apply_unsafe_with_error.snap index a0ff5c72b48..579041b3445 100644 --- a/crates/rome_cli/tests/snapshots/main_commands_check/apply_unsafe_with_error.snap +++ b/crates/rome_cli/tests/snapshots/main_commands_check/apply_unsafe_with_error.snap @@ -29,7 +29,7 @@ function f() { ```block check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Some errors were emitted while running checks + × Some errors were emitted while running checks. diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/check_help.snap b/crates/rome_cli/tests/snapshots/main_commands_check/check_help.snap index 0db32081be9..5c38ab43ee2 100644 --- a/crates/rome_cli/tests/snapshots/main_commands_check/check_help.snap +++ b/crates/rome_cli/tests/snapshots/main_commands_check/check_help.snap @@ -42,11 +42,12 @@ Global options applied to all commands --verbose Print additional verbose advices on diagnostics --config-path=PATH Set the filesystem path to the directory of the rome.json configuration file - --max-diagnostics=NUMBER Cap the amount of diagnostics displayed (default: 20) + --max-diagnostics=NUMBER Cap the amount of diagnostics displayed. --skip-errors Skip over files containing syntax errors instead of emitting an error diagnostic. --no-errors-on-unmatched Silence errors that would be emitted in case no files were processed during the execution of the command. + --error-on-warnings Tell Rome to exit with an error code if some diagnostics emit warnings. --json Reports information using the JSON format Available positional items: diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/check_json_files.snap b/crates/rome_cli/tests/snapshots/main_commands_check/check_json_files.snap index 501fbdb4eb1..99457626ee0 100644 --- a/crates/rome_cli/tests/snapshots/main_commands_check/check_json_files.snap +++ b/crates/rome_cli/tests/snapshots/main_commands_check/check_json_files.snap @@ -27,7 +27,7 @@ expression: content ```block check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Some errors were emitted while running checks + × Some errors were emitted while running checks. @@ -76,7 +76,7 @@ test.json format ━━━━━━━━━━━━━━━━━━━━━ ```block check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Some errors were emitted while running checks + × Some errors were emitted while running checks. ``` diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/config_recommended_group.snap b/crates/rome_cli/tests/snapshots/main_commands_check/config_recommended_group.snap index 940784d5206..c96089a99f5 100644 --- a/crates/rome_cli/tests/snapshots/main_commands_check/config_recommended_group.snap +++ b/crates/rome_cli/tests/snapshots/main_commands_check/config_recommended_group.snap @@ -28,7 +28,7 @@ new Symbol(""); ```block check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Some errors were emitted while running checks + × Some errors were emitted while running checks. @@ -74,7 +74,7 @@ check.js format ━━━━━━━━━━━━━━━━━━━━━ ```block check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Some errors were emitted while running checks + × Some errors were emitted while running checks. ``` diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/deprecated_suppression_comment.snap b/crates/rome_cli/tests/snapshots/main_commands_check/deprecated_suppression_comment.snap index 3003048287b..19889f35d84 100644 --- a/crates/rome_cli/tests/snapshots/main_commands_check/deprecated_suppression_comment.snap +++ b/crates/rome_cli/tests/snapshots/main_commands_check/deprecated_suppression_comment.snap @@ -14,7 +14,7 @@ a == b; ```block check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Some errors were emitted while running checks + × Some errors were emitted while running checks. @@ -56,7 +56,7 @@ file.js format ━━━━━━━━━━━━━━━━━━━━━ ```block check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Some errors were emitted while running checks + × Some errors were emitted while running checks. ``` diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/does_error_with_only_warnings.snap b/crates/rome_cli/tests/snapshots/main_commands_check/does_error_with_only_warnings.snap new file mode 100644 index 00000000000..c1e1f01bc57 --- /dev/null +++ b/crates/rome_cli/tests/snapshots/main_commands_check/does_error_with_only_warnings.snap @@ -0,0 +1,65 @@ +--- +source: crates/rome_cli/tests/snap_test.rs +expression: content +--- +## `rome.json` + +```json +{ + "linter": { + "rules": { + "recommended": true, + "suspicious": { + "noClassAssign": "warn" + } + } + } +} +``` + +## `file.js` + +```js +class A {} +A = 0; + +``` + +# Termination Message + +```block +check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Some warnings were emitted while running checks. + + + +``` + +# Emitted Messages + +```block +file.js:2:1 lint/suspicious/noClassAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! 'A' is a class. + + 1 │ class A {}; + > 2 │ A = 0; + │ ^ + 3 │ + + i 'A' is defined here. + + > 1 │ class A {}; + │ ^ + 2 │ A = 0; + 3 │ + + +``` + +```block +Fixed 1 file(s) in