diff --git a/crates/ruff_linter/src/rules/ruff/mod.rs b/crates/ruff_linter/src/rules/ruff/mod.rs index c2d03fb1ae..ad18e24d59 100644 --- a/crates/ruff_linter/src/rules/ruff/mod.rs +++ b/crates/ruff_linter/src/rules/ruff/mod.rs @@ -313,11 +313,17 @@ mod tests { Rule::UnusedVariable, Rule::AmbiguousVariableName, Rule::UnusedNOQA, + Rule::InvalidRuleCode, + Rule::InvalidSuppressionComment, + Rule::UnmatchedSuppressionComment, ]), &settings::LinterSettings::for_rules(vec![ Rule::UnusedVariable, Rule::AmbiguousVariableName, Rule::UnusedNOQA, + Rule::InvalidRuleCode, + Rule::InvalidSuppressionComment, + Rule::UnmatchedSuppressionComment, ]) .with_preview_mode(), ); diff --git a/crates/ruff_linter/src/rules/ruff/rules/invalid_suppression_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/invalid_suppression_comment.rs index 54e2da0434..25b9eb2ebb 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/invalid_suppression_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/invalid_suppression_comment.rs @@ -30,7 +30,7 @@ pub(crate) struct InvalidSuppressionComment { pub kind: InvalidSuppressionCommentKind, } -impl Violation for InvalidSuppressionComment { +impl AlwaysFixableViolation for InvalidSuppressionComment { #[derive_message_formats] fn message(&self) -> String { let msg = match self.kind { @@ -48,8 +48,8 @@ impl Violation for InvalidSuppressionComment { format!("Invalid suppression comment: {msg}") } - fn fix_title(&self) -> Option { - Some("Remove invalid suppression comment".to_string()) + fn fix_title(&self) -> String { + "Remove invalid suppression comment".to_string() } } diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__range_suppressions.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__range_suppressions.snap index 908cca2cbd..0094d8474a 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__range_suppressions.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__range_suppressions.snap @@ -7,7 +7,7 @@ source: crates/ruff_linter/src/rules/ruff/mod.rs --- Summary --- Removed: 14 -Added: 18 +Added: 19 --- Removed --- E741 Ambiguous variable name: `I` @@ -251,6 +251,24 @@ RUF104 Unmatched suppression comment | +RUF103 [*] Invalid suppression comment: no matching 'disable' comment + --> suppressions.py:19:5 + | +17 | # should be generated. +18 | I = 1 +19 | # ruff: enable[E741, F841] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: Remove invalid suppression comment +16 | # Neither warning is ignored, and an "unmatched suppression" +17 | # should be generated. +18 | I = 1 + - # ruff: enable[E741, F841] +19 | +20 | +21 | def f(): + + RUF100 [*] Unused suppression (non-enabled: `E501`) --> suppressions.py:46:5 | diff --git a/crates/ruff_linter/src/suppression.rs b/crates/ruff_linter/src/suppression.rs index fd5e2064ba..83acaffe4f 100644 --- a/crates/ruff_linter/src/suppression.rs +++ b/crates/ruff_linter/src/suppression.rs @@ -251,7 +251,6 @@ impl Suppressions { diagnostic.set_fix(Fix::safe_edit(delete_comment(error.range, locator))); } - // TODO: sometimes these don't get fixes attached? for invalid in &self.invalid { let mut diagnostic = context.report_diagnostic( InvalidSuppressionComment {