Fix test cases causing panics

This commit is contained in:
Amethyst Reese 2025-12-11 15:05:06 -08:00
parent 61b48fbcc4
commit e19ddb6e15
4 changed files with 28 additions and 5 deletions

View File

@ -313,11 +313,17 @@ mod tests {
Rule::UnusedVariable, Rule::UnusedVariable,
Rule::AmbiguousVariableName, Rule::AmbiguousVariableName,
Rule::UnusedNOQA, Rule::UnusedNOQA,
Rule::InvalidRuleCode,
Rule::InvalidSuppressionComment,
Rule::UnmatchedSuppressionComment,
]), ]),
&settings::LinterSettings::for_rules(vec![ &settings::LinterSettings::for_rules(vec![
Rule::UnusedVariable, Rule::UnusedVariable,
Rule::AmbiguousVariableName, Rule::AmbiguousVariableName,
Rule::UnusedNOQA, Rule::UnusedNOQA,
Rule::InvalidRuleCode,
Rule::InvalidSuppressionComment,
Rule::UnmatchedSuppressionComment,
]) ])
.with_preview_mode(), .with_preview_mode(),
); );

View File

@ -30,7 +30,7 @@ pub(crate) struct InvalidSuppressionComment {
pub kind: InvalidSuppressionCommentKind, pub kind: InvalidSuppressionCommentKind,
} }
impl Violation for InvalidSuppressionComment { impl AlwaysFixableViolation for InvalidSuppressionComment {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
let msg = match self.kind { let msg = match self.kind {
@ -48,8 +48,8 @@ impl Violation for InvalidSuppressionComment {
format!("Invalid suppression comment: {msg}") format!("Invalid suppression comment: {msg}")
} }
fn fix_title(&self) -> Option<String> { fn fix_title(&self) -> String {
Some("Remove invalid suppression comment".to_string()) "Remove invalid suppression comment".to_string()
} }
} }

View File

@ -7,7 +7,7 @@ source: crates/ruff_linter/src/rules/ruff/mod.rs
--- Summary --- --- Summary ---
Removed: 14 Removed: 14
Added: 18 Added: 19
--- Removed --- --- Removed ---
E741 Ambiguous variable name: `I` 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`) RUF100 [*] Unused suppression (non-enabled: `E501`)
--> suppressions.py:46:5 --> suppressions.py:46:5
| |

View File

@ -251,7 +251,6 @@ impl Suppressions {
diagnostic.set_fix(Fix::safe_edit(delete_comment(error.range, locator))); diagnostic.set_fix(Fix::safe_edit(delete_comment(error.range, locator)));
} }
// TODO: sometimes these don't get fixes attached?
for invalid in &self.invalid { for invalid in &self.invalid {
let mut diagnostic = context.report_diagnostic( let mut diagnostic = context.report_diagnostic(
InvalidSuppressionComment { InvalidSuppressionComment {