diff --git a/.changeset/fix-suppress-only-overrides.md b/.changeset/fix-suppress-only-overrides.md new file mode 100644 index 000000000000..07d612aeb21f --- /dev/null +++ b/.changeset/fix-suppress-only-overrides.md @@ -0,0 +1,7 @@ +--- +"@biomejs/biome": patch +--- + +Fixed [#10113](https://github.com/biomejs/biome/issues/10113): `--suppress` with `--only` no longer ignores overrides that disable a rule. + +Previously, running `biome lint --suppress --only=lint/suspicious/noDebugger` would add suppression comments to files where the rule was disabled by an override. Now, overrides that set a rule to `"off"` are always respected, regardless of whether `--only` is active. diff --git a/crates/biome_cli/tests/cases/suppressions.rs b/crates/biome_cli/tests/cases/suppressions.rs index 064c15645dc5..9d5f2686313e 100644 --- a/crates/biome_cli/tests/cases/suppressions.rs +++ b/crates/biome_cli/tests/cases/suppressions.rs @@ -278,6 +278,93 @@ fn custom_explanation_with_reason() { )); } +#[test] +fn suppress_only_respects_override_disabling_rule() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + // Config: noDebugger enabled at root, disabled for foo/** + let config_path = Utf8Path::new("biome.json"); + fs.insert( + config_path.into(), + r#"{ + "linter": { + "rules": { + "suspicious": { + "noDebugger": "error" + } + } + }, + "overrides": [{ + "includes": ["foo/**"], + "linter": { + "rules": { + "suspicious": { + "noDebugger": "off" + } + } + } + }] +}"# + .as_bytes(), + ); + + // File in normal path: should get suppression + let regular_path = Utf8Path::new("src/regular.js"); + fs.insert(regular_path.into(), b"debugger;" as &[u8]); + + // File in overridden path: should NOT get suppression (rule is off) + let overridden_path = Utf8Path::new("foo/overridden.js"); + fs.insert(overridden_path.into(), b"debugger;" as &[u8]); + + let (fs, result) = run_cli( + fs, + &mut console, + Args::from( + [ + "lint", + "--suppress", + "--only=lint/suspicious/noDebugger", + regular_path.as_str(), + overridden_path.as_str(), + ] + .as_slice(), + ), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + // The overridden file should be unchanged (no suppression comment added) + let mut overridden_content = String::new(); + fs.open(overridden_path) + .unwrap() + .read_to_string(&mut overridden_content) + .unwrap(); + assert_eq!( + overridden_content, "debugger;", + "override-disabled file should not receive a suppression comment" + ); + + // The regular file should have the suppression comment + let mut regular_content = String::new(); + fs.open(regular_path) + .unwrap() + .read_to_string(&mut regular_content) + .unwrap(); + assert!( + regular_content.contains("biome-ignore lint/suspicious/noDebugger"), + "regular file should receive a noDebugger suppression comment" + ); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "suppress_only_respects_override_disabling_rule", + fs, + console, + result, + )); +} + #[test] fn unused_suppression_after_top_level() { let fs = MemoryFileSystem::default(); diff --git a/crates/biome_cli/tests/snapshots/main_cases_suppressions/suppress_only_respects_override_disabling_rule.snap b/crates/biome_cli/tests/snapshots/main_cases_suppressions/suppress_only_respects_override_disabling_rule.snap new file mode 100644 index 000000000000..56739bc28f92 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_suppressions/suppress_only_respects_override_disabling_rule.snap @@ -0,0 +1,49 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +assertion_line: 520 +expression: redactor(content) +--- +## `biome.json` + +```json +{ + "linter": { + "rules": { + "suspicious": { + "noDebugger": "error" + } + } + }, + "overrides": [ + { + "includes": ["foo/**"], + "linter": { + "rules": { + "suspicious": { + "noDebugger": "off" + } + } + } + } + ] +} +``` + +## `foo/overridden.js` + +```js +debugger; +``` + +## `src/regular.js` + +```js +// biome-ignore lint/suspicious/noDebugger: ignored using `--suppress` +debugger; +``` + +# Emitted Messages + +```block +Checked 2 files in