Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fix-suppress-only-overrides.md
Original file line number Diff line number Diff line change
@@ -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.
87 changes: 87 additions & 0 deletions crates/biome_cli/tests/cases/suppressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <TIME>. Fixed 1 file.
```
10 changes: 8 additions & 2 deletions crates/biome_service/src/file_handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1700,8 +1700,11 @@ impl<'a, 'b> LintVisitor<'a, 'b> {
.unwrap_or_default();
if !has_only_filter {
self.enabled_rules.extend(rules.as_enabled_rules());
self.disabled_rules.extend(rules.as_disabled_rules());
}
// Always respect overrides that disable rules, even when --only is active.
// Without this, --suppress with --only would add suppression comments to
// files where the rule is disabled by an override.
self.disabled_rules.extend(rules.as_disabled_rules());
Comment thread
blackwell-systems marked this conversation as resolved.
let fixable_rules = self
.enabled_rules
.iter()
Expand Down Expand Up @@ -1988,8 +1991,11 @@ impl<'a, 'b> AssistsVisitor<'a, 'b> {
.unwrap_or_default();
if !has_only_filter {
self.enabled_rules.extend(rules.as_enabled_rules());
self.disabled_rules.extend(rules.as_disabled_rules());
}
// Always respect overrides that disable rules, even when --only is active.
// Without this, --suppress with --only would add suppression comments to
// files where the rule is disabled by an override.
self.disabled_rules.extend(rules.as_disabled_rules());
let fixable_rules = self
.enabled_rules
.iter()
Expand Down