mirror of https://github.com/astral-sh/ruff
Fix test cases causing panics
This commit is contained in:
parent
61b48fbcc4
commit
e19ddb6e15
|
|
@ -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(),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue