many-to-one 1/9: Rename Rule::code to Rule::noqa_code

Post this commit series several codes can be mapped to a single rule,
this commit therefore renames Rule::code to Rule::noqa_code,
which is the code that --add-noqa will add to ignore a rule.
This commit is contained in:
Martin Fischer 2023-01-30 06:30:36 +01:00 committed by Charlie Marsh
parent 502ce80c91
commit d451c7a506
36 changed files with 66 additions and 62 deletions

View file

@ -55,13 +55,13 @@ pub fn check_noqa(
});
match noqa {
(Directive::All(..), matches) => {
matches.push(diagnostic.kind.rule().code());
matches.push(diagnostic.kind.rule().noqa_code());
ignored.push(index);
continue;
}
(Directive::Codes(.., codes), matches) => {
if noqa::includes(diagnostic.kind.rule(), codes) {
matches.push(diagnostic.kind.rule().code());
matches.push(diagnostic.kind.rule().noqa_code());
ignored.push(index);
continue;
}
@ -82,12 +82,12 @@ pub fn check_noqa(
.or_insert_with(|| (noqa::extract_noqa_directive(lines[noqa_lineno - 1]), vec![]));
match noqa {
(Directive::All(..), matches) => {
matches.push(diagnostic.kind.rule().code());
matches.push(diagnostic.kind.rule().noqa_code());
ignored.push(index);
}
(Directive::Codes(.., codes), matches) => {
if noqa::includes(diagnostic.kind.rule(), codes) {
matches.push(diagnostic.kind.rule().code());
matches.push(diagnostic.kind.rule().noqa_code());
ignored.push(index);
}
}
@ -128,7 +128,7 @@ pub fn check_noqa(
let mut self_ignore = false;
for code in codes {
let code = get_redirect_target(code).unwrap_or(code);
if code == Rule::UnusedNOQA.code() {
if code == Rule::UnusedNOQA.noqa_code() {
self_ignore = true;
break;
}

View file

@ -66,7 +66,7 @@ impl Serialize for SerializeRuleAsCode {
where
S: serde::Serializer,
{
serializer.serialize_str(self.0.code())
serializer.serialize_str(self.0.noqa_code())
}
}

View file

@ -72,7 +72,7 @@ pub fn extract_noqa_directive(line: &str) -> Directive {
/// Returns `true` if the string list of `codes` includes `code` (or an alias
/// thereof).
pub fn includes(needle: &Rule, haystack: &[&str]) -> bool {
let needle: &str = needle.code();
let needle: &str = needle.noqa_code();
haystack
.iter()
.any(|candidate| needle == get_redirect_target(candidate).unwrap_or(candidate))
@ -205,7 +205,7 @@ fn add_noqa_inner(
output.push_str(" # noqa: ");
// Add codes.
let codes: Vec<&str> = rules.iter().map(|r| r.code()).collect();
let codes: Vec<&str> = rules.iter().map(|r| r.noqa_code()).collect();
let suffix = codes.join(", ");
output.push_str(&suffix);
output.push_str(line_ending);
@ -230,7 +230,7 @@ fn add_noqa_inner(
// Add codes.
let codes: Vec<&str> = rules
.iter()
.map(|r| r.code())
.map(|r| r.noqa_code())
.chain(existing.into_iter())
.sorted_unstable()
.collect();

View file

@ -895,7 +895,7 @@ mod tests {
fn check_code_serialization() {
for rule in Rule::iter() {
assert!(
Rule::from_code(rule.code()).is_ok(),
Rule::from_code(rule.noqa_code()).is_ok(),
"{rule:?} could not be round-trip serialized."
);
}
@ -904,7 +904,7 @@ mod tests {
#[test]
fn test_linter_parse_code() {
for rule in Rule::iter() {
let code = rule.code();
let code = rule.noqa_code();
let (linter, rest) =
Linter::parse_code(code).unwrap_or_else(|| panic!("couldn't parse {code:?}"));
assert_eq!(code, format!("{}{rest}", linter.common_prefix()));

View file

@ -15,7 +15,7 @@ mod tests {
#[test_case(Rule::CommentedOutCode, Path::new("ERA001.py"); "ERA001")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("eradicate").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -23,7 +23,7 @@ mod tests {
#[test_case(Rule::SysVersionCmpStr10, Path::new("YTT302.py"); "YTT302")]
#[test_case(Rule::SysVersionSlice1Referenced, Path::new("YTT303.py"); "YTT303")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_2020").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -35,7 +35,7 @@ mod tests {
#[test_case(Rule::TryExceptPass, Path::new("S110.py"); "S110")]
#[test_case(Rule::TryExceptContinue, Path::new("S112.py"); "S112")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_bandit").join(path).as_path(),
&Settings::for_rule(rule_code),

View file

@ -14,7 +14,7 @@ mod tests {
#[test_case(Rule::BlindExcept, Path::new("BLE.py"); "BLE001")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_blind_except").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -16,7 +16,7 @@ mod tests {
#[test_case(Rule::BooleanDefaultValueInFunctionDefinition, Path::new("FBT.py"); "FBT002")]
#[test_case(Rule::BooleanPositionalValueInFunctionCall, Path::new("FBT.py"); "FBT003")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_boolean_trap").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -43,7 +43,7 @@ mod tests {
#[test_case(Rule::RaiseWithoutFromInsideExcept, Path::new("B904.py"); "B904")]
#[test_case(Rule::ZipWithoutExplicitStrict, Path::new("B905.py"); "B905")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_bugbear").join(path).as_path(),
&Settings::for_rule(rule_code),

View file

@ -19,7 +19,7 @@ mod tests {
#[test_case(Rule::BuiltinArgumentShadowing, Path::new("A002.py"); "A002")]
#[test_case(Rule::BuiltinAttributeShadowing, Path::new("A003.py"); "A003")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_builtins").join(path).as_path(),
&Settings::for_rule(rule_code),
@ -34,7 +34,7 @@ mod tests {
fn builtins_ignorelist(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!(
"{}_{}_builtins_ignorelist",
rule_code.code(),
rule_code.noqa_code(),
path.to_string_lossy()
);

View file

@ -31,7 +31,7 @@ mod tests {
#[test_case(Rule::UnnecessaryMap, Path::new("C417.py"); "C417")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_comprehensions").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -22,7 +22,7 @@ mod tests {
#[test_case(Rule::CallDateToday, Path::new("DTZ011.py"); "DTZ011")]
#[test_case(Rule::CallDateFromtimestamp, Path::new("DTZ012.py"); "DTZ012")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_datetimez").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -15,7 +15,7 @@ mod tests {
#[test_case(Rule::Debugger, Path::new("T100.py"); "T100")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_debugger").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -16,7 +16,7 @@ mod tests {
#[test_case(Rule::ModelWithoutDunderStr, Path::new("DJ008.py"); "DJ008")]
#[test_case(Rule::NonLeadingReceiverDecorator, Path::new("DJ013.py"); "DJ013")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_django").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -17,7 +17,7 @@ mod tests {
#[test_case(Rule::MultiLineImplicitStringConcatenation, Path::new("ISC.py"); "ISC002")]
#[test_case(Rule::ExplicitStringConcatenation, Path::new("ISC.py"); "ISC003")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_implicit_str_concat").join(path).as_path(),
&settings::Settings::for_rule(rule_code),
@ -30,7 +30,11 @@ mod tests {
#[test_case(Rule::MultiLineImplicitStringConcatenation, Path::new("ISC.py"); "ISC002")]
#[test_case(Rule::ExplicitStringConcatenation, Path::new("ISC.py"); "ISC003")]
fn multiline(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("multiline_{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!(
"multiline_{}_{}",
rule_code.noqa_code(),
path.to_string_lossy()
);
let diagnostics = test_path(
Path::new("flake8_implicit_str_concat").join(path).as_path(),
&settings::Settings {

View file

@ -20,7 +20,7 @@ mod tests {
#[test_case(Rule::PreferListBuiltin, Path::new("PIE807.py"); "PIE807")]
#[test_case(Rule::PreferUniqueEnums, Path::new("PIE796.py"); "PIE796")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_pie").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -15,7 +15,7 @@ mod tests {
#[test_case(Rule::PrintFound, Path::new("T201.py"); "T201")]
#[test_case(Rule::PPrintFound, Path::new("T203.py"); "T203")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_print").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -19,7 +19,7 @@ mod tests {
#[test_case(Rule::UnrecognizedPlatformName, Path::new("PYI008.pyi"))]
#[test_case(Rule::UnrecognizedPlatformName, Path::new("PYI008.py"))]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_pyi").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -25,7 +25,7 @@ mod tests {
#[test_case(Rule::SuperfluousElseContinue, Path::new("RET507.py"); "RET507")]
#[test_case(Rule::SuperfluousElseBreak, Path::new("RET508.py"); "RET508")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_return").join(path).as_path(),
&Settings::for_rule(rule_code),

View file

@ -39,7 +39,7 @@ mod tests {
#[test_case(Rule::DictGetWithDefault, Path::new("SIM401.py"); "SIM401")]
#[test_case(Rule::IfWithSameArms, Path::new("SIM114.py"); "SIM114")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_simplify").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -21,7 +21,7 @@ mod tests {
#[test_case(Rule::UnusedStaticMethodArgument, Path::new("ARG.py"); "ARG004")]
#[test_case(Rule::UnusedLambdaArgument, Path::new("ARG.py"); "ARG005")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_unused_arguments").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -56,7 +56,7 @@ mod tests {
#[test_case(Rule::PathlibPyPath, Path::new("py_path_1.py"); "PTH024_1")]
#[test_case(Rule::PathlibPyPath, Path::new("py_path_2.py"); "PTH024_2")]
fn rules_pypath(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_use_pathlib").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -251,7 +251,7 @@ mod tests {
#[test_case(Rule::UseOfInplaceArgument, Path::new("PD002.py"); "PD002")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("pandas_vet").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -31,7 +31,7 @@ mod tests {
#[test_case(Rule::CamelcaseImportedAsAcronym, Path::new("N817.py"); "N817")]
#[test_case(Rule::ErrorSuffixOnExceptionName, Path::new("N818.py"); "N818")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("pep8_naming").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -44,7 +44,7 @@ mod tests {
#[test_case(Rule::TypeComparison, Path::new("E721.py"))]
#[test_case(Rule::UselessSemicolon, Path::new("E70.py"))]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("pycodestyle").join(path).as_path(),
&settings::Settings::for_rule(rule_code),
@ -77,7 +77,7 @@ mod tests {
#[test_case(Rule::WhitespaceBeforeCloseBracket, Path::new("E20.py"))]
#[test_case(Rule::WhitespaceBeforePunctuation, Path::new("E20.py"))]
fn logical(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("pycodestyle").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -68,7 +68,7 @@ mod tests {
#[test_case(Rule::EscapeSequenceInDocstring, Path::new("D.py"); "D301")]
#[test_case(Rule::TripleSingleQuotes, Path::new("D.py"); "D300")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("pydocstyle").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -111,7 +111,7 @@ mod tests {
#[test_case(Rule::UnusedAnnotation, Path::new("F842.py"); "F842")]
#[test_case(Rule::RaiseNotImplemented, Path::new("F901.py"); "F901")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("pyflakes").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -19,7 +19,7 @@ mod tests {
#[test_case(Rule::BlanketTypeIgnore, Path::new("PGH003_0.py"); "PGH003_0")]
#[test_case(Rule::BlanketNOQA, Path::new("PGH004_0.py"); "PGH004_0")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("pygrep-hooks").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -46,7 +46,7 @@ mod tests {
#[test_case(Rule::BadStrStripCall, Path::new("bad_str_strip_call.py"); "PLE01310")]
#[test_case(Rule::YieldInInit, Path::new("yield_in_init.py"); "PLE0100")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("pylint").join(path).as_path(),
&Settings::for_rules(vec![rule_code]),

View file

@ -19,7 +19,7 @@ mod tests {
#[test_case(Rule::KeywordArgumentBeforeStarArgument, Path::new("RUF004.py"); "RUF004")]
#[test_case(Rule::UnpackInsteadOfConcatenatingToCollectionLiteral, Path::new("RUF005.py"); "RUF005")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("ruff").join(path).as_path(),
&settings::Settings::for_rule(rule_code),

View file

@ -22,17 +22,17 @@ struct Explanation<'a> {
/// Explain a `Rule` to the user.
pub fn rule(rule: &Rule, format: HelpFormat) -> Result<()> {
let (linter, _) = Linter::parse_code(rule.code()).unwrap();
let (linter, _) = Linter::parse_code(rule.noqa_code()).unwrap();
let mut stdout = BufWriter::new(io::stdout().lock());
let mut output = String::new();
match format {
HelpFormat::Text | HelpFormat::Pretty => {
output.push_str(&format!("# {} ({})", rule.as_ref(), rule.code()));
output.push_str(&format!("# {} ({})", rule.as_ref(), rule.noqa_code()));
output.push('\n');
output.push('\n');
let (linter, _) = Linter::parse_code(rule.code()).unwrap();
let (linter, _) = Linter::parse_code(rule.noqa_code()).unwrap();
output.push_str(&format!("Derived from the **{}** linter.", linter.name()));
output.push('\n');
output.push('\n');
@ -58,7 +58,7 @@ pub fn rule(rule: &Rule, format: HelpFormat) -> Result<()> {
}
HelpFormat::Json => {
output.push_str(&serde_json::to_string_pretty(&Explanation {
code: rule.code(),
code: rule.noqa_code(),
linter: linter.name(),
summary: rule.message_formats()[0],
})?);

View file

@ -67,7 +67,7 @@ impl Serialize for SerializeRuleAsCode<'_> {
where
S: serde::Serializer,
{
serializer.serialize_str(self.0.code())
serializer.serialize_str(self.0.noqa_code())
}
}
@ -221,7 +221,7 @@ impl Printer {
message.kind.body()
));
let mut case = TestCase::new(
format!("org.ruff.{}", message.kind.rule().code()),
format!("org.ruff.{}", message.kind.rule().noqa_code()),
status,
);
let file_path = Path::new(filename);
@ -313,14 +313,14 @@ impl Printer {
":",
message.location.column(),
":",
message.kind.rule().code(),
message.kind.rule().noqa_code(),
message.kind.body(),
);
writeln!(
stdout,
"::error title=Ruff \
({}),file={},line={},col={},endLine={},endColumn={}::{}",
message.kind.rule().code(),
message.kind.rule().noqa_code(),
message.filename,
message.location.row(),
message.location.column(),
@ -341,9 +341,9 @@ impl Printer {
.iter()
.map(|message| {
json!({
"description": format!("({}) {}", message.kind.rule().code(), message.kind.body()),
"description": format!("({}) {}", message.kind.rule().noqa_code(), message.kind.body()),
"severity": "major",
"fingerprint": message.kind.rule().code(),
"fingerprint": message.kind.rule().noqa_code(),
"location": {
"path": message.filename,
"lines": {
@ -366,7 +366,7 @@ impl Printer {
"{}:{}: [{}] {}",
relativize_path(Path::new(&message.filename)),
message.location.row(),
message.kind.rule().code(),
message.kind.rule().noqa_code(),
message.kind.body(),
);
writeln!(stdout, "{label}")?;
@ -394,7 +394,7 @@ impl Printer {
let statistics = violations
.iter()
.map(|rule| ExpandedStatistics {
code: rule.code(),
code: rule.noqa_code(),
count: diagnostics
.messages
.iter()
@ -538,7 +538,7 @@ impl Display for CodeAndBody<'_> {
write!(
f,
"{code} {autofix}{body}",
code = self.0.kind.rule().code().red().bold(),
code = self.0.kind.rule().noqa_code().red().bold(),
autofix = format_args!("[{}] ", "*".cyan()),
body = self.0.kind.body(),
)
@ -546,7 +546,7 @@ impl Display for CodeAndBody<'_> {
write!(
f,
"{code} {body}",
code = self.0.kind.rule().code().red().bold(),
code = self.0.kind.rule().noqa_code().red().bold(),
body = self.0.kind.body(),
)
}
@ -601,7 +601,7 @@ fn print_message<T: Write>(
source: &source.contents,
line_start: message.location.row(),
annotations: vec![SourceAnnotation {
label: message.kind.rule().code(),
label: message.kind.rule().noqa_code(),
annotation_type: AnnotationType::Error,
range: source.range,
}],
@ -656,7 +656,7 @@ fn print_fixed<T: Write>(stdout: &mut T, fixed: &FxHashMap<String, FixTable>) ->
writeln!(
stdout,
" {count:>num_digits$} × {} ({})",
rule.code().red().bold(),
rule.noqa_code().red().bold(),
rule.as_ref(),
)?;
}
@ -706,7 +706,7 @@ fn print_grouped_message<T: Write>(
source: &source.contents,
line_start: message.location.row(),
annotations: vec![SourceAnnotation {
label: message.kind.rule().code(),
label: message.kind.rule().noqa_code(),
annotation_type: AnnotationType::Error,
range: source.range,
}],

View file

@ -21,11 +21,11 @@ pub fn main(args: &Args) -> Result<()> {
for rule in Rule::iter() {
if let Some(explanation) = rule.explanation() {
let mut output = String::new();
output.push_str(&format!("# {} ({})", rule.as_ref(), rule.code()));
output.push_str(&format!("# {} ({})", rule.as_ref(), rule.noqa_code()));
output.push('\n');
output.push('\n');
let (linter, _) = Linter::parse_code(rule.code()).unwrap();
let (linter, _) = Linter::parse_code(rule.noqa_code()).unwrap();
output.push_str(&format!("Derived from the **{}** linter.", linter.name()));
output.push('\n');
output.push('\n');

View file

@ -39,7 +39,7 @@ fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>)
#[allow(clippy::or_fun_call)]
table_out.push_str(&format!(
"| {} | {} | {} | {} |",
rule.code(),
rule.noqa_code(),
rule.explanation()
.is_some()
.then_some(format_args!("[{rule_name}]({URL_PREFIX}/{rule_name}/)",))

View file

@ -106,7 +106,7 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream {
match self { #rule_autofixable_match_arms }
}
pub fn code(&self) -> &'static str {
pub fn noqa_code(&self) -> &'static str {
match self { #rule_code_match_arms }
}