From d451c7a506090a1d4fd1fffb44fbd41185186da1 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Mon, 30 Jan 2023 06:30:36 +0100 Subject: [PATCH] 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. --- crates/ruff/src/checkers/noqa.rs | 10 +++---- crates/ruff/src/lib_wasm.rs | 2 +- crates/ruff/src/noqa.rs | 6 ++--- crates/ruff/src/registry.rs | 4 +-- crates/ruff/src/rules/eradicate/mod.rs | 2 +- crates/ruff/src/rules/flake8_2020/mod.rs | 2 +- crates/ruff/src/rules/flake8_bandit/mod.rs | 2 +- .../ruff/src/rules/flake8_blind_except/mod.rs | 2 +- .../ruff/src/rules/flake8_boolean_trap/mod.rs | 2 +- crates/ruff/src/rules/flake8_bugbear/mod.rs | 2 +- crates/ruff/src/rules/flake8_builtins/mod.rs | 4 +-- .../src/rules/flake8_comprehensions/mod.rs | 2 +- crates/ruff/src/rules/flake8_datetimez/mod.rs | 2 +- crates/ruff/src/rules/flake8_debugger/mod.rs | 2 +- crates/ruff/src/rules/flake8_django/mod.rs | 2 +- .../rules/flake8_implicit_str_concat/mod.rs | 8 ++++-- crates/ruff/src/rules/flake8_pie/mod.rs | 2 +- crates/ruff/src/rules/flake8_print/mod.rs | 2 +- crates/ruff/src/rules/flake8_pyi/mod.rs | 2 +- crates/ruff/src/rules/flake8_return/mod.rs | 2 +- crates/ruff/src/rules/flake8_simplify/mod.rs | 2 +- .../src/rules/flake8_unused_arguments/mod.rs | 2 +- .../ruff/src/rules/flake8_use_pathlib/mod.rs | 2 +- crates/ruff/src/rules/pandas_vet/mod.rs | 2 +- crates/ruff/src/rules/pep8_naming/mod.rs | 2 +- crates/ruff/src/rules/pycodestyle/mod.rs | 4 +-- crates/ruff/src/rules/pydocstyle/mod.rs | 2 +- crates/ruff/src/rules/pyflakes/mod.rs | 2 +- crates/ruff/src/rules/pygrep_hooks/mod.rs | 2 +- crates/ruff/src/rules/pylint/mod.rs | 2 +- crates/ruff/src/rules/ruff/mod.rs | 2 +- crates/ruff_cli/src/commands/rule.rs | 8 +++--- crates/ruff_cli/src/printer.rs | 26 +++++++++---------- crates/ruff_dev/src/generate_docs.rs | 4 +-- crates/ruff_dev/src/generate_rules_table.rs | 2 +- crates/ruff_macros/src/define_rule_mapping.rs | 2 +- 36 files changed, 66 insertions(+), 62 deletions(-) diff --git a/crates/ruff/src/checkers/noqa.rs b/crates/ruff/src/checkers/noqa.rs index 0ae9830f29..9224b81d9d 100644 --- a/crates/ruff/src/checkers/noqa.rs +++ b/crates/ruff/src/checkers/noqa.rs @@ -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; } diff --git a/crates/ruff/src/lib_wasm.rs b/crates/ruff/src/lib_wasm.rs index d503f945d2..c888bd7d85 100644 --- a/crates/ruff/src/lib_wasm.rs +++ b/crates/ruff/src/lib_wasm.rs @@ -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()) } } diff --git a/crates/ruff/src/noqa.rs b/crates/ruff/src/noqa.rs index cdc524be7b..082bb81fb9 100644 --- a/crates/ruff/src/noqa.rs +++ b/crates/ruff/src/noqa.rs @@ -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(); diff --git a/crates/ruff/src/registry.rs b/crates/ruff/src/registry.rs index 28fcd9f890..1214a6a924 100644 --- a/crates/ruff/src/registry.rs +++ b/crates/ruff/src/registry.rs @@ -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())); diff --git a/crates/ruff/src/rules/eradicate/mod.rs b/crates/ruff/src/rules/eradicate/mod.rs index e3d9724778..3552d642d2 100644 --- a/crates/ruff/src/rules/eradicate/mod.rs +++ b/crates/ruff/src/rules/eradicate/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/flake8_2020/mod.rs b/crates/ruff/src/rules/flake8_2020/mod.rs index f3c03d0d4d..45cbf91943 100644 --- a/crates/ruff/src/rules/flake8_2020/mod.rs +++ b/crates/ruff/src/rules/flake8_2020/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/flake8_bandit/mod.rs b/crates/ruff/src/rules/flake8_bandit/mod.rs index 0026ee9118..26d5f94744 100644 --- a/crates/ruff/src/rules/flake8_bandit/mod.rs +++ b/crates/ruff/src/rules/flake8_bandit/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/flake8_blind_except/mod.rs b/crates/ruff/src/rules/flake8_blind_except/mod.rs index 438c5e9c9c..28ddf48d12 100644 --- a/crates/ruff/src/rules/flake8_blind_except/mod.rs +++ b/crates/ruff/src/rules/flake8_blind_except/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/flake8_boolean_trap/mod.rs b/crates/ruff/src/rules/flake8_boolean_trap/mod.rs index 7d1187cb77..375e9b60e8 100644 --- a/crates/ruff/src/rules/flake8_boolean_trap/mod.rs +++ b/crates/ruff/src/rules/flake8_boolean_trap/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/flake8_bugbear/mod.rs b/crates/ruff/src/rules/flake8_bugbear/mod.rs index 512fa97f49..6b03217507 100644 --- a/crates/ruff/src/rules/flake8_bugbear/mod.rs +++ b/crates/ruff/src/rules/flake8_bugbear/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/flake8_builtins/mod.rs b/crates/ruff/src/rules/flake8_builtins/mod.rs index 501cde0744..5bb20d8a62 100644 --- a/crates/ruff/src/rules/flake8_builtins/mod.rs +++ b/crates/ruff/src/rules/flake8_builtins/mod.rs @@ -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() ); diff --git a/crates/ruff/src/rules/flake8_comprehensions/mod.rs b/crates/ruff/src/rules/flake8_comprehensions/mod.rs index 4088f52a2c..3765a24c8b 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/mod.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/flake8_datetimez/mod.rs b/crates/ruff/src/rules/flake8_datetimez/mod.rs index ba49fe5fb4..96d7ca268a 100644 --- a/crates/ruff/src/rules/flake8_datetimez/mod.rs +++ b/crates/ruff/src/rules/flake8_datetimez/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/flake8_debugger/mod.rs b/crates/ruff/src/rules/flake8_debugger/mod.rs index 5318073b06..16d67f338c 100644 --- a/crates/ruff/src/rules/flake8_debugger/mod.rs +++ b/crates/ruff/src/rules/flake8_debugger/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/flake8_django/mod.rs b/crates/ruff/src/rules/flake8_django/mod.rs index a5138595ba..0fce19b4ab 100644 --- a/crates/ruff/src/rules/flake8_django/mod.rs +++ b/crates/ruff/src/rules/flake8_django/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/flake8_implicit_str_concat/mod.rs b/crates/ruff/src/rules/flake8_implicit_str_concat/mod.rs index 98116d8d70..644b94e7c2 100644 --- a/crates/ruff/src/rules/flake8_implicit_str_concat/mod.rs +++ b/crates/ruff/src/rules/flake8_implicit_str_concat/mod.rs @@ -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 { diff --git a/crates/ruff/src/rules/flake8_pie/mod.rs b/crates/ruff/src/rules/flake8_pie/mod.rs index c804e48bd8..501c0d4774 100644 --- a/crates/ruff/src/rules/flake8_pie/mod.rs +++ b/crates/ruff/src/rules/flake8_pie/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/flake8_print/mod.rs b/crates/ruff/src/rules/flake8_print/mod.rs index 1238f7d5a5..e2094d7189 100644 --- a/crates/ruff/src/rules/flake8_print/mod.rs +++ b/crates/ruff/src/rules/flake8_print/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/flake8_pyi/mod.rs b/crates/ruff/src/rules/flake8_pyi/mod.rs index 3608f8d16a..6c4edf4f16 100644 --- a/crates/ruff/src/rules/flake8_pyi/mod.rs +++ b/crates/ruff/src/rules/flake8_pyi/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/flake8_return/mod.rs b/crates/ruff/src/rules/flake8_return/mod.rs index 1d0d26ed18..2160c281df 100644 --- a/crates/ruff/src/rules/flake8_return/mod.rs +++ b/crates/ruff/src/rules/flake8_return/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/flake8_simplify/mod.rs b/crates/ruff/src/rules/flake8_simplify/mod.rs index 3f7c3db9fb..f9bda94f1b 100644 --- a/crates/ruff/src/rules/flake8_simplify/mod.rs +++ b/crates/ruff/src/rules/flake8_simplify/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/flake8_unused_arguments/mod.rs b/crates/ruff/src/rules/flake8_unused_arguments/mod.rs index ba63d6efb3..e85e811d3f 100644 --- a/crates/ruff/src/rules/flake8_unused_arguments/mod.rs +++ b/crates/ruff/src/rules/flake8_unused_arguments/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/flake8_use_pathlib/mod.rs b/crates/ruff/src/rules/flake8_use_pathlib/mod.rs index 90f7bc395a..5aac0f9021 100644 --- a/crates/ruff/src/rules/flake8_use_pathlib/mod.rs +++ b/crates/ruff/src/rules/flake8_use_pathlib/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/pandas_vet/mod.rs b/crates/ruff/src/rules/pandas_vet/mod.rs index 69dc1fe4c3..5cf21e46e2 100644 --- a/crates/ruff/src/rules/pandas_vet/mod.rs +++ b/crates/ruff/src/rules/pandas_vet/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/pep8_naming/mod.rs b/crates/ruff/src/rules/pep8_naming/mod.rs index 74143ab716..f099bb0bd0 100644 --- a/crates/ruff/src/rules/pep8_naming/mod.rs +++ b/crates/ruff/src/rules/pep8_naming/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/pycodestyle/mod.rs b/crates/ruff/src/rules/pycodestyle/mod.rs index 29ff7b1f49..4c58b68eb7 100644 --- a/crates/ruff/src/rules/pycodestyle/mod.rs +++ b/crates/ruff/src/rules/pycodestyle/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/pydocstyle/mod.rs b/crates/ruff/src/rules/pydocstyle/mod.rs index ac26e031f0..a363c6f480 100644 --- a/crates/ruff/src/rules/pydocstyle/mod.rs +++ b/crates/ruff/src/rules/pydocstyle/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/pyflakes/mod.rs b/crates/ruff/src/rules/pyflakes/mod.rs index 2b1b2b911a..f729bb4856 100644 --- a/crates/ruff/src/rules/pyflakes/mod.rs +++ b/crates/ruff/src/rules/pyflakes/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/pygrep_hooks/mod.rs b/crates/ruff/src/rules/pygrep_hooks/mod.rs index 7857da2331..381c3199f5 100644 --- a/crates/ruff/src/rules/pygrep_hooks/mod.rs +++ b/crates/ruff/src/rules/pygrep_hooks/mod.rs @@ -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), diff --git a/crates/ruff/src/rules/pylint/mod.rs b/crates/ruff/src/rules/pylint/mod.rs index 7655dca7c9..1970064105 100644 --- a/crates/ruff/src/rules/pylint/mod.rs +++ b/crates/ruff/src/rules/pylint/mod.rs @@ -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]), diff --git a/crates/ruff/src/rules/ruff/mod.rs b/crates/ruff/src/rules/ruff/mod.rs index d654d07454..d0661c8d6a 100644 --- a/crates/ruff/src/rules/ruff/mod.rs +++ b/crates/ruff/src/rules/ruff/mod.rs @@ -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), diff --git a/crates/ruff_cli/src/commands/rule.rs b/crates/ruff_cli/src/commands/rule.rs index 5080f49f3f..88d1158e9e 100644 --- a/crates/ruff_cli/src/commands/rule.rs +++ b/crates/ruff_cli/src/commands/rule.rs @@ -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], })?); diff --git a/crates/ruff_cli/src/printer.rs b/crates/ruff_cli/src/printer.rs index 1434ac841a..896c96e320 100644 --- a/crates/ruff_cli/src/printer.rs +++ b/crates/ruff_cli/src/printer.rs @@ -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( 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(stdout: &mut T, fixed: &FxHashMap) -> 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( 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, }], diff --git a/crates/ruff_dev/src/generate_docs.rs b/crates/ruff_dev/src/generate_docs.rs index 58b803a41d..8d71a6d229 100644 --- a/crates/ruff_dev/src/generate_docs.rs +++ b/crates/ruff_dev/src/generate_docs.rs @@ -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'); diff --git a/crates/ruff_dev/src/generate_rules_table.rs b/crates/ruff_dev/src/generate_rules_table.rs index 18afcef8b2..50c5aedff4 100644 --- a/crates/ruff_dev/src/generate_rules_table.rs +++ b/crates/ruff_dev/src/generate_rules_table.rs @@ -39,7 +39,7 @@ fn generate_table(table_out: &mut String, rules: impl IntoIterator) #[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}/)",)) diff --git a/crates/ruff_macros/src/define_rule_mapping.rs b/crates/ruff_macros/src/define_rule_mapping.rs index 2c7f0efa33..e341f320b7 100644 --- a/crates/ruff_macros/src/define_rule_mapping.rs +++ b/crates/ruff_macros/src/define_rule_mapping.rs @@ -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 } }