update wording in invalid rule code diagnostics

This commit is contained in:
Amethyst Reese 2025-12-16 18:17:17 -08:00
parent 13b3143c29
commit 9735f0af19
3 changed files with 31 additions and 8 deletions

View File

@ -9,6 +9,21 @@ use crate::registry::Rule;
use crate::rule_redirects::get_redirect_target; use crate::rule_redirects::get_redirect_target;
use crate::{AlwaysFixableViolation, Edit, Fix}; use crate::{AlwaysFixableViolation, Edit, Fix};
#[derive(Debug, PartialEq, Eq)]
pub(crate) enum InvalidRuleCodeKind {
Noqa,
Suppression,
}
impl InvalidRuleCodeKind {
fn as_str(&self) -> &str {
match self {
InvalidRuleCodeKind::Noqa => "`# noqa`",
InvalidRuleCodeKind::Suppression => "suppression",
}
}
}
/// ## What it does /// ## What it does
/// Checks for `noqa` codes that are invalid. /// Checks for `noqa` codes that are invalid.
/// ///
@ -36,12 +51,17 @@ use crate::{AlwaysFixableViolation, Edit, Fix};
#[violation_metadata(preview_since = "0.11.4")] #[violation_metadata(preview_since = "0.11.4")]
pub(crate) struct InvalidRuleCode { pub(crate) struct InvalidRuleCode {
pub(crate) rule_code: String, pub(crate) rule_code: String,
pub(crate) kind: InvalidRuleCodeKind,
} }
impl AlwaysFixableViolation for InvalidRuleCode { impl AlwaysFixableViolation for InvalidRuleCode {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
format!("Invalid rule code in `# noqa`: {}", self.rule_code) format!(
"Invalid rule code in {}: {}",
self.kind.as_str(),
self.rule_code
)
} }
fn fix_title(&self) -> String { fn fix_title(&self) -> String {
@ -100,6 +120,7 @@ fn all_codes_invalid_diagnostic(
.map(Code::as_str) .map(Code::as_str)
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "), .join(", "),
kind: InvalidRuleCodeKind::Noqa,
}, },
directive.range(), directive.range(),
) )
@ -116,6 +137,7 @@ fn some_codes_are_invalid_diagnostic(
.report_diagnostic( .report_diagnostic(
InvalidRuleCode { InvalidRuleCode {
rule_code: invalid_code.to_string(), rule_code: invalid_code.to_string(),
kind: InvalidRuleCodeKind::Noqa,
}, },
invalid_code.range(), invalid_code.range(),
) )

View File

@ -576,7 +576,7 @@ help: Remove unused suppression
90 | 90 |
RUF102 [*] Invalid rule code in `# noqa`: YF829 RUF102 [*] Invalid rule code in suppression: YF829
--> suppressions.py:93:21 --> suppressions.py:93:21
| |
91 | def f(): 91 | def f():
@ -596,7 +596,7 @@ help: Remove the rule code
95 | # ruff: enable[F841, RQW320] 95 | # ruff: enable[F841, RQW320]
RUF102 [*] Invalid rule code in `# noqa`: RQW320 RUF102 [*] Invalid rule code in suppression: RQW320
--> suppressions.py:94:27 --> suppressions.py:94:27
| |
92 | # Unknown rule codes 92 | # Unknown rule codes
@ -617,7 +617,7 @@ help: Remove the rule code
97 | # ruff: enable[YF829] 97 | # ruff: enable[YF829]
RUF102 [*] Invalid rule code in `# noqa`: RQW320 RUF102 [*] Invalid rule code in suppression: RQW320
--> suppressions.py:96:26 --> suppressions.py:96:26
| |
94 | # ruff: disable[F841, RQW320] 94 | # ruff: disable[F841, RQW320]
@ -637,7 +637,7 @@ help: Remove the rule code
99 | 99 |
RUF102 [*] Invalid rule code in `# noqa`: YF829 RUF102 [*] Invalid rule code in suppression: YF829
--> suppressions.py:97:20 --> suppressions.py:97:20
| |
95 | value = 0 95 | value = 0
@ -655,7 +655,7 @@ help: Remove the rule code
99 | def f(): 99 | def f():
RUF102 [*] Invalid rule code in `# noqa`: TK421 RUF102 [*] Invalid rule code in suppression: TK421
--> suppressions.py:102:21 --> suppressions.py:102:21
| |
100 | def f(): 100 | def f():
@ -674,7 +674,7 @@ help: Remove the rule code
103 | # ruff: enable[TK421] 103 | # ruff: enable[TK421]
RUF102 [*] Invalid rule code in `# noqa`: TK421 RUF102 [*] Invalid rule code in suppression: TK421
--> suppressions.py:104:20 --> suppressions.py:104:20
| |
102 | # ruff: disable[TK421] 102 | # ruff: disable[TK421]

View File

@ -19,7 +19,7 @@ use crate::codes::Rule;
use crate::fix::edits::delete_comment; use crate::fix::edits::delete_comment;
use crate::preview::is_range_suppressions_enabled; use crate::preview::is_range_suppressions_enabled;
use crate::rules::ruff::rules::{ use crate::rules::ruff::rules::{
InvalidRuleCode, InvalidSuppressionComment, InvalidSuppressionCommentKind, InvalidRuleCode, InvalidRuleCodeKind, InvalidSuppressionComment, InvalidSuppressionCommentKind,
UnmatchedSuppressionComment, UnusedCodes, UnusedNOQA, UnusedNOQAKind, UnmatchedSuppressionComment, UnusedCodes, UnusedNOQA, UnusedNOQAKind,
}; };
use crate::settings::LinterSettings; use crate::settings::LinterSettings;
@ -229,6 +229,7 @@ impl Suppressions {
let mut diagnostic = context.report_diagnostic( let mut diagnostic = context.report_diagnostic(
InvalidRuleCode { InvalidRuleCode {
rule_code: suppression.code.to_string(), rule_code: suppression.code.to_string(),
kind: InvalidRuleCodeKind::Suppression,
}, },
range, range,
); );