mirror of https://github.com/astral-sh/ruff
update wording in invalid rule code diagnostics
This commit is contained in:
parent
13b3143c29
commit
9735f0af19
|
|
@ -9,6 +9,21 @@ use crate::registry::Rule;
|
|||
use crate::rule_redirects::get_redirect_target;
|
||||
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
|
||||
/// Checks for `noqa` codes that are invalid.
|
||||
///
|
||||
|
|
@ -36,12 +51,17 @@ use crate::{AlwaysFixableViolation, Edit, Fix};
|
|||
#[violation_metadata(preview_since = "0.11.4")]
|
||||
pub(crate) struct InvalidRuleCode {
|
||||
pub(crate) rule_code: String,
|
||||
pub(crate) kind: InvalidRuleCodeKind,
|
||||
}
|
||||
|
||||
impl AlwaysFixableViolation for InvalidRuleCode {
|
||||
#[derive_message_formats]
|
||||
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 {
|
||||
|
|
@ -100,6 +120,7 @@ fn all_codes_invalid_diagnostic(
|
|||
.map(Code::as_str)
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "),
|
||||
kind: InvalidRuleCodeKind::Noqa,
|
||||
},
|
||||
directive.range(),
|
||||
)
|
||||
|
|
@ -116,6 +137,7 @@ fn some_codes_are_invalid_diagnostic(
|
|||
.report_diagnostic(
|
||||
InvalidRuleCode {
|
||||
rule_code: invalid_code.to_string(),
|
||||
kind: InvalidRuleCodeKind::Noqa,
|
||||
},
|
||||
invalid_code.range(),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -576,7 +576,7 @@ help: Remove unused suppression
|
|||
90 |
|
||||
|
||||
|
||||
RUF102 [*] Invalid rule code in `# noqa`: YF829
|
||||
RUF102 [*] Invalid rule code in suppression: YF829
|
||||
--> suppressions.py:93:21
|
||||
|
|
||||
91 | def f():
|
||||
|
|
@ -596,7 +596,7 @@ help: Remove the rule code
|
|||
95 | # ruff: enable[F841, RQW320]
|
||||
|
||||
|
||||
RUF102 [*] Invalid rule code in `# noqa`: RQW320
|
||||
RUF102 [*] Invalid rule code in suppression: RQW320
|
||||
--> suppressions.py:94:27
|
||||
|
|
||||
92 | # Unknown rule codes
|
||||
|
|
@ -617,7 +617,7 @@ help: Remove the rule code
|
|||
97 | # ruff: enable[YF829]
|
||||
|
||||
|
||||
RUF102 [*] Invalid rule code in `# noqa`: RQW320
|
||||
RUF102 [*] Invalid rule code in suppression: RQW320
|
||||
--> suppressions.py:96:26
|
||||
|
|
||||
94 | # ruff: disable[F841, RQW320]
|
||||
|
|
@ -637,7 +637,7 @@ help: Remove the rule code
|
|||
99 |
|
||||
|
||||
|
||||
RUF102 [*] Invalid rule code in `# noqa`: YF829
|
||||
RUF102 [*] Invalid rule code in suppression: YF829
|
||||
--> suppressions.py:97:20
|
||||
|
|
||||
95 | value = 0
|
||||
|
|
@ -655,7 +655,7 @@ help: Remove the rule code
|
|||
99 | def f():
|
||||
|
||||
|
||||
RUF102 [*] Invalid rule code in `# noqa`: TK421
|
||||
RUF102 [*] Invalid rule code in suppression: TK421
|
||||
--> suppressions.py:102:21
|
||||
|
|
||||
100 | def f():
|
||||
|
|
@ -674,7 +674,7 @@ help: Remove the rule code
|
|||
103 | # ruff: enable[TK421]
|
||||
|
||||
|
||||
RUF102 [*] Invalid rule code in `# noqa`: TK421
|
||||
RUF102 [*] Invalid rule code in suppression: TK421
|
||||
--> suppressions.py:104:20
|
||||
|
|
||||
102 | # ruff: disable[TK421]
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use crate::codes::Rule;
|
|||
use crate::fix::edits::delete_comment;
|
||||
use crate::preview::is_range_suppressions_enabled;
|
||||
use crate::rules::ruff::rules::{
|
||||
InvalidRuleCode, InvalidSuppressionComment, InvalidSuppressionCommentKind,
|
||||
InvalidRuleCode, InvalidRuleCodeKind, InvalidSuppressionComment, InvalidSuppressionCommentKind,
|
||||
UnmatchedSuppressionComment, UnusedCodes, UnusedNOQA, UnusedNOQAKind,
|
||||
};
|
||||
use crate::settings::LinterSettings;
|
||||
|
|
@ -229,6 +229,7 @@ impl Suppressions {
|
|||
let mut diagnostic = context.report_diagnostic(
|
||||
InvalidRuleCode {
|
||||
rule_code: suppression.code.to_string(),
|
||||
kind: InvalidRuleCodeKind::Suppression,
|
||||
},
|
||||
range,
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue