From b650b7a509ef0f90dbf052091919405c426ac6b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Hugo=20Freitas=20Magalh=C3=A3es?= Date: Thu, 16 Oct 2025 19:08:33 -0300 Subject: [PATCH 1/6] feat: Make --fix respect --diagnostic-level --- .../execute/process_file/lint_and_assist.rs | 3 +- crates/biome_cli/src/execute/std_in.rs | 1 + crates/biome_cli/src/execute/traverse.rs | 3 ++ crates/biome_lsp/src/handlers/analysis.rs | 1 + crates/biome_service/src/file_handlers/css.rs | 12 +++++++- .../src/file_handlers/graphql.rs | 12 +++++++- .../src/file_handlers/javascript.rs | 12 +++++++- .../biome_service/src/file_handlers/json.rs | 12 +++++++- crates/biome_service/src/file_handlers/mod.rs | 17 ++++++++--- crates/biome_service/src/workspace.rs | 28 +++++++++++++++++++ crates/biome_service/src/workspace/server.rs | 2 ++ 11 files changed, 94 insertions(+), 9 deletions(-) diff --git a/crates/biome_cli/src/execute/process_file/lint_and_assist.rs b/crates/biome_cli/src/execute/process_file/lint_and_assist.rs index a025e4fcbeb0..fbac873580d4 100644 --- a/crates/biome_cli/src/execute/process_file/lint_and_assist.rs +++ b/crates/biome_cli/src/execute/process_file/lint_and_assist.rs @@ -65,13 +65,14 @@ pub(crate) fn analyze_with_guard<'ctx>( let fix_result = workspace_file .guard() - .fix_file( + .fix_file_with_diagnostic_level( *fix_mode, false, categories, only.clone(), skip.clone(), Some(suppression_explanation.to_string()), + Some(ctx.diagnostic_level), ) .with_file_path_and_code( workspace_file.path.to_string(), diff --git a/crates/biome_cli/src/execute/std_in.rs b/crates/biome_cli/src/execute/std_in.rs index 1420358c8828..a5dbb05bcc40 100644 --- a/crates/biome_cli/src/execute/std_in.rs +++ b/crates/biome_cli/src/execute/std_in.rs @@ -172,6 +172,7 @@ pub(crate) fn run<'a>( suppression_reason: None, enabled_rules: vec![], rule_categories: rule_categories.build(), + diagnostic_level: Some(cli_options.diagnostic_level), })?; let code = fix_file_result.code; let output = match biome_path.extension() { diff --git a/crates/biome_cli/src/execute/traverse.rs b/crates/biome_cli/src/execute/traverse.rs index 28f7512a4f14..e2a35ee63d15 100644 --- a/crates/biome_cli/src/execute/traverse.rs +++ b/crates/biome_cli/src/execute/traverse.rs @@ -84,6 +84,7 @@ pub(crate) fn traverse( skipped: &skipped, messages: sender, evaluated_paths: RwLock::default(), + diagnostic_level: cli_options.diagnostic_level, }, ); // wait for the main thread to finish @@ -447,6 +448,8 @@ pub(crate) struct TraversalOptions<'ctx, 'app> { pub(crate) messages: Sender, /// List of paths that should be processed pub(crate) evaluated_paths: RwLock>, + /// The minimum diagnostic level to fix + pub(crate) diagnostic_level: biome_diagnostics::Severity, } impl TraversalOptions<'_, '_> { diff --git a/crates/biome_lsp/src/handlers/analysis.rs b/crates/biome_lsp/src/handlers/analysis.rs index 531e009efafd..cab4928aa696 100644 --- a/crates/biome_lsp/src/handlers/analysis.rs +++ b/crates/biome_lsp/src/handlers/analysis.rs @@ -352,6 +352,7 @@ fn fix_all( enabled_rules: vec![], suppression_reason: None, rule_categories: categories.build(), + diagnostic_level: None, })?; let output = match path.as_path().extension() { diff --git a/crates/biome_service/src/file_handlers/css.rs b/crates/biome_service/src/file_handlers/css.rs index dff0fdc8929e..0f48cc1e8f9c 100644 --- a/crates/biome_service/src/file_handlers/css.rs +++ b/crates/biome_service/src/file_handlers/css.rs @@ -1,6 +1,6 @@ use super::{ AnalyzerVisitorBuilder, CodeActionsParams, EnabledForPath, ExtensionHandler, FixAllParams, - LintParams, LintResults, ParseResult, ProcessLint, SearchCapabilities, is_diagnostic_error, + LintParams, LintResults, ParseResult, ProcessLint, SearchCapabilities, get_diagnostic_severity, is_diagnostic_error, search, }; use crate::WorkspaceError; @@ -659,6 +659,16 @@ pub(crate) fn fix_all(params: FixAllParams) -> Result { if action.applicability == Applicability::MaybeIncorrect { diff --git a/crates/biome_service/src/file_handlers/graphql.rs b/crates/biome_service/src/file_handlers/graphql.rs index 7f009ae61393..9497a5bfa1ec 100644 --- a/crates/biome_service/src/file_handlers/graphql.rs +++ b/crates/biome_service/src/file_handlers/graphql.rs @@ -1,7 +1,7 @@ use super::{ AnalyzerVisitorBuilder, CodeActionsParams, DocumentFileSource, EnabledForPath, ExtensionHandler, FixAllParams, LintParams, LintResults, ParseResult, ProcessLint, - SearchCapabilities, is_diagnostic_error, + SearchCapabilities, get_diagnostic_severity, is_diagnostic_error, }; use crate::WorkspaceError; use crate::file_handlers::DebugCapabilities; @@ -564,6 +564,16 @@ pub(crate) fn fix_all(params: FixAllParams) -> Result { if action.applicability == Applicability::MaybeIncorrect { diff --git a/crates/biome_service/src/file_handlers/javascript.rs b/crates/biome_service/src/file_handlers/javascript.rs index e72945c81ceb..8c825eff4353 100644 --- a/crates/biome_service/src/file_handlers/javascript.rs +++ b/crates/biome_service/src/file_handlers/javascript.rs @@ -5,7 +5,7 @@ use super::{ }; use crate::configuration::to_analyzer_rules; use crate::diagnostics::extension_error; -use crate::file_handlers::{FixAllParams, is_diagnostic_error}; +use crate::file_handlers::{FixAllParams, get_diagnostic_severity, is_diagnostic_error}; use crate::settings::{ OverrideSettings, Settings, check_feature_activity, check_override_feature_activity, }; @@ -898,6 +898,16 @@ pub(crate) fn fix_all(params: FixAllParams) -> Result { if action.is_suppression() { diff --git a/crates/biome_service/src/file_handlers/json.rs b/crates/biome_service/src/file_handlers/json.rs index fed54cd0ad67..a1b10484c255 100644 --- a/crates/biome_service/src/file_handlers/json.rs +++ b/crates/biome_service/src/file_handlers/json.rs @@ -1,6 +1,6 @@ use super::{ AnalyzerVisitorBuilder, CodeActionsParams, DocumentFileSource, EnabledForPath, - ExtensionHandler, ParseResult, ProcessLint, SearchCapabilities, is_diagnostic_error, + ExtensionHandler, ParseResult, ProcessLint, SearchCapabilities, get_diagnostic_severity, is_diagnostic_error, }; use crate::configuration::to_analyzer_rules; use crate::file_handlers::DebugCapabilities; @@ -664,6 +664,16 @@ fn fix_all(params: FixAllParams) -> Result { continue; } + // Check if we should skip this fix based on diagnostic level + if let Some(diagnostic) = current_diagnostic.as_ref() { + if let Some(min_level) = params.diagnostic_level { + let diagnostic_severity = get_diagnostic_severity(diagnostic, rules.as_deref()); + if diagnostic_severity < min_level { + continue; + } + } + } + match params.fix_file_mode { FixFileMode::SafeFixes => { if action.applicability == Applicability::MaybeIncorrect { diff --git a/crates/biome_service/src/file_handlers/mod.rs b/crates/biome_service/src/file_handlers/mod.rs index a30b1eb66e6b..c1af0e6e2036 100644 --- a/crates/biome_service/src/file_handlers/mod.rs +++ b/crates/biome_service/src/file_handlers/mod.rs @@ -414,6 +414,8 @@ pub struct FixAllParams<'a> { pub(crate) suppression_reason: Option, pub(crate) enabled_rules: Vec, pub(crate) plugins: AnalyzerPluginVec, + /// The minimum diagnostic level to fix + pub(crate) diagnostic_level: Option, } #[derive(Default)] @@ -744,7 +746,16 @@ pub(crate) fn is_diagnostic_error( diagnostic: &'_ AnalyzerDiagnostic, rules: Option<&'_ Rules>, ) -> bool { - let severity = diagnostic + let severity = get_diagnostic_severity(diagnostic, rules); + severity >= Severity::Error +} + +/// Gets the effective severity of a diagnostic, taking into account rule configuration +pub(crate) fn get_diagnostic_severity( + diagnostic: &'_ AnalyzerDiagnostic, + rules: Option<&'_ Rules>, +) -> Severity { + diagnostic .category() .filter(|category| category.name().starts_with("lint/")) .map_or_else( @@ -756,9 +767,7 @@ pub(crate) fn is_diagnostic_error( }) .unwrap_or(Severity::Warning) }, - ); - - severity >= Severity::Error + ) } /// Parse the "lang" attribute from the opening tag of the "\" block in Svelte or Vue files. diff --git a/crates/biome_service/src/workspace.rs b/crates/biome_service/src/workspace.rs index 752aba4dc3eb..6019012e8f7b 100644 --- a/crates/biome_service/src/workspace.rs +++ b/crates/biome_service/src/workspace.rs @@ -1028,6 +1028,9 @@ pub struct FixFileParams { pub rule_categories: RuleCategories, #[serde(default)] pub suppression_reason: Option, + /// The minimum diagnostic level to fix + #[serde(default)] + pub diagnostic_level: Option, } #[derive(Debug, serde::Serialize, serde::Deserialize)] @@ -1721,6 +1724,31 @@ impl<'app, W: Workspace + ?Sized> FileGuard<'app, W> { rule_categories, suppression_reason, enabled_rules: vec![], + diagnostic_level: None, + }) + } + + pub fn fix_file_with_diagnostic_level( + &self, + fix_file_mode: FixFileMode, + should_format: bool, + rule_categories: RuleCategories, + only: Vec, + skip: Vec, + suppression_reason: Option, + diagnostic_level: Option, + ) -> Result { + self.workspace.fix_file(FixFileParams { + project_key: self.project_key, + path: self.path.clone(), + fix_file_mode, + should_format, + only, + skip, + rule_categories, + suppression_reason, + enabled_rules: vec![], + diagnostic_level, }) } diff --git a/crates/biome_service/src/workspace/server.rs b/crates/biome_service/src/workspace/server.rs index 02433def994f..d6d934e29679 100644 --- a/crates/biome_service/src/workspace/server.rs +++ b/crates/biome_service/src/workspace/server.rs @@ -1519,6 +1519,7 @@ impl Workspace for WorkspaceServer { enabled_rules, rule_categories, suppression_reason, + diagnostic_level, } = params; let capabilities = self.get_file_capabilities(&path); @@ -1558,6 +1559,7 @@ impl Workspace for WorkspaceServer { } else { Vec::new() }, + diagnostic_level, }) } From 40d45d7fdb44dafbb1909c29994d978a7655fbc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Hugo=20Freitas=20Magalh=C3=A3es?= Date: Thu, 16 Oct 2025 19:08:50 -0300 Subject: [PATCH 2/6] test: Implement tests for new functionality --- crates/biome_cli/tests/commands/check.rs | 206 ++++++++++++++++++ crates/biome_cli/tests/commands/lint.rs | 158 ++++++++++++++ ...ic_level_error_only_fixes_error_level.snap | 38 ++++ ...iagnostic_level_info_fixes_all_levels.snap | 38 ++++ ...evel_warn_fixes_warn_and_error_levels.snap | 38 ++++ ...stic_level_without_fix_respects_level.snap | 85 ++++++++ ...ic_level_error_only_fixes_error_level.snap | 38 ++++ ...iagnostic_level_info_fixes_all_levels.snap | 38 ++++ ...stic_level_without_fix_respects_level.snap | 70 ++++++ crates/biome_service/src/workspace.tests.rs | 122 +++++++++++ 10 files changed, 831 insertions(+) create mode 100644 crates/biome_cli/tests/snapshots/main_commands_check/diagnostic_level_error_only_fixes_error_level.snap create mode 100644 crates/biome_cli/tests/snapshots/main_commands_check/diagnostic_level_info_fixes_all_levels.snap create mode 100644 crates/biome_cli/tests/snapshots/main_commands_check/diagnostic_level_warn_fixes_warn_and_error_levels.snap create mode 100644 crates/biome_cli/tests/snapshots/main_commands_check/diagnostic_level_without_fix_respects_level.snap create mode 100644 crates/biome_cli/tests/snapshots/main_commands_lint/lint_diagnostic_level_error_only_fixes_error_level.snap create mode 100644 crates/biome_cli/tests/snapshots/main_commands_lint/lint_diagnostic_level_info_fixes_all_levels.snap create mode 100644 crates/biome_cli/tests/snapshots/main_commands_lint/lint_diagnostic_level_without_fix_respects_level.snap diff --git a/crates/biome_cli/tests/commands/check.rs b/crates/biome_cli/tests/commands/check.rs index 6c8e39fc84b2..c2ffd7641023 100644 --- a/crates/biome_cli/tests/commands/check.rs +++ b/crates/biome_cli/tests/commands/check.rs @@ -54,6 +54,30 @@ const NO_DEBUGGER_AFTER: &str = "debugger;\n"; const UPGRADE_SEVERITY_CODE: &str = r#"if(!cond) { exprA(); } else { exprB() }"#; +// Test code for diagnostic level with fix functionality +const DIAGNOSTIC_LEVEL_TEST_BEFORE: &str = r#"let x: number | undefined = undefined; +if (x == 1) { + console.log(x); +} +"#; + +const DIAGNOSTIC_LEVEL_TEST_CONFIG: &str = r#"{ + "linter": { + "enabled": true, + "rules": { + "recommended": false, + "complexity": { + "noUselessUndefinedInitialization": "info" + }, + "suspicious": { + "noDoubleEquals": "error" + } + } + } +} +"#; + + const NURSERY_UNSTABLE: &str = r#"if(a = b) {}"#; #[test] @@ -3251,3 +3275,185 @@ fn check_does_not_enable_assist() { result, )); } + +#[test] +fn diagnostic_level_error_only_fixes_error_level() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path = Utf8Path::new("test.ts"); + let config_path = Utf8Path::new("biome.json"); + + fs.insert(file_path.into(), DIAGNOSTIC_LEVEL_TEST_BEFORE.as_bytes()); + fs.insert(config_path.into(), DIAGNOSTIC_LEVEL_TEST_CONFIG.as_bytes()); + + let (fs, result) = run_cli( + fs, + &mut console, + Args::from([ + "check", + "--diagnostic-level=error", + "--fix", + "--unsafe", + file_path.as_str(), + ] + .as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let mut buffer = String::new(); + fs.open(file_path) + .unwrap() + .read_to_string(&mut buffer) + .unwrap(); + + // Should only fix the error-level violation (noDoubleEquals), not the info-level one + // Verify that == was changed to === (error-level fix applied) + assert!(buffer.contains("x === 1"), "Error-level fix should be applied: == -> ==="); + // Verify that undefined initialization was NOT removed (info-level fix not applied) + assert!(buffer.contains("= undefined"), "Info-level fix should NOT be applied: = undefined should remain"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "diagnostic_level_error_only_fixes_error_level", + fs, + console, + result, + )); +} + +#[test] +fn diagnostic_level_info_fixes_all_levels() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path = Utf8Path::new("test.ts"); + let config_path = Utf8Path::new("biome.json"); + + fs.insert(file_path.into(), DIAGNOSTIC_LEVEL_TEST_BEFORE.as_bytes()); + fs.insert(config_path.into(), DIAGNOSTIC_LEVEL_TEST_CONFIG.as_bytes()); + + let (fs, result) = run_cli( + fs, + &mut console, + Args::from([ + "check", + "--diagnostic-level=info", + "--fix", + "--unsafe", + file_path.as_str(), + ] + .as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let mut buffer = String::new(); + fs.open(file_path) + .unwrap() + .read_to_string(&mut buffer) + .unwrap(); + + // Should fix both info-level and error-level violations + // Verify that == was changed to === (error-level fix applied) + assert!(buffer.contains("x === 1"), "Error-level fix should be applied: == -> ==="); + // Verify that undefined initialization was removed (info-level fix applied) + assert!(!buffer.contains("= undefined"), "Info-level fix should be applied: = undefined should be removed"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "diagnostic_level_info_fixes_all_levels", + fs, + console, + result, + )); +} + +#[test] +fn diagnostic_level_warn_fixes_warn_and_error_levels() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path = Utf8Path::new("test.ts"); + let config_path = Utf8Path::new("biome.json"); + + fs.insert(file_path.into(), DIAGNOSTIC_LEVEL_TEST_BEFORE.as_bytes()); + fs.insert(config_path.into(), DIAGNOSTIC_LEVEL_TEST_CONFIG.as_bytes()); + + let (fs, result) = run_cli( + fs, + &mut console, + Args::from([ + "check", + "--diagnostic-level=warn", + "--fix", + "--unsafe", + file_path.as_str(), + ] + .as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let mut buffer = String::new(); + fs.open(file_path) + .unwrap() + .read_to_string(&mut buffer) + .unwrap(); + + // Should only fix the error-level violation (warn < error), not the info-level one + // Verify that == was changed to === (error-level fix applied) + assert!(buffer.contains("x === 1"), "Error-level fix should be applied: == -> ==="); + // Verify that undefined initialization was NOT removed (info-level fix not applied) + assert!(buffer.contains("= undefined"), "Info-level fix should NOT be applied: = undefined should remain"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "diagnostic_level_warn_fixes_warn_and_error_levels", + fs, + console, + result, + )); +} + +#[test] +fn diagnostic_level_without_fix_respects_level() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path = Utf8Path::new("test.ts"); + let config_path = Utf8Path::new("biome.json"); + + fs.insert(file_path.into(), DIAGNOSTIC_LEVEL_TEST_BEFORE.as_bytes()); + fs.insert(config_path.into(), DIAGNOSTIC_LEVEL_TEST_CONFIG.as_bytes()); + + let (fs, result) = run_cli( + fs, + &mut console, + Args::from([ + "check", + "--diagnostic-level=error", + file_path.as_str(), + ] + .as_slice()), + ); + + assert!(result.is_err(), "run_cli returned {result:?}"); + + // File should remain unchanged + let mut buffer = String::new(); + fs.open(file_path) + .unwrap() + .read_to_string(&mut buffer) + .unwrap(); + assert_eq!(buffer, DIAGNOSTIC_LEVEL_TEST_BEFORE); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "diagnostic_level_without_fix_respects_level", + fs, + console, + result, + )); +} diff --git a/crates/biome_cli/tests/commands/lint.rs b/crates/biome_cli/tests/commands/lint.rs index a9a734160715..f34a261065ee 100644 --- a/crates/biome_cli/tests/commands/lint.rs +++ b/crates/biome_cli/tests/commands/lint.rs @@ -52,6 +52,29 @@ const NO_DEBUGGER_AFTER: &str = "debugger;\n"; const UPGRADE_SEVERITY_CODE: &str = r#"if(!cond) { exprA(); } else { exprB() }"#; +// Test code for diagnostic level with fix functionality +const DIAGNOSTIC_LEVEL_TEST_BEFORE: &str = r#"let x: number | undefined = undefined; +if (x == 1) { + console.log(x); +} +"#; + +const DIAGNOSTIC_LEVEL_TEST_CONFIG: &str = r#"{ + "linter": { + "enabled": true, + "rules": { + "recommended": false, + "complexity": { + "noUselessUndefinedInitialization": "info" + }, + "suspicious": { + "noDoubleEquals": "error" + } + } + } +} +"#; + const NURSERY_UNSTABLE: &str = r#"if(a = b) {}"#; #[test] @@ -4339,3 +4362,138 @@ fn should_not_choke_on_recursive_function_call() { result, )); } + +#[test] +fn lint_diagnostic_level_error_only_fixes_error_level() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path = Utf8Path::new("test.ts"); + let config_path = Utf8Path::new("biome.json"); + + fs.insert(file_path.into(), DIAGNOSTIC_LEVEL_TEST_BEFORE.as_bytes()); + fs.insert(config_path.into(), DIAGNOSTIC_LEVEL_TEST_CONFIG.as_bytes()); + + let (fs, result) = run_cli( + fs, + &mut console, + Args::from([ + "lint", + "--diagnostic-level=error", + "--fix", + "--unsafe", + file_path.as_str(), + ] + .as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let mut buffer = String::new(); + fs.open(file_path) + .unwrap() + .read_to_string(&mut buffer) + .unwrap(); + + // Should only fix the error-level violation (noDoubleEquals), not the info-level one + // Verify that == was changed to === (error-level fix applied) + assert!(buffer.contains("x === 1"), "Error-level fix should be applied: == -> ==="); + // Verify that undefined initialization was NOT removed (info-level fix not applied) + assert!(buffer.contains("= undefined"), "Info-level fix should NOT be applied: = undefined should remain"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "lint_diagnostic_level_error_only_fixes_error_level", + fs, + console, + result, + )); +} + +#[test] +fn lint_diagnostic_level_info_fixes_all_levels() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path = Utf8Path::new("test.ts"); + let config_path = Utf8Path::new("biome.json"); + + fs.insert(file_path.into(), DIAGNOSTIC_LEVEL_TEST_BEFORE.as_bytes()); + fs.insert(config_path.into(), DIAGNOSTIC_LEVEL_TEST_CONFIG.as_bytes()); + + let (fs, result) = run_cli( + fs, + &mut console, + Args::from([ + "lint", + "--diagnostic-level=info", + "--fix", + "--unsafe", + file_path.as_str(), + ] + .as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let mut buffer = String::new(); + fs.open(file_path) + .unwrap() + .read_to_string(&mut buffer) + .unwrap(); + + // Should fix both info-level and error-level violations + // Verify that == was changed to === (error-level fix applied) + assert!(buffer.contains("x === 1"), "Error-level fix should be applied: == -> ==="); + // Verify that undefined initialization was removed (info-level fix applied) + assert!(!buffer.contains("= undefined"), "Info-level fix should be applied: = undefined should be removed"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "lint_diagnostic_level_info_fixes_all_levels", + fs, + console, + result, + )); +} + +#[test] +fn lint_diagnostic_level_without_fix_respects_level() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path = Utf8Path::new("test.ts"); + let config_path = Utf8Path::new("biome.json"); + + fs.insert(file_path.into(), DIAGNOSTIC_LEVEL_TEST_BEFORE.as_bytes()); + fs.insert(config_path.into(), DIAGNOSTIC_LEVEL_TEST_CONFIG.as_bytes()); + + let (fs, result) = run_cli( + fs, + &mut console, + Args::from([ + "lint", + "--diagnostic-level=error", + file_path.as_str(), + ] + .as_slice()), + ); + + assert!(result.is_err(), "run_cli returned {result:?}"); + + // File should remain unchanged + let mut buffer = String::new(); + fs.open(file_path) + .unwrap() + .read_to_string(&mut buffer) + .unwrap(); + assert_eq!(buffer, DIAGNOSTIC_LEVEL_TEST_BEFORE); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "lint_diagnostic_level_without_fix_respects_level", + fs, + console, + result, + )); +} diff --git a/crates/biome_cli/tests/snapshots/main_commands_check/diagnostic_level_error_only_fixes_error_level.snap b/crates/biome_cli/tests/snapshots/main_commands_check/diagnostic_level_error_only_fixes_error_level.snap new file mode 100644 index 000000000000..50eacb4462e7 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_commands_check/diagnostic_level_error_only_fixes_error_level.snap @@ -0,0 +1,38 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: redactor(content) +--- +## `biome.json` + +```json +{ + "linter": { + "enabled": true, + "rules": { + "recommended": false, + "complexity": { + "noUselessUndefinedInitialization": "info" + }, + "suspicious": { + "noDoubleEquals": "error" + } + } + } +} +``` + +## `test.ts` + +```ts +let x: number | undefined = undefined; +if (x === 1) { + console.log(x); +} + +``` + +# Emitted Messages + +```block +Checked 1 file in