From ac6ab7692b75ebd430e920d60f44cd593aa08abd Mon Sep 17 00:00:00 2001 From: InSync Date: Mon, 4 Nov 2024 22:51:55 +0000 Subject: [PATCH 01/29] [`ruff`] Unformatted special comments (`RUF102`) --- .../resources/test/fixtures/ruff/RUF102.py | 106 +++++++ crates/ruff_linter/src/checkers/tokens.rs | 4 + crates/ruff_linter/src/codes.rs | 1 + crates/ruff_linter/src/noqa.rs | 2 +- crates/ruff_linter/src/registry.rs | 1 + crates/ruff_linter/src/rules/ruff/mod.rs | 3 +- .../ruff_linter/src/rules/ruff/rules/mod.rs | 2 + .../ruff/rules/unformatted_special_comment.rs | 259 ++++++++++++++++++ ..._rules__ruff__tests__RUF102_RUF102.py.snap | 4 + ruff.schema.json | 1 + 10 files changed, 381 insertions(+), 2 deletions(-) create mode 100644 crates/ruff_linter/resources/test/fixtures/ruff/RUF102.py create mode 100644 crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs create mode 100644 crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF102_RUF102.py.snap diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF102.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF102.py new file mode 100644 index 00000000000000..3b4848e9df98db --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF102.py @@ -0,0 +1,106 @@ +### No leading space + +#noqa +#noqa: PTH123 +#ruff: noqa +#ruff: noqa: PTH123 +#flake8: noqa +#flake8: noqa: PTH123 +#ruff: isort: skip_file + + +### Too many leading spaces + +# noqa +# noqa: PTH123 +# ruff: noqa +# ruff: noqa: PTH123 +# flake8: noqa +# flake8: noqa: PTH123 +# ruff: isort: skip_file + + +### Space before colon + +# noqa : PTH123 +# ruff : noqa +# ruff : noqa: PTH123 +# ruff: noqa : PTH123 +# ruff : noqa : PTH123 +# flake8 : noqa +# flake8 : noqa: PTH123 +# flake8: noqa : PTH123 +# flake8 : noqa : PTH123 +# ruff : isort: skip_file +# ruff: isort : skip_file +# ruff : isort : skip_file + + +### No space after colon + +# noqa:PTH123 +# ruff:noqa +# ruff:noqa: PTH123 +# ruff: noqa:PTH123 +# ruff:noqa:PTH123 +# flake8:noqa +# flake8:noqa: PTH123 +# flake8: noqa:PTH123 +# flake8:noqa:PTH123 +# ruff:isort: skip_file +# ruff: isort:skip_file +# ruff:isort:skip_file + + +### Too many spaces after colon + +# noqa: PTH123 +# ruff: noqa +# ruff: noqa: PTH123 +# ruff: noqa: PTH123 +# ruff: noqa: PTH123 +# flake8: noqa +# flake8: noqa: PTH123 +# flake8: noqa: PTH123 +# flake8: noqa: PTH123 +# ruff: isort: skip_file +# ruff: isort: skip_file +# ruff: isort: skip_file + + +### Rule list separators + +# noqa: PTH123,B012 +# noqa: PTH123 ,B012 +# noqa: PTH123 , B012 +# noqa: PTH123 B012 +# noqa: PTH123 B012 +# noqa: PTH123 B012 +# noqa: PTH123,,B012 +# noqa: PTH123 ,, B012 +# noqa: PTH123 , , B012 + + +### Common + +#fmt : off +# fmt:on +# fmt :skip + +#isort: on +# isort: off +# isort:skip +# isort: skip_file +# isort :dont-add-imports + +# mypy :strict +# mypy: disallow-subclassing-any + +# nopycln : import + +#pyright:basic +#pyright:strict +# pyright: ignore[reportMissingModuleSource] + +#type:ignore +#type :int diff --git a/crates/ruff_linter/src/checkers/tokens.rs b/crates/ruff_linter/src/checkers/tokens.rs index 7be23f8bfd0352..ac6b63858e3755 100644 --- a/crates/ruff_linter/src/checkers/tokens.rs +++ b/crates/ruff_linter/src/checkers/tokens.rs @@ -191,6 +191,10 @@ pub(crate) fn check_tokens( pycodestyle::rules::too_many_newlines_at_end_of_file(&mut diagnostics, tokens); } + if settings.rules.enabled(Rule::UnformattedSpecialComment) { + ruff::rules::unformatted_special_comment(&mut diagnostics, locator, comment_ranges); + } + diagnostics.retain(|diagnostic| settings.rules.enabled(diagnostic.kind.rule())); diagnostics diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index be27d11fc6b1d9..8cfa0897ac916a 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -967,6 +967,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Ruff, "034") => (RuleGroup::Preview, rules::ruff::rules::UselessIfElse), (Ruff, "100") => (RuleGroup::Stable, rules::ruff::rules::UnusedNOQA), (Ruff, "101") => (RuleGroup::Stable, rules::ruff::rules::RedirectedNOQA), + (Ruff, "102") => (RuleGroup::Preview, rules::ruff::rules::UnformattedSpecialComment), (Ruff, "200") => (RuleGroup::Stable, rules::ruff::rules::InvalidPyprojectToml), #[cfg(any(feature = "test-rules", test))] diff --git a/crates/ruff_linter/src/noqa.rs b/crates/ruff_linter/src/noqa.rs index f734448c795e21..1b9020874d0034 100644 --- a/crates/ruff_linter/src/noqa.rs +++ b/crates/ruff_linter/src/noqa.rs @@ -432,7 +432,7 @@ pub(crate) enum ParsedFileExemption<'a> { impl<'a> ParsedFileExemption<'a> { /// Return a [`ParsedFileExemption`] for a given comment line. - fn try_extract(line: &'a str) -> Result, ParseError> { + pub(crate) fn try_extract(line: &'a str) -> Result, ParseError> { let line = Self::lex_whitespace(line); let Some(line) = Self::lex_char(line, '#') else { return Ok(None); diff --git a/crates/ruff_linter/src/registry.rs b/crates/ruff_linter/src/registry.rs index 1ee0cc5102addd..664d2d493d36de 100644 --- a/crates/ruff_linter/src/registry.rs +++ b/crates/ruff_linter/src/registry.rs @@ -301,6 +301,7 @@ impl Rule { | Rule::TrailingCommaOnBareTuple | Rule::TypeCommentInStub | Rule::UselessSemicolon + | Rule::UnformattedSpecialComment | Rule::UTF8EncodingDeclaration => LintSource::Tokens, Rule::IOError => LintSource::Io, Rule::UnsortedImports | Rule::MissingRequiredImport => LintSource::Imports, diff --git a/crates/ruff_linter/src/rules/ruff/mod.rs b/crates/ruff_linter/src/rules/ruff/mod.rs index 84b7fd0d8ff7d9..ed3a836fac9aa4 100644 --- a/crates/ruff_linter/src/rules/ruff/mod.rs +++ b/crates/ruff_linter/src/rules/ruff/mod.rs @@ -58,9 +58,10 @@ mod tests { #[test_case(Rule::AssertWithPrintMessage, Path::new("RUF030.py"))] #[test_case(Rule::IncorrectlyParenthesizedTupleInSubscript, Path::new("RUF031.py"))] #[test_case(Rule::DecimalFromFloatLiteral, Path::new("RUF032.py"))] + #[test_case(Rule::PostInitDefault, Path::new("RUF033.py"))] #[test_case(Rule::UselessIfElse, Path::new("RUF034.py"))] #[test_case(Rule::RedirectedNOQA, Path::new("RUF101.py"))] - #[test_case(Rule::PostInitDefault, Path::new("RUF033.py"))] + #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF102.py"))] fn rules(rule_code: Rule, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( diff --git a/crates/ruff_linter/src/rules/ruff/rules/mod.rs b/crates/ruff_linter/src/rules/ruff/rules/mod.rs index d386c3c7c6d8cb..636119d0799460 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/mod.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/mod.rs @@ -26,6 +26,7 @@ pub(crate) use sort_dunder_slots::*; pub(crate) use static_key_dict_comprehension::*; #[cfg(any(feature = "test-rules", test))] pub(crate) use test_rules::*; +pub(crate) use unformatted_special_comment::*; pub(crate) use unnecessary_iterable_allocation_for_first_element::*; pub(crate) use unnecessary_key_check::*; pub(crate) use unused_async::*; @@ -65,6 +66,7 @@ mod static_key_dict_comprehension; mod suppression_comment_visitor; #[cfg(any(feature = "test-rules", test))] pub(crate) mod test_rules; +mod unformatted_special_comment; mod unnecessary_iterable_allocation_for_first_element; mod unnecessary_key_check; mod unused_async; diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs new file mode 100644 index 00000000000000..ccf74783bcc4c1 --- /dev/null +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -0,0 +1,259 @@ +use crate::Locator; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; +use ruff_macros::{derive_message_formats, violation}; +use ruff_python_trivia::CommentRanges; +use ruff_text_size::TextRange; + +use crate::noqa::{Directive, ParseError, ParsedFileExemption}; + +const KNOWN_COMMON_HINT: [&str; 6] = ["fmt", "isort", "mypy", "nopycln", "pyright", "type"]; + +#[derive(Debug, Eq, PartialEq)] +enum SpecialComment { + /// `# noqa`, `# noqa: A123, B456` + Noqa(Option>), + /// `# ruff: noqa`, `# ruff: noqa: A123, B456`, + /// `# flake8: noqa`, `# flake8: noqa: A123, B456` + FileLevelNoqa { + hint: String, + codes: Option>, + }, + /// `# ruff: isort: skip_file` + RuffIsort(String), + /// `# mypy: ignore-errors`, `# type: ignore`/`# type: int`, + /// `# pyright: strict`/`# pyright: ignore[reportFoo]`, + /// `# isort: skip_file`, `# nopycln: import`, + /// `# fmt: on`/`# fmt: off`/`fmt: skip`. + Common { hint: String, rest: String }, +} + +impl SpecialComment { + fn formatted(&self) -> String { + match self { + SpecialComment::Common { hint, rest } => format!("# {}: {}", hint.to_lowercase(), rest) + .trim_ascii_end() + .to_owned(), + SpecialComment::RuffIsort(rest) => { + format!("# ruff: isort: {rest}") + } + SpecialComment::Noqa(None) => { + format!("# noqa") + } + SpecialComment::Noqa(Some(codes)) => { + format!("# noqa: {}", codes.join(", ")) + } + SpecialComment::FileLevelNoqa { hint, codes: None } => { + format!("# {hint}: noqa") + } + SpecialComment::FileLevelNoqa { + hint, + codes: Some(codes), + } => { + format!("# {hint}: noqa: {}", codes.join(", ")) + } + } + } +} + +/// ## What it does +/// Checks special comments' formatting. +/// +/// ## Why is this bad? +/// +/// Special comments are often written in the following format +/// (hash, space, directive, colon, space, directive body): +/// +/// ```python +/// # name: body +/// ``` +/// +/// ## Example +/// +/// ```python +/// # ruff: noqa:A123 B456 +/// # fmt:off +/// #type:ignore +/// ``` +/// +/// Use instead: +/// +/// ```python +/// # ruff: noqa: A123, B456 +/// # fmt: off +/// # type: ignore +/// ``` +#[violation] +pub(crate) struct UnformattedSpecialComment(SpecialComment); + +impl AlwaysFixableViolation for UnformattedSpecialComment { + #[derive_message_formats] + fn message(&self) -> String { + "Unformatted special comment".to_string() + } + + fn fix_title(&self) -> String { + "Format comment".to_string() + } +} + +fn add_diagnostic_if_applicable( + diagnostics: &mut Vec, + comment: SpecialComment, + original_text: &str, + range: TextRange, +) { + let formatted_comment = comment.formatted(); + + if original_text == formatted_comment { + return; + } + + let edit = Edit::range_replacement(formatted_comment, range); + let fix = Fix::safe_edit(edit); + + let violation = UnformattedSpecialComment(comment); + let diagnostic = Diagnostic::new(violation, range).with_fix(fix); + + diagnostics.push(diagnostic); +} + +#[inline] +fn all_to_owned(codes: Vec<&str>) -> Vec { + codes + .iter() + .map(|code| code.to_string()) + .collect::>() +} + +#[inline] +fn remove_comment_start_and_leading_whitespace(text: &str) -> Option<&str> { + text.strip_prefix("#").map(|text| text.trim_ascii_start()) +} + +#[inline] +fn try_parse_file_level_noqa(text: &str) -> Result, ParseError> { + ParsedFileExemption::try_extract(text) +} + +#[inline] +fn file_level_noqa_special_comment( + hint: String, + file_level_noqa: ParsedFileExemption, +) -> SpecialComment { + let codes = match file_level_noqa { + ParsedFileExemption::All => None, + ParsedFileExemption::Codes(codes) => Some(all_to_owned(codes)), + }; + + SpecialComment::FileLevelNoqa { hint, codes } +} + +#[inline] +fn try_parse_noqa(text: &str) -> Result, ParseError> { + Directive::try_extract(text, 0.into()) +} + +#[inline] +fn noqa_special_comment(noqa: Directive) -> SpecialComment { + let codes = match noqa { + Directive::All(..) => None, + Directive::Codes(codes) => { + let as_vec = codes.iter().map(|code| code.as_str()).collect::>(); + + Some(all_to_owned(as_vec)) + } + }; + + SpecialComment::Noqa(codes) +} + +#[inline] +fn consume_hint(text: &str) -> Option<(&str, &str)> { + let hint_end = text.chars().take_while(char::is_ascii_alphanumeric).count(); + let hint = &text[..hint_end]; + + if hint.len() == 0 { + return None; + } + + let before_colon = text.strip_prefix(hint).unwrap().trim_ascii_start(); + + let Some(rest) = before_colon + .strip_prefix(':') + .map(|text| text.trim_ascii_start()) + else { + return None; + }; + + return Some((hint, rest)); +} + +fn try_parse_generic_hint_comment(comment_body: &str) -> Option { + let Some((hint, rest)) = consume_hint(comment_body) else { + return None; + }; + + match &hint.to_lowercase() { + hint if KNOWN_COMMON_HINT.contains(&hint.as_str()) => Some(SpecialComment::Common { + hint: hint.to_lowercase(), + rest: rest.to_owned(), + }), + hint if hint == "ruff" => { + let Some((second_hint, rest)) = consume_hint(rest) else { + return None; + }; + + if second_hint != "isort" { + return None; + } + + Some(SpecialComment::RuffIsort(rest.to_owned())) + } + _ => None, + } +} + +fn check_single_comment(diagnostics: &mut Vec, text: &str, range: TextRange) { + let Some(comment_body) = remove_comment_start_and_leading_whitespace(text) else { + return; + }; + + println!("Comment: {text:?}"); + + if let Ok(Some(file_level_noqa)) = try_parse_file_level_noqa(text) { + let hint = match comment_body.chars().into_iter().next() { + Some('f') => "flake8", + Some('r') => "ruff", + _ => panic!("Unexpected parsed file exemption hint"), + }; + + let comment = file_level_noqa_special_comment(hint.to_owned(), file_level_noqa); + add_diagnostic_if_applicable(diagnostics, comment, text, range); + return; + } + + if let Ok(Some(noqa)) = try_parse_noqa(text) { + let comment = noqa_special_comment(noqa); + add_diagnostic_if_applicable(diagnostics, comment, text, range); + return; + } + + let Some(comment) = try_parse_generic_hint_comment(comment_body) else { + return; + }; + + add_diagnostic_if_applicable(diagnostics, comment, text, range); +} + +/// RUF102 +pub(crate) fn unformatted_special_comment( + diagnostics: &mut Vec, + locator: &Locator, + comment_ranges: &CommentRanges, +) { + for range in comment_ranges { + let text = locator.slice(range); + + check_single_comment(diagnostics, text, range); + } +} diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF102_RUF102.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF102_RUF102.py.snap new file mode 100644 index 00000000000000..7f58cfd7246a31 --- /dev/null +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF102_RUF102.py.snap @@ -0,0 +1,4 @@ +--- +source: crates/ruff_linter/src/rules/ruff/mod.rs +--- + diff --git a/ruff.schema.json b/ruff.schema.json index b1e24b47760305..b2363d0428f959 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -3820,6 +3820,7 @@ "RUF10", "RUF100", "RUF101", + "RUF102", "RUF2", "RUF20", "RUF200", From 58c46ff524bdc41695dd80850e412f84190e6501 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Wed, 6 Nov 2024 02:20:31 +0000 Subject: [PATCH 02/29] Rename to `RUF104` --- .../resources/test/fixtures/ruff/{RUF102.py => RUF104.py} | 0 .../rules/fastapi/rules/fastapi_redundant_response_model.rs | 2 +- crates/ruff_linter/src/rules/ruff/mod.rs | 2 +- .../src/rules/ruff/rules/unformatted_special_comment.rs | 3 ++- ruff.schema.json | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) rename crates/ruff_linter/resources/test/fixtures/ruff/{RUF102.py => RUF104.py} (100%) diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF102.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py similarity index 100% rename from crates/ruff_linter/resources/test/fixtures/ruff/RUF102.py rename to crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py diff --git a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_redundant_response_model.rs b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_redundant_response_model.rs index 36f7fc1129a8fa..a18749d05b5dd7 100644 --- a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_redundant_response_model.rs +++ b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_redundant_response_model.rs @@ -73,7 +73,7 @@ impl AlwaysFixableViolation for FastApiRedundantResponseModel { } } -/// RUF102 +/// FAST001 pub(crate) fn fastapi_redundant_response_model( checker: &mut Checker, function_def: &StmtFunctionDef, diff --git a/crates/ruff_linter/src/rules/ruff/mod.rs b/crates/ruff_linter/src/rules/ruff/mod.rs index ed3a836fac9aa4..f0c6dfc353b428 100644 --- a/crates/ruff_linter/src/rules/ruff/mod.rs +++ b/crates/ruff_linter/src/rules/ruff/mod.rs @@ -61,7 +61,7 @@ mod tests { #[test_case(Rule::PostInitDefault, Path::new("RUF033.py"))] #[test_case(Rule::UselessIfElse, Path::new("RUF034.py"))] #[test_case(Rule::RedirectedNOQA, Path::new("RUF101.py"))] - #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF102.py"))] + #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104.py"))] fn rules(rule_code: Rule, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index ccf74783bcc4c1..418cd088cce624 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -218,6 +218,7 @@ fn check_single_comment(diagnostics: &mut Vec, text: &str, range: Te return; }; + // FIXME: Remove this once everything is done println!("Comment: {text:?}"); if let Ok(Some(file_level_noqa)) = try_parse_file_level_noqa(text) { @@ -245,7 +246,7 @@ fn check_single_comment(diagnostics: &mut Vec, text: &str, range: Te add_diagnostic_if_applicable(diagnostics, comment, text, range); } -/// RUF102 +/// RUF104 pub(crate) fn unformatted_special_comment( diagnostics: &mut Vec, locator: &Locator, diff --git a/ruff.schema.json b/ruff.schema.json index b2363d0428f959..e0dee716b97500 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -3820,7 +3820,7 @@ "RUF10", "RUF100", "RUF101", - "RUF102", + "RUF104", "RUF2", "RUF20", "RUF200", From d7db816937684232912047c20d3af14318a764a1 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Wed, 6 Nov 2024 02:37:06 +0000 Subject: [PATCH 03/29] Exempt doc comment from formatting checks --- scripts/check_docs_formatted.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/check_docs_formatted.py b/scripts/check_docs_formatted.py index c2627220562673..10215a45cde7fb 100755 --- a/scripts/check_docs_formatted.py +++ b/scripts/check_docs_formatted.py @@ -81,6 +81,7 @@ "under-indentation", "unexpected-indentation-comment", "unexpected-spaces-around-keyword-parameter-equals", + "unformatted-special-comment", "unicode-kind-prefix", "unnecessary-class-parentheses", "unnecessary-escaped-quote", From dc2e86619159420c596bb8c7d02d25ad90b25473 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Wed, 6 Nov 2024 04:38:27 +0000 Subject: [PATCH 04/29] Rewrite --- .../resources/test/fixtures/ruff/RUF104.py | 8 + .../ruff/rules/unformatted_special_comment.rs | 237 ++++++++++-------- 2 files changed, 136 insertions(+), 109 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py index 3b4848e9df98db..8ca6268a5bb98e 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py @@ -104,3 +104,11 @@ #type:ignore #type :int + + +### Mix'n'match + +#noqa: D101 undocumented-public-class + + # noqa :RUF001,RUF002 # type:ignore + diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index 418cd088cce624..238ed4f352a569 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -1,10 +1,13 @@ +use crate::noqa::{Directive, ParseError, ParsedFileExemption}; use crate::Locator; +use once_cell::sync::Lazy; +use regex::Regex; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_trivia::CommentRanges; use ruff_text_size::TextRange; -use crate::noqa::{Directive, ParseError, ParsedFileExemption}; +type EndIndex = usize; const KNOWN_COMMON_HINT: [&str; 6] = ["fmt", "isort", "mypy", "nopycln", "pyright", "type"]; @@ -59,7 +62,6 @@ impl SpecialComment { /// Checks special comments' formatting. /// /// ## Why is this bad? -/// /// Special comments are often written in the following format /// (hash, space, directive, colon, space, directive body): /// @@ -99,12 +101,12 @@ impl AlwaysFixableViolation for UnformattedSpecialComment { fn add_diagnostic_if_applicable( diagnostics: &mut Vec, comment: SpecialComment, - original_text: &str, + original_comment_text: &str, range: TextRange, ) { let formatted_comment = comment.formatted(); - if original_text == formatted_comment { + if original_comment_text == formatted_comment { return; } @@ -117,133 +119,144 @@ fn add_diagnostic_if_applicable( diagnostics.push(diagnostic); } -#[inline] -fn all_to_owned(codes: Vec<&str>) -> Vec { - codes - .iter() - .map(|code| code.to_string()) - .collect::>() -} - -#[inline] -fn remove_comment_start_and_leading_whitespace(text: &str) -> Option<&str> { - text.strip_prefix("#").map(|text| text.trim_ascii_start()) -} +fn parse_code_list(code_list: &str) -> Vec { + static PATTERN: Regex = Lazy::new(Regex::new(r"[A-Z]+[A-Za-z0-9]+")); -#[inline] -fn try_parse_file_level_noqa(text: &str) -> Result, ParseError> { - ParsedFileExemption::try_extract(text) + PATTERN + .find_iter(list) + .map(|code| code.as_str().to_owned()) + .collect() } -#[inline] -fn file_level_noqa_special_comment( - hint: String, - file_level_noqa: ParsedFileExemption, -) -> SpecialComment { - let codes = match file_level_noqa { - ParsedFileExemption::All => None, - ParsedFileExemption::Codes(codes) => Some(all_to_owned(codes)), +fn try_parse_file_level_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { + static PATTERN: Regex = Lazy::new( + Regex::new( + r"(?x) + ^ + \#\s* + (?flake8|ruff)\s*:\s* + (?i:noqa)\s* + (?: + :\s* + (? + [A-Z]+[A-Za-z0-9]+ + (?:[\s,]\s*[A-Z]+[A-Za-z0-9]+)* + )? + \s* + )? + $ + ", + ) + .unwrap(), + ); + + let Some(result) = PATTERN.captures(text) else { + return None; }; - SpecialComment::FileLevelNoqa { hint, codes } -} + let end_index = result.get(0).unwrap().end(); + let hint = result.name("hint").unwrap().as_str().to_owned(); + let codes = result + .name("code_list") + .map(|it| parse_code_list(it.as_str())); -#[inline] -fn try_parse_noqa(text: &str) -> Result, ParseError> { - Directive::try_extract(text, 0.into()) + Some((end_index, SpecialComment::FileLevelNoqa { hint, codes })) } -#[inline] -fn noqa_special_comment(noqa: Directive) -> SpecialComment { - let codes = match noqa { - Directive::All(..) => None, - Directive::Codes(codes) => { - let as_vec = codes.iter().map(|code| code.as_str()).collect::>(); - - Some(all_to_owned(as_vec)) - } - }; - - SpecialComment::Noqa(codes) -} - -#[inline] -fn consume_hint(text: &str) -> Option<(&str, &str)> { - let hint_end = text.chars().take_while(char::is_ascii_alphanumeric).count(); - let hint = &text[..hint_end]; - - if hint.len() == 0 { - return None; - } - - let before_colon = text.strip_prefix(hint).unwrap().trim_ascii_start(); - - let Some(rest) = before_colon - .strip_prefix(':') - .map(|text| text.trim_ascii_start()) - else { +fn try_parse_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { + static PATTERN: Regex = Lazy::new( + Regex::new( + r"(?x) + ^ + \#\s* + (?i:noqa) + (?: + :\s* + (? + [A-Z]+[A-Za-z0-9]+ + (?:[\h,]+[A-Z]+[A-Za-z0-9]+)* + )? + )? + $ + ", + ) + .unwrap(), + ); + + let Some(result) = PATTERN.captures(text) else { return None; }; - return Some((hint, rest)); + let end_index = result.get(0).unwrap().end(); + let codes = result + .name("code_list") + .map(|it| parse_code_list(it.as_str())); + + Some((end_index, SpecialComment::Noqa(codes))) } -fn try_parse_generic_hint_comment(comment_body: &str) -> Option { - let Some((hint, rest)) = consume_hint(comment_body) else { +fn try_parse_ruff_isort(text: &str) -> Option<(EndIndex, SpecialComment)> { + static PATTERN: Regex = Lazy::new( + Regex::new( + r"(?x) + ^ + \#\s* + ruff\s*:\s* + isort\s*:\s* + (?.+) + ", + ) + .unwrap(), + ); + + let Some(result) = PATTERN.captures(text) else { return None; }; - match &hint.to_lowercase() { - hint if KNOWN_COMMON_HINT.contains(&hint.as_str()) => Some(SpecialComment::Common { - hint: hint.to_lowercase(), - rest: rest.to_owned(), - }), - hint if hint == "ruff" => { - let Some((second_hint, rest)) = consume_hint(rest) else { - return None; - }; - - if second_hint != "isort" { - return None; - } + let end_index = result.get(0).unwrap().end(); + let rest = result.name("rest").unwrap().as_str().to_owned(); - Some(SpecialComment::RuffIsort(rest.to_owned())) - } - _ => None, - } + Some((end_index, SpecialComment::RuffIsort(rest))) } -fn check_single_comment(diagnostics: &mut Vec, text: &str, range: TextRange) { - let Some(comment_body) = remove_comment_start_and_leading_whitespace(text) else { - return; - }; - - // FIXME: Remove this once everything is done - println!("Comment: {text:?}"); - - if let Ok(Some(file_level_noqa)) = try_parse_file_level_noqa(text) { - let hint = match comment_body.chars().into_iter().next() { - Some('f') => "flake8", - Some('r') => "ruff", - _ => panic!("Unexpected parsed file exemption hint"), - }; - - let comment = file_level_noqa_special_comment(hint.to_owned(), file_level_noqa); - add_diagnostic_if_applicable(diagnostics, comment, text, range); - return; - } +fn try_parse_common(text: &str) -> Option<(EndIndex, SpecialComment)> { + static PATTERN: Lazy = Lazy::new( + Regex::new( + r"(?x) + ^ + \#\s* + (?type|mypy|pyright|fmt|isort|nopycln):\s* + (?.+) + " + ) + .unwrap() + ); + + let Some(result) = PATTERN.captures(text); + + let end_index = result.get(0).unwrap().end(); + let hint = result.name("hint").unwrap().as_str().to_owned(); + let rest = result.name("rest").unwrap().as_str().to_owned(); + + Some((end_index, SpecialComment::Common(hint, rest))) +} - if let Ok(Some(noqa)) = try_parse_noqa(text) { - let comment = noqa_special_comment(noqa); - add_diagnostic_if_applicable(diagnostics, comment, text, range); - return; - } +macro_rules! parse_and_handle_comment { + ($parse:ident, $text:ident, $diagnostics:ident, $range:ident) => { + if let Some((end_index, comment)) = $parse($text) { + let comment_text = &$text[..end_index]; - let Some(comment) = try_parse_generic_hint_comment(comment_body) else { - return; + add_diagnostic_if_applicable($diagnostics, comment, comment_text, $range); + return; + } }; +} - add_diagnostic_if_applicable(diagnostics, comment, text, range); +fn check_single_comment(diagnostics: &mut Vec, text: &str, range: TextRange) { + parse_and_handle_comment!(try_parse_file_level_noqa, text, diagnostics, range); + parse_and_handle_comment!(try_parse_noqa, text, diagnostics, range); + parse_and_handle_comment!(try_parse_ruff_isort, text, diagnostics, range); + parse_and_handle_comment!(try_parse_common, text, diagnostics, range); } /// RUF104 @@ -255,6 +268,12 @@ pub(crate) fn unformatted_special_comment( for range in comment_ranges { let text = locator.slice(range); - check_single_comment(diagnostics, text, range); + for (index, char) in text.char_indices() { + if !matches!(char, '#') { + continue; + } + + check_single_comment(diagnostics, text, range); + } } } From 7c97af8ebd7729a07871d2afffa05adaf27e506c Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Wed, 6 Nov 2024 06:10:05 +0000 Subject: [PATCH 05/29] Fix --- Cargo.lock | 1 + Cargo.toml | 1 + crates/ruff_linter/Cargo.toml | 1 + .../ruff/rules/unformatted_special_comment.rs | 101 +++++++++--------- 4 files changed, 53 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1a09eb3febecca..5df3556f4985f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2555,6 +2555,7 @@ dependencies = [ "log", "memchr", "natord", + "once_cell", "path-absolutize", "pathdiff", "pep440_rs 0.7.2", diff --git a/Cargo.toml b/Cargo.toml index 1002410da691ae..8709acbdff91f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -103,6 +103,7 @@ memchr = { version = "2.7.1" } mimalloc = { version = "0.1.39" } natord = { version = "1.0.9" } notify = { version = "7.0.0" } +once_cell = { version = "1.20.2" } ordermap = { version = "0.5.0" } path-absolutize = { version = "3.1.1" } path-slash = { version = "0.2.1" } diff --git a/crates/ruff_linter/Cargo.toml b/crates/ruff_linter/Cargo.toml index ef2dfd885f6a66..dae8e25677ab1b 100644 --- a/crates/ruff_linter/Cargo.toml +++ b/crates/ruff_linter/Cargo.toml @@ -46,6 +46,7 @@ libcst = { workspace = true } log = { workspace = true } memchr = { workspace = true } natord = { workspace = true } +once_cell = { workspace = true } path-absolutize = { workspace = true, features = [ "once_cell_cache", "use_unix_paths_on_wasm", diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index 238ed4f352a569..ecb9b91345c379 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -1,4 +1,3 @@ -use crate::noqa::{Directive, ParseError, ParsedFileExemption}; use crate::Locator; use once_cell::sync::Lazy; use regex::Regex; @@ -6,11 +5,10 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_trivia::CommentRanges; use ruff_text_size::TextRange; +use ruff_text_size::TextSize; type EndIndex = usize; -const KNOWN_COMMON_HINT: [&str; 6] = ["fmt", "isort", "mypy", "nopycln", "pyright", "type"]; - #[derive(Debug, Eq, PartialEq)] enum SpecialComment { /// `# noqa`, `# noqa: A123, B456` @@ -33,15 +31,13 @@ enum SpecialComment { impl SpecialComment { fn formatted(&self) -> String { match self { - SpecialComment::Common { hint, rest } => format!("# {}: {}", hint.to_lowercase(), rest) - .trim_ascii_end() - .to_owned(), + SpecialComment::Common { hint, rest } => { + format!("# {}: {}", hint.to_lowercase(), rest) + } SpecialComment::RuffIsort(rest) => { format!("# ruff: isort: {rest}") } - SpecialComment::Noqa(None) => { - format!("# noqa") - } + SpecialComment::Noqa(None) => "# noqa".to_string(), SpecialComment::Noqa(Some(codes)) => { format!("# noqa: {}", codes.join(", ")) } @@ -102,34 +98,34 @@ fn add_diagnostic_if_applicable( diagnostics: &mut Vec, comment: SpecialComment, original_comment_text: &str, - range: TextRange, + original_comment_text_range: TextRange, ) { - let formatted_comment = comment.formatted(); + let formatted_comment_text = comment.formatted(); - if original_comment_text == formatted_comment { + if original_comment_text == formatted_comment_text { return; } - let edit = Edit::range_replacement(formatted_comment, range); + let edit = Edit::range_replacement(formatted_comment_text, original_comment_text_range); let fix = Fix::safe_edit(edit); let violation = UnformattedSpecialComment(comment); - let diagnostic = Diagnostic::new(violation, range).with_fix(fix); + let diagnostic = Diagnostic::new(violation, original_comment_text_range).with_fix(fix); diagnostics.push(diagnostic); } fn parse_code_list(code_list: &str) -> Vec { - static PATTERN: Regex = Lazy::new(Regex::new(r"[A-Z]+[A-Za-z0-9]+")); + static PATTERN: Lazy = Lazy::new(|| Regex::new(r"[A-Z]+[A-Za-z0-9]+").unwrap()); PATTERN - .find_iter(list) + .find_iter(code_list) .map(|code| code.as_str().to_owned()) .collect() } fn try_parse_file_level_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { - static PATTERN: Regex = Lazy::new( + static PATTERN: Lazy = Lazy::new(|| { Regex::new( r"(?x) ^ @@ -147,12 +143,10 @@ fn try_parse_file_level_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { $ ", ) - .unwrap(), - ); + .unwrap() + }); - let Some(result) = PATTERN.captures(text) else { - return None; - }; + let result = PATTERN.captures(text)?; let end_index = result.get(0).unwrap().end(); let hint = result.name("hint").unwrap().as_str().to_owned(); @@ -164,7 +158,7 @@ fn try_parse_file_level_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { } fn try_parse_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { - static PATTERN: Regex = Lazy::new( + static PATTERN: Lazy = Lazy::new(|| { Regex::new( r"(?x) ^ @@ -174,18 +168,16 @@ fn try_parse_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { :\s* (? [A-Z]+[A-Za-z0-9]+ - (?:[\h,]+[A-Z]+[A-Za-z0-9]+)* + (?:[\s,]+[A-Z]+[A-Za-z0-9]+)* )? )? $ ", ) - .unwrap(), - ); + .unwrap() + }); - let Some(result) = PATTERN.captures(text) else { - return None; - }; + let result = PATTERN.captures(text)?; let end_index = result.get(0).unwrap().end(); let codes = result @@ -196,7 +188,7 @@ fn try_parse_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { } fn try_parse_ruff_isort(text: &str) -> Option<(EndIndex, SpecialComment)> { - static PATTERN: Regex = Lazy::new( + static PATTERN: Lazy = Lazy::new(|| { Regex::new( r"(?x) ^ @@ -206,12 +198,10 @@ fn try_parse_ruff_isort(text: &str) -> Option<(EndIndex, SpecialComment)> { (?.+) ", ) - .unwrap(), - ); + .unwrap() + }); - let Some(result) = PATTERN.captures(text) else { - return None; - }; + let result = PATTERN.captures(text)?; let end_index = result.get(0).unwrap().end(); let rest = result.name("rest").unwrap().as_str().to_owned(); @@ -220,43 +210,52 @@ fn try_parse_ruff_isort(text: &str) -> Option<(EndIndex, SpecialComment)> { } fn try_parse_common(text: &str) -> Option<(EndIndex, SpecialComment)> { - static PATTERN: Lazy = Lazy::new( + static PATTERN: Lazy = Lazy::new(|| { Regex::new( r"(?x) ^ \#\s* (?type|mypy|pyright|fmt|isort|nopycln):\s* (?.+) - " + ", ) .unwrap() - ); + }); - let Some(result) = PATTERN.captures(text); + let result = PATTERN.captures(text)?; let end_index = result.get(0).unwrap().end(); let hint = result.name("hint").unwrap().as_str().to_owned(); let rest = result.name("rest").unwrap().as_str().to_owned(); - Some((end_index, SpecialComment::Common(hint, rest))) + Some((end_index, SpecialComment::Common { hint, rest })) } macro_rules! parse_and_handle_comment { - ($parse:ident, $text:ident, $diagnostics:ident, $range:ident) => { - if let Some((end_index, comment)) = $parse($text) { - let comment_text = &$text[..end_index]; - - add_diagnostic_if_applicable($diagnostics, comment, comment_text, $range); + ($parse:ident, $text:ident, $diagnostics:ident, $absolute_start_index:ident) => { + if let Some((relative_end_index, comment)) = $parse($text) { + let comment_text = &$text[..relative_end_index]; + let absolute_end_index = $absolute_start_index + relative_end_index; + + let Ok(start) = TryInto::::try_into($absolute_start_index) else { + return; + }; + let Ok(end) = TryInto::::try_into(absolute_end_index) else { + return; + }; + let range = TextRange::new(start, end); + + add_diagnostic_if_applicable($diagnostics, comment, comment_text, range); return; } }; } -fn check_single_comment(diagnostics: &mut Vec, text: &str, range: TextRange) { - parse_and_handle_comment!(try_parse_file_level_noqa, text, diagnostics, range); - parse_and_handle_comment!(try_parse_noqa, text, diagnostics, range); - parse_and_handle_comment!(try_parse_ruff_isort, text, diagnostics, range); - parse_and_handle_comment!(try_parse_common, text, diagnostics, range); +fn check_single_comment(diagnostics: &mut Vec, text: &str, start_index: usize) { + parse_and_handle_comment!(try_parse_file_level_noqa, text, diagnostics, start_index); + parse_and_handle_comment!(try_parse_noqa, text, diagnostics, start_index); + parse_and_handle_comment!(try_parse_ruff_isort, text, diagnostics, start_index); + parse_and_handle_comment!(try_parse_common, text, diagnostics, start_index); } /// RUF104 @@ -273,7 +272,7 @@ pub(crate) fn unformatted_special_comment( continue; } - check_single_comment(diagnostics, text, range); + check_single_comment(diagnostics, &text[index..], index); } } } From 43b24cdb797454a7b4e03bfa403fe4ab81a6a37c Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Thu, 7 Nov 2024 06:11:56 +0000 Subject: [PATCH 06/29] Switch to `std::sync::LazyLock` --- Cargo.lock | 1 - Cargo.toml | 1 - crates/ruff_linter/Cargo.toml | 1 - crates/ruff_linter/src/codes.rs | 2 +- crates/ruff_linter/src/noqa.rs | 2 +- .../rules/ruff/rules/unformatted_special_comment.rs | 12 ++++++------ ...inter__rules__ruff__tests__RUF104_RUF104.py.snap} | 1 + 7 files changed, 9 insertions(+), 11 deletions(-) rename crates/ruff_linter/src/rules/ruff/snapshots/{ruff_linter__rules__ruff__tests__RUF102_RUF102.py.snap => ruff_linter__rules__ruff__tests__RUF104_RUF104.py.snap} (74%) diff --git a/Cargo.lock b/Cargo.lock index 5df3556f4985f9..1a09eb3febecca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2555,7 +2555,6 @@ dependencies = [ "log", "memchr", "natord", - "once_cell", "path-absolutize", "pathdiff", "pep440_rs 0.7.2", diff --git a/Cargo.toml b/Cargo.toml index 8709acbdff91f3..1002410da691ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -103,7 +103,6 @@ memchr = { version = "2.7.1" } mimalloc = { version = "0.1.39" } natord = { version = "1.0.9" } notify = { version = "7.0.0" } -once_cell = { version = "1.20.2" } ordermap = { version = "0.5.0" } path-absolutize = { version = "3.1.1" } path-slash = { version = "0.2.1" } diff --git a/crates/ruff_linter/Cargo.toml b/crates/ruff_linter/Cargo.toml index dae8e25677ab1b..ef2dfd885f6a66 100644 --- a/crates/ruff_linter/Cargo.toml +++ b/crates/ruff_linter/Cargo.toml @@ -46,7 +46,6 @@ libcst = { workspace = true } log = { workspace = true } memchr = { workspace = true } natord = { workspace = true } -once_cell = { workspace = true } path-absolutize = { workspace = true, features = [ "once_cell_cache", "use_unix_paths_on_wasm", diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index 8cfa0897ac916a..857bb68c26309e 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -967,7 +967,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Ruff, "034") => (RuleGroup::Preview, rules::ruff::rules::UselessIfElse), (Ruff, "100") => (RuleGroup::Stable, rules::ruff::rules::UnusedNOQA), (Ruff, "101") => (RuleGroup::Stable, rules::ruff::rules::RedirectedNOQA), - (Ruff, "102") => (RuleGroup::Preview, rules::ruff::rules::UnformattedSpecialComment), + (Ruff, "104") => (RuleGroup::Preview, rules::ruff::rules::UnformattedSpecialComment), (Ruff, "200") => (RuleGroup::Stable, rules::ruff::rules::InvalidPyprojectToml), #[cfg(any(feature = "test-rules", test))] diff --git a/crates/ruff_linter/src/noqa.rs b/crates/ruff_linter/src/noqa.rs index 1b9020874d0034..f734448c795e21 100644 --- a/crates/ruff_linter/src/noqa.rs +++ b/crates/ruff_linter/src/noqa.rs @@ -432,7 +432,7 @@ pub(crate) enum ParsedFileExemption<'a> { impl<'a> ParsedFileExemption<'a> { /// Return a [`ParsedFileExemption`] for a given comment line. - pub(crate) fn try_extract(line: &'a str) -> Result, ParseError> { + fn try_extract(line: &'a str) -> Result, ParseError> { let line = Self::lex_whitespace(line); let Some(line) = Self::lex_char(line, '#') else { return Ok(None); diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index ecb9b91345c379..14c4ace4001be2 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -1,5 +1,5 @@ use crate::Locator; -use once_cell::sync::Lazy; +use std::sync::LazyLock; use regex::Regex; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; @@ -116,7 +116,7 @@ fn add_diagnostic_if_applicable( } fn parse_code_list(code_list: &str) -> Vec { - static PATTERN: Lazy = Lazy::new(|| Regex::new(r"[A-Z]+[A-Za-z0-9]+").unwrap()); + static PATTERN: LazyLock = LazyLock::new(|| Regex::new(r"[A-Z]+[A-Za-z0-9]+").unwrap()); PATTERN .find_iter(code_list) @@ -125,7 +125,7 @@ fn parse_code_list(code_list: &str) -> Vec { } fn try_parse_file_level_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { - static PATTERN: Lazy = Lazy::new(|| { + static PATTERN: LazyLock = LazyLock::new(|| { Regex::new( r"(?x) ^ @@ -158,7 +158,7 @@ fn try_parse_file_level_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { } fn try_parse_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { - static PATTERN: Lazy = Lazy::new(|| { + static PATTERN: LazyLock = LazyLock::new(|| { Regex::new( r"(?x) ^ @@ -188,7 +188,7 @@ fn try_parse_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { } fn try_parse_ruff_isort(text: &str) -> Option<(EndIndex, SpecialComment)> { - static PATTERN: Lazy = Lazy::new(|| { + static PATTERN: LazyLock = LazyLock::new(|| { Regex::new( r"(?x) ^ @@ -210,7 +210,7 @@ fn try_parse_ruff_isort(text: &str) -> Option<(EndIndex, SpecialComment)> { } fn try_parse_common(text: &str) -> Option<(EndIndex, SpecialComment)> { - static PATTERN: Lazy = Lazy::new(|| { + static PATTERN: LazyLock = LazyLock::new(|| { Regex::new( r"(?x) ^ diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF102_RUF102.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF104_RUF104.py.snap similarity index 74% rename from crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF102_RUF102.py.snap rename to crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF104_RUF104.py.snap index 7f58cfd7246a31..b3a37c09211090 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF102_RUF102.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF104_RUF104.py.snap @@ -1,4 +1,5 @@ --- source: crates/ruff_linter/src/rules/ruff/mod.rs +snapshot_kind: text --- From 0d0cc2bd00ef3454f4e9be5ef621bd632a4d054f Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Thu, 7 Nov 2024 09:10:39 +0000 Subject: [PATCH 07/29] Add a few tests --- .../resources/test/fixtures/ruff/RUF104.py | 1 - .../ruff/rules/unformatted_special_comment.rs | 153 ++++++++++++++++-- 2 files changed, 139 insertions(+), 15 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py index 8ca6268a5bb98e..69dbecbc496657 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py @@ -111,4 +111,3 @@ #noqa: D101 undocumented-public-class # noqa :RUF001,RUF002 # type:ignore - diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index 14c4ace4001be2..2f0c97b25f1f47 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -1,11 +1,11 @@ use crate::Locator; -use std::sync::LazyLock; use regex::Regex; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_trivia::CommentRanges; use ruff_text_size::TextRange; use ruff_text_size::TextSize; +use std::sync::LazyLock; type EndIndex = usize; @@ -29,26 +29,34 @@ enum SpecialComment { } impl SpecialComment { - fn formatted(&self) -> String { + fn formatted(&self) -> Option { match self { SpecialComment::Common { hint, rest } => { - format!("# {}: {}", hint.to_lowercase(), rest) - } - SpecialComment::RuffIsort(rest) => { - format!("# ruff: isort: {rest}") + Some(format!("# {}: {}", hint.to_lowercase(), rest)) } - SpecialComment::Noqa(None) => "# noqa".to_string(), + SpecialComment::RuffIsort(rest) => Some(format!("# ruff: isort: {rest}")), + SpecialComment::Noqa(None) => Some("# noqa".to_string()), SpecialComment::Noqa(Some(codes)) => { - format!("# noqa: {}", codes.join(", ")) - } - SpecialComment::FileLevelNoqa { hint, codes: None } => { - format!("# {hint}: noqa") + if codes.is_empty() { + // Avoid suggesting the unsafe fix + // `# noqa:` (ignore nothing) -> `# noqa` (ignore everything). + None + } else { + Some(format!("# noqa: {}", codes.join(", "))) + } } + SpecialComment::FileLevelNoqa { hint, codes: None } => Some(format!("# {hint}: noqa")), SpecialComment::FileLevelNoqa { hint, codes: Some(codes), } => { - format!("# {hint}: noqa: {}", codes.join(", ")) + if codes.is_empty() { + // Avoid suggesting the unsafe fix + // `# ruff: noqa:` (ignore nothing) -> `# ruff: noqa` (ignore everything). + None + } else { + Some(format!("# {hint}: noqa: {}", codes.join(", "))) + } } } } @@ -100,7 +108,9 @@ fn add_diagnostic_if_applicable( original_comment_text: &str, original_comment_text_range: TextRange, ) { - let formatted_comment_text = comment.formatted(); + let Some(formatted_comment_text) = comment.formatted() else { + return; + }; if original_comment_text == formatted_comment_text { return; @@ -216,7 +226,7 @@ fn try_parse_common(text: &str) -> Option<(EndIndex, SpecialComment)> { ^ \#\s* (?type|mypy|pyright|fmt|isort|nopycln):\s* - (?.+) + (?\S.*) ", ) .unwrap() @@ -276,3 +286,118 @@ pub(crate) fn unformatted_special_comment( } } } + +#[cfg(test)] +mod tests { + use ruff_diagnostics::Diagnostic; + + use super::check_single_comment; + + fn test(text: &str) -> Vec { + let mut diagnostics = vec![]; + let start_index = 0; + + check_single_comment(&mut diagnostics, text, start_index); + + return diagnostics; + } + + fn has_unformatted(text: &str) { + let diagnostics = test(text); + + assert!(!diagnostics.is_empty()); + } + + fn no_unformatted(text: &str) { + let diagnostics = test(text); + + assert!(diagnostics.is_empty()); + } + + #[test] + fn unknown() { + no_unformatted("#foo"); + no_unformatted("# foo"); + + no_unformatted("#ruff: foo-bar"); + no_unformatted("# flake8:foo-bar"); + + no_unformatted("# black:skip"); + } + + #[test] + fn casing() { + no_unformatted("# Mypy: disallow-subclassing-any"); + no_unformatted("# Type: ignore"); + no_unformatted("# FMT:OFF"); + } + + #[test] + fn already_formatted_noqa() { + no_unformatted("# noqa"); + no_unformatted("# noqa: A123"); + no_unformatted("# noqa: A123, B456"); + + no_unformatted("# ruff: noqa"); + no_unformatted("# ruff: noqa: A123"); + no_unformatted("# ruff: noqa: A123, B456"); + + no_unformatted("# flake8: noqa"); + no_unformatted("# flake8: noqa: A123"); + no_unformatted("# flake8: noqa: A123, B456"); + + no_unformatted("# ruff: isort: on"); + no_unformatted("# ruff: isort: skip_file"); + } + + #[test] + fn whitespace() { + has_unformatted("# noqa:A123"); + has_unformatted("#noqa: A123"); + + has_unformatted("# type:ignore"); + has_unformatted("#type:\tint"); + + has_unformatted("# fmt:off"); + has_unformatted("#fmt: on"); + has_unformatted("#fmt: skip"); + } + + #[test] + fn rule_code_separators() { + has_unformatted("# noqa: A123 B456"); + has_unformatted("# ruff: noqa: A123 B456"); + has_unformatted("# flake8: noqa: A123 B456"); + + has_unformatted("# noqa: A123,B456"); + has_unformatted("# ruff: noqa: A123,B456"); + has_unformatted("# flake8: noqa: A123,B456"); + + has_unformatted("# noqa: A123,,B456"); + has_unformatted("# noqa: A123 , \t,\t \tB456"); + has_unformatted("# noqa: A123\tB456"); + has_unformatted("# noqa: A123\t\t\tB456"); + has_unformatted("# noqa: A123\t\t\t\tB456"); + + has_unformatted("# noqa: A123 ,B456"); + has_unformatted("# ruff: noqa: A123\tB456"); + has_unformatted("# flake8: noqa: A123 B456"); + } + + #[test] + fn common() { + has_unformatted("#type:ignore"); + has_unformatted("#pyright:strict"); + has_unformatted("#isort:skip_file"); + has_unformatted("#nopycln:import"); + has_unformatted("#fmt:off"); + has_unformatted("#fmt:on"); + has_unformatted("#fmt:skip"); + + has_unformatted("#\t mypy: ignore-errors"); + has_unformatted("#\t type:ignore"); + has_unformatted("# \tpyright: \t strict"); + has_unformatted("# \t pyright:ignore[reportFoo]"); + has_unformatted("# \t\t\tisort:skip_file"); + } +} From 189f2656af8230016fbffc036e3ac1600e34ff5e Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Thu, 7 Nov 2024 11:02:04 +0000 Subject: [PATCH 08/29] Fix lint error --- .../src/rules/ruff/rules/unformatted_special_comment.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index 2f0c97b25f1f47..6eb8abcdb2fc85 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -299,7 +299,7 @@ mod tests { check_single_comment(&mut diagnostics, text, start_index); - return diagnostics; + diagnostics } fn has_unformatted(text: &str) { From 7cfe1b46d2985821a10f2ead2ab165a46b565202 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Fri, 8 Nov 2024 06:21:53 +0000 Subject: [PATCH 09/29] Use different variant for each kind of special comments --- .../ruff/rules/unformatted_special_comment.rs | 269 +++++++++++------- 1 file changed, 174 insertions(+), 95 deletions(-) diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index 6eb8abcdb2fc85..f14b01878be981 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -19,45 +19,55 @@ enum SpecialComment { hint: String, codes: Option>, }, + + /// `# fmt: on`, `# fmt: off`, `fmt: skip` + Fmt(String), + /// `# isort: skip_file` + Isort(String), + /// `# mypy: ignore-errors` + Mypy(String), + /// `# nopycln: import` + Nopycln(String), + /// `# pyright: strict`, `# pyright: ignore[reportFoo]` + Pyright(String), /// `# ruff: isort: skip_file` RuffIsort(String), - /// `# mypy: ignore-errors`, `# type: ignore`/`# type: int`, - /// `# pyright: strict`/`# pyright: ignore[reportFoo]`, - /// `# isort: skip_file`, `# nopycln: import`, - /// `# fmt: on`/`# fmt: off`/`fmt: skip`. - Common { hint: String, rest: String }, + /// `# type: int`, `# type: ignore` + Type(String), } impl SpecialComment { fn formatted(&self) -> Option { match self { - SpecialComment::Common { hint, rest } => { - Some(format!("# {}: {}", hint.to_lowercase(), rest)) - } - SpecialComment::RuffIsort(rest) => Some(format!("# ruff: isort: {rest}")), SpecialComment::Noqa(None) => Some("# noqa".to_string()), - SpecialComment::Noqa(Some(codes)) => { - if codes.is_empty() { - // Avoid suggesting the unsafe fix - // `# noqa:` (ignore nothing) -> `# noqa` (ignore everything). - None - } else { - Some(format!("# noqa: {}", codes.join(", "))) - } - } + + // Avoid suggesting the unsafe fix + // `# noqa:` (ignore nothing) -> `# noqa` (ignore everything). + SpecialComment::Noqa(Some(codes)) if codes.is_empty() => None, + + SpecialComment::Noqa(Some(codes)) => Some(format!("# noqa: {}", codes.join(", "))), + SpecialComment::FileLevelNoqa { hint, codes: None } => Some(format!("# {hint}: noqa")), + + // Avoid suggesting the unsafe fix + // `# ruff: noqa:` (ignore nothing) -> `# ruff: noqa` (ignore everything). + SpecialComment::FileLevelNoqa { + codes: Some(codes), .. + } if codes.is_empty() => None, + SpecialComment::FileLevelNoqa { hint, codes: Some(codes), - } => { - if codes.is_empty() { - // Avoid suggesting the unsafe fix - // `# ruff: noqa:` (ignore nothing) -> `# ruff: noqa` (ignore everything). - None - } else { - Some(format!("# {hint}: noqa: {}", codes.join(", "))) - } - } + } => Some(format!("# {hint}: noqa: {}", codes.join(", "))), + + SpecialComment::Nopycln(rest) => Some(format!("# nopycln: {}", rest.to_lowercase())), + + SpecialComment::Fmt(rest) => Some(format!("# fmt: {rest}")), + SpecialComment::Isort(rest) => Some(format!("# isort: {rest}")), + SpecialComment::Mypy(rest) => Some(format!("# mypy: {rest}")), + SpecialComment::Pyright(rest) => Some(format!("# pyright: {rest}")), + SpecialComment::RuffIsort(rest) => Some(format!("# ruff: isort: {rest}")), + SpecialComment::Type(rest) => Some(format!("# type: {rest}")), } } } @@ -134,21 +144,31 @@ fn parse_code_list(code_list: &str) -> Vec { .collect() } -fn try_parse_file_level_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { +macro_rules! try_parse_common { + ($pattern:ident, $text:ident, $special_comment:expr) => {{ + let result = $pattern.captures($text)?; + + let end_index = result.get(0).unwrap().end(); + let rest = result.name("rest").unwrap().as_str().to_owned(); + + Some((end_index, $special_comment(rest))) + }}; +} + +fn try_parse_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { + // ruff_linter::noqa::Directive::try_extract static PATTERN: LazyLock = LazyLock::new(|| { Regex::new( r"(?x) ^ \#\s* - (?flake8|ruff)\s*:\s* - (?i:noqa)\s* + (?i:noqa) (?: :\s* (? [A-Z]+[A-Za-z0-9]+ - (?:[\s,]\s*[A-Z]+[A-Za-z0-9]+)* + (?:[\s,]+[A-Z]+[A-Za-z0-9]+)* )? - \s* )? $ ", @@ -159,27 +179,29 @@ fn try_parse_file_level_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { let result = PATTERN.captures(text)?; let end_index = result.get(0).unwrap().end(); - let hint = result.name("hint").unwrap().as_str().to_owned(); let codes = result .name("code_list") .map(|it| parse_code_list(it.as_str())); - Some((end_index, SpecialComment::FileLevelNoqa { hint, codes })) + Some((end_index, SpecialComment::Noqa(codes))) } -fn try_parse_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { +fn try_parse_file_level_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { + // ruff_linter::noqa::ParsedFileExemption::try_extract static PATTERN: LazyLock = LazyLock::new(|| { Regex::new( r"(?x) ^ \#\s* - (?i:noqa) + (?flake8|ruff)\s*:\s* + (?i:noqa)\s* (?: :\s* (? [A-Z]+[A-Za-z0-9]+ - (?:[\s,]+[A-Z]+[A-Za-z0-9]+)* + (?:[\s,]\s*[A-Z]+[A-Za-z0-9]+)* )? + \s* )? $ ", @@ -190,55 +212,69 @@ fn try_parse_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { let result = PATTERN.captures(text)?; let end_index = result.get(0).unwrap().end(); + let hint = result.name("hint").unwrap().as_str().to_owned(); let codes = result .name("code_list") .map(|it| parse_code_list(it.as_str())); - Some((end_index, SpecialComment::Noqa(codes))) + Some((end_index, SpecialComment::FileLevelNoqa { hint, codes })) } -fn try_parse_ruff_isort(text: &str) -> Option<(EndIndex, SpecialComment)> { - static PATTERN: LazyLock = LazyLock::new(|| { - Regex::new( - r"(?x) - ^ - \#\s* - ruff\s*:\s* - isort\s*:\s* - (?.+) - ", - ) - .unwrap() - }); +fn try_parse_fmt(text: &str) -> Option<(EndIndex, SpecialComment)> { + static PATTERN: LazyLock = + LazyLock::new(|| Regex::new(r"^#\s*fmt:\s*(?on|off|skip)").unwrap()); - let result = PATTERN.captures(text)?; + try_parse_common!(PATTERN, text, SpecialComment::Fmt) +} - let end_index = result.get(0).unwrap().end(); - let rest = result.name("rest").unwrap().as_str().to_owned(); +fn try_parse_isort(text: &str) -> Option<(EndIndex, SpecialComment)> { + static PATTERN: LazyLock = + LazyLock::new(|| Regex::new(r"^# isort:(?skip|skip_file)").unwrap()); - Some((end_index, SpecialComment::RuffIsort(rest))) + try_parse_common!(PATTERN, text, SpecialComment::Isort) } -fn try_parse_common(text: &str) -> Option<(EndIndex, SpecialComment)> { - static PATTERN: LazyLock = LazyLock::new(|| { - Regex::new( - r"(?x) - ^ - \#\s* - (?type|mypy|pyright|fmt|isort|nopycln):\s* - (?\S.*) - ", - ) - .unwrap() - }); +fn try_parse_mypy(text: &str) -> Option<(EndIndex, SpecialComment)> { + // https://github.com/python/mypy/blob/3b00002acd/mypy/util.py#L228 + static PATTERN: LazyLock = + LazyLock::new(|| Regex::new(r"^# mypy:\s*(?\S)").unwrap()); - let result = PATTERN.captures(text)?; + try_parse_common!(PATTERN, text, SpecialComment::Mypy) +} - let end_index = result.get(0).unwrap().end(); - let hint = result.name("hint").unwrap().as_str().to_owned(); - let rest = result.name("rest").unwrap().as_str().to_owned(); +fn try_parse_nopycln(text: &str) -> Option<(EndIndex, SpecialComment)> { + // https://github.com/hadialqattan/pycln/blob/d0aeb62860/pycln/utils/regexu.py#L18-L19 + // https://github.com/hadialqattan/pycln/blob/d0aeb62860/pycln/utils/regexu.py#L127 + // https://github.com/hadialqattan/pycln/blob/d0aeb62860/pycln/utils/regexu.py#L136 + static PATTERN: LazyLock = + LazyLock::new(|| Regex::new(r"(?i)^#\s*nopycln\s*:\s*(?file|import)").unwrap()); + + try_parse_common!(PATTERN, text, SpecialComment::Nopycln) +} + +fn try_parse_pyright(text: &str) -> Option<(EndIndex, SpecialComment)> { + // https://github.com/microsoft/pyright/blob/9d60c434c4/packages/pyright-internal/src/parser/tokenizer.ts#L1314 + // https://github.com/microsoft/pyright/blob/9d60c434c4/packages/pyright-internal/src/analyzer/commentUtils.ts#L138 + static PATTERN: LazyLock = + LazyLock::new(|| Regex::new(r"^#\s*pyright:\s*(?\S)").unwrap()); + + try_parse_common!(PATTERN, text, SpecialComment::Pyright) +} + +fn try_parse_ruff_isort(text: &str) -> Option<(EndIndex, SpecialComment)> { + // ruff_linter::directives::extract_isort_directives + static PATTERN: LazyLock = + LazyLock::new(|| Regex::new(r"^# ruff: isort: ?(?skip|skip_file)").unwrap()); + + try_parse_common!(PATTERN, text, SpecialComment::RuffIsort) +} + +fn try_parse_type(text: &str) -> Option<(EndIndex, SpecialComment)> { + // https://github.com/python/cpython/blob/c222441fa7/Parser/lexer/lexer.c#L45-L47 + static PATTERN: LazyLock = + LazyLock::new(|| Regex::new(r"^#\s*type:\s*(?\S)").unwrap()); - Some((end_index, SpecialComment::Common { hint, rest })) + try_parse_common!(PATTERN, text, SpecialComment::Type) } macro_rules! parse_and_handle_comment { @@ -262,10 +298,15 @@ macro_rules! parse_and_handle_comment { } fn check_single_comment(diagnostics: &mut Vec, text: &str, start_index: usize) { - parse_and_handle_comment!(try_parse_file_level_noqa, text, diagnostics, start_index); parse_and_handle_comment!(try_parse_noqa, text, diagnostics, start_index); + parse_and_handle_comment!(try_parse_file_level_noqa, text, diagnostics, start_index); + parse_and_handle_comment!(try_parse_fmt, text, diagnostics, start_index); + parse_and_handle_comment!(try_parse_isort, text, diagnostics, start_index); + parse_and_handle_comment!(try_parse_mypy, text, diagnostics, start_index); + parse_and_handle_comment!(try_parse_nopycln, text, diagnostics, start_index); + parse_and_handle_comment!(try_parse_pyright, text, diagnostics, start_index); parse_and_handle_comment!(try_parse_ruff_isort, text, diagnostics, start_index); - parse_and_handle_comment!(try_parse_common, text, diagnostics, start_index); + parse_and_handle_comment!(try_parse_type, text, diagnostics, start_index); } /// RUF104 @@ -326,14 +367,16 @@ mod tests { } #[test] - fn casing() { + fn incorrect_casing() { + no_unformatted("# FMT:OFF"); + no_unformatted("# isort: On"); no_unformatted("# Mypy: disallow-subclassing-any"); + no_unformatted("# PyRight: basic"); no_unformatted("# Type: ignore"); - no_unformatted("# FMT:OFF"); } #[test] - fn already_formatted_noqa() { + fn already_formatted() { no_unformatted("# noqa"); no_unformatted("# noqa: A123"); no_unformatted("# noqa: A123, B456"); @@ -346,8 +389,33 @@ mod tests { no_unformatted("# flake8: noqa: A123"); no_unformatted("# flake8: noqa: A123, B456"); + no_unformatted("# fmt: on"); + no_unformatted("# fmt: off"); + no_unformatted("# fmt: skip"); + + no_unformatted("# isort: on"); + no_unformatted("# isort: off"); + no_unformatted("# isort: split"); + no_unformatted("# isort: skip"); + no_unformatted("# isort: skip_file"); + + no_unformatted("# mypy: enable-error-codes="); + + no_unformatted("# nopycln: file"); + no_unformatted("# nopycln: import"); + + no_unformatted("# pyright: basic"); + no_unformatted("# pyright: standard"); + no_unformatted("# pyright: strict"); + no_unformatted("# pyright: ignore"); + no_unformatted("# pyright: ignore [reportFoo]"); + no_unformatted("# ruff: isort: on"); no_unformatted("# ruff: isort: skip_file"); + + no_unformatted("# type: ignore"); + no_unformatted("# type: int"); + no_unformatted("# type: list[str]"); } #[test] @@ -360,7 +428,35 @@ mod tests { has_unformatted("# fmt:off"); has_unformatted("#fmt: on"); - has_unformatted("#fmt: skip"); + has_unformatted("# \t fmt:\t skip"); + + has_unformatted("# isort:skip"); + has_unformatted("# isort:skip_file"); + + has_unformatted("# mypy: disallow-subclassing-any"); + + has_unformatted("# nopycln: \t \t\tfile"); + has_unformatted("# \tnopycln:\t import"); + + has_unformatted("#pyright:ignore[]"); + has_unformatted("#\t\t\tpyright: ignore[]"); + + has_unformatted("# ruff: isort:skip"); + has_unformatted("# ruff: isort:skip_file"); + + has_unformatted("# type:\t\t\tignore"); + has_unformatted("#\t \t \ttype:\t\t \tint"); + } + + #[test] + fn casing() { + has_unformatted("# NoQA: A123, B456"); + has_unformatted("# ruff: NoQA: A123, B456"); + has_unformatted("# flake8: NoQA: A123, B456"); + + has_unformatted("# NoPyCLN: File"); + has_unformatted("# NoPycln: Import"); + has_unformatted("# nOpYcLn: iMpOrT"); } #[test] @@ -383,21 +479,4 @@ mod tests { has_unformatted("# ruff: noqa: A123\tB456"); has_unformatted("# flake8: noqa: A123 B456"); } - - #[test] - fn common() { - has_unformatted("#type:ignore"); - has_unformatted("#pyright:strict"); - has_unformatted("#isort:skip_file"); - has_unformatted("#nopycln:import"); - has_unformatted("#fmt:off"); - has_unformatted("#fmt:on"); - has_unformatted("#fmt:skip"); - - has_unformatted("#\t mypy: ignore-errors"); - has_unformatted("#\t type:ignore"); - has_unformatted("# \tpyright: \t strict"); - has_unformatted("# \t pyright:ignore[reportFoo]"); - has_unformatted("# \t\t\tisort:skip_file"); - } } From fd51044852ca72ceb8a648cec89cf4371ac44399 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Fri, 8 Nov 2024 07:32:29 +0000 Subject: [PATCH 10/29] Fix index bug --- .../ruff/rules/unformatted_special_comment.rs | 21 ++++++++++++------- crates/ruff_python_trivia/src/cursor.rs | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index f14b01878be981..3e2d325710aae2 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -229,7 +229,7 @@ fn try_parse_fmt(text: &str) -> Option<(EndIndex, SpecialComment)> { fn try_parse_isort(text: &str) -> Option<(EndIndex, SpecialComment)> { static PATTERN: LazyLock = - LazyLock::new(|| Regex::new(r"^# isort:(?skip|skip_file)").unwrap()); + LazyLock::new(|| Regex::new(r"^# isort:(?skip_file|skip)").unwrap()); try_parse_common!(PATTERN, text, SpecialComment::Isort) } @@ -237,7 +237,7 @@ fn try_parse_isort(text: &str) -> Option<(EndIndex, SpecialComment)> { fn try_parse_mypy(text: &str) -> Option<(EndIndex, SpecialComment)> { // https://github.com/python/mypy/blob/3b00002acd/mypy/util.py#L228 static PATTERN: LazyLock = - LazyLock::new(|| Regex::new(r"^# mypy:\s*(?\S)").unwrap()); + LazyLock::new(|| Regex::new(r"^# mypy:\s*(?\S+)").unwrap()); try_parse_common!(PATTERN, text, SpecialComment::Mypy) } @@ -256,7 +256,7 @@ fn try_parse_pyright(text: &str) -> Option<(EndIndex, SpecialComment)> { // https://github.com/microsoft/pyright/blob/9d60c434c4/packages/pyright-internal/src/parser/tokenizer.ts#L1314 // https://github.com/microsoft/pyright/blob/9d60c434c4/packages/pyright-internal/src/analyzer/commentUtils.ts#L138 static PATTERN: LazyLock = - LazyLock::new(|| Regex::new(r"^#\s*pyright:\s*(?\S)").unwrap()); + LazyLock::new(|| Regex::new(r"^#\s*pyright:\s*(?\S+)").unwrap()); try_parse_common!(PATTERN, text, SpecialComment::Pyright) } @@ -264,7 +264,7 @@ fn try_parse_pyright(text: &str) -> Option<(EndIndex, SpecialComment)> { fn try_parse_ruff_isort(text: &str) -> Option<(EndIndex, SpecialComment)> { // ruff_linter::directives::extract_isort_directives static PATTERN: LazyLock = - LazyLock::new(|| Regex::new(r"^# ruff: isort: ?(?skip|skip_file)").unwrap()); + LazyLock::new(|| Regex::new(r"^# ruff: isort: ?(?skip_file|skip)").unwrap()); try_parse_common!(PATTERN, text, SpecialComment::RuffIsort) } @@ -272,7 +272,7 @@ fn try_parse_ruff_isort(text: &str) -> Option<(EndIndex, SpecialComment)> { fn try_parse_type(text: &str) -> Option<(EndIndex, SpecialComment)> { // https://github.com/python/cpython/blob/c222441fa7/Parser/lexer/lexer.c#L45-L47 static PATTERN: LazyLock = - LazyLock::new(|| Regex::new(r"^#\s*type:\s*(?\S)").unwrap()); + LazyLock::new(|| Regex::new(r"^#\s*type:\s*(?\S+)").unwrap()); try_parse_common!(PATTERN, text, SpecialComment::Type) } @@ -317,13 +317,18 @@ pub(crate) fn unformatted_special_comment( ) { for range in comment_ranges { let text = locator.slice(range); + let range_start: usize = range.start().into(); - for (index, char) in text.char_indices() { - if !matches!(char, '#') { + for (char_index, char) in text.char_indices() { + let next_char = text[char_index..].chars().next(); + + if char != '#' || matches!(next_char, Some('#')) { continue; } - check_single_comment(diagnostics, &text[index..], index); + let absolute_start_index = range_start + char_index; + + check_single_comment(diagnostics, &text[char_index..], absolute_start_index); } } } diff --git a/crates/ruff_python_trivia/src/cursor.rs b/crates/ruff_python_trivia/src/cursor.rs index c06d83156549d3..3d95334f10ac3f 100644 --- a/crates/ruff_python_trivia/src/cursor.rs +++ b/crates/ruff_python_trivia/src/cursor.rs @@ -21,7 +21,7 @@ impl<'a> Cursor<'a> { } } - /// Return the remaining input as a string slice. + /// Returns the remaining input as an iterator. pub fn chars(&self) -> Chars<'a> { self.chars.clone() } From e332e23fc5456e6268f1fa5735f27b0ff23edc80 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Sat, 9 Nov 2024 01:42:35 +0000 Subject: [PATCH 11/29] Add a few more tests --- .../resources/test/fixtures/ruff/RUF104.py | 194 ++++++++---------- .../ruff/rules/unformatted_special_comment.rs | 6 + 2 files changed, 88 insertions(+), 112 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py index 69dbecbc496657..4d3fb0f472c058 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py @@ -1,113 +1,83 @@ -### No leading space - -#noqa -#noqa: PTH123 -#ruff: noqa -#ruff: noqa: PTH123 -#flake8: noqa -#flake8: noqa: PTH123 -#ruff: isort: skip_file - - -### Too many leading spaces - -# noqa -# noqa: PTH123 -# ruff: noqa -# ruff: noqa: PTH123 -# flake8: noqa -# flake8: noqa: PTH123 -# ruff: isort: skip_file - - -### Space before colon - -# noqa : PTH123 -# ruff : noqa -# ruff : noqa: PTH123 -# ruff: noqa : PTH123 -# ruff : noqa : PTH123 -# flake8 : noqa -# flake8 : noqa: PTH123 -# flake8: noqa : PTH123 -# flake8 : noqa : PTH123 -# ruff : isort: skip_file -# ruff: isort : skip_file -# ruff : isort : skip_file - - -### No space after colon - -# noqa:PTH123 -# ruff:noqa -# ruff:noqa: PTH123 -# ruff: noqa:PTH123 -# ruff:noqa:PTH123 -# flake8:noqa -# flake8:noqa: PTH123 -# flake8: noqa:PTH123 -# flake8:noqa:PTH123 -# ruff:isort: skip_file +#foo +# foo +#ruff: foo-bar +# flake8:foo-bar +# black:skip + +# FMT:OFF +# isort: On +# Mypy: disallow-subclassing-any +# PyRight: basic +# Type: ignore + +# noqa +# noqa: A123 +# noqa: A123, B456 +# ruff: noqa +# ruff: noqa: A123 +# ruff: noqa: A123, B456 +# flake8: noqa +# flake8: noqa: A123 +# flake8: noqa: A123, B456 +# fmt: on +# fmt: off +# fmt: skip +# isort: on +# isort: off +# isort: split +# isort: skip +# isort: skip_file +# mypy: enable-error-codes= +# nopycln: file +# nopycln: import +# pyright: basic +# pyright: standard +# pyright: strict +# pyright: ignore +# pyright: ignore [reportFoo] +# ruff: isort: on +# ruff: isort: skip_file +# type: ignore +# type: int +# type: list[str] + +# noqa:A123 +#noqa: A123 +# type:ignore +#type: int +# fmt:off +#fmt: on +# fmt: skip +# isort:skip +# isort:skip_file +# mypy: disallow-subclassing-any +# nopycln: file +# nopycln: import +#pyright:ignore[] +# pyright: ignore[] +# ruff: isort:skip # ruff: isort:skip_file -# ruff:isort:skip_file - - -### Too many spaces after colon - -# noqa: PTH123 -# ruff: noqa -# ruff: noqa: PTH123 -# ruff: noqa: PTH123 -# ruff: noqa: PTH123 -# flake8: noqa -# flake8: noqa: PTH123 -# flake8: noqa: PTH123 -# flake8: noqa: PTH123 -# ruff: isort: skip_file -# ruff: isort: skip_file -# ruff: isort: skip_file - - -### Rule list separators - -# noqa: PTH123,B012 -# noqa: PTH123 ,B012 -# noqa: PTH123 , B012 -# noqa: PTH123 B012 -# noqa: PTH123 B012 -# noqa: PTH123 B012 -# noqa: PTH123,,B012 -# noqa: PTH123 ,, B012 -# noqa: PTH123 , , B012 - - -### Common - -#fmt : off -# fmt:on -# fmt :skip - -#isort: on -# isort: off -# isort:skip -# isort: skip_file -# isort :dont-add-imports - -# mypy :strict -# mypy: disallow-subclassing-any - -# nopycln : import - -#pyright:basic -#pyright:strict -# pyright: ignore[reportMissingModuleSource] - -#type:ignore -#type :int - - -### Mix'n'match - -#noqa: D101 undocumented-public-class - - # noqa :RUF001,RUF002 # type:ignore +# type: ignore +# type: int + +# NoQA: A123, B456 +# ruff: NoQA: A123, B456 +# flake8: NoQA: A123, B456 +# NoPyCLN: File +# NoPycln: Import +# nOpYcLn: iMpOrT + +# noqa: A123 B456 +# ruff: noqa: A123 B456 +# flake8: noqa: A123 B456 +# noqa: A123,B456 +# ruff: noqa: A123,B456 +# flake8: noqa: A123,B456 +# noqa: A123,,B456 +# noqa: A123 , , B456 +# noqa: A123 B456 +# noqa: A123 B456 +# noqa: A123 B456 +# noqa: A123 ,B456 +# ruff: noqa: A123 B456 +# flake8: noqa: A123 B456 diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index 3e2d325710aae2..95859ad7c75094 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -484,4 +484,10 @@ mod tests { has_unformatted("# ruff: noqa: A123\tB456"); has_unformatted("# flake8: noqa: A123 B456"); } + + #[test] + fn composite() { + has_unformatted("# type: ignore # noqa:A123"); + has_unformatted("# noqa:A123 - Lorem ipsum dolor sit amet"); + } } From 48bba9da073d89c01f335854b7b8643da4b868d2 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Sat, 9 Nov 2024 02:48:03 +0000 Subject: [PATCH 12/29] Fix off-by-one error --- .../ruff/rules/unformatted_special_comment.rs | 61 +++++++++++++------ 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index 95859ad7c75094..436875936beb81 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -309,6 +309,20 @@ fn check_single_comment(diagnostics: &mut Vec, text: &str, start_ind parse_and_handle_comment!(try_parse_type, text, diagnostics, start_index); } +fn check_composite_comment(diagnostics: &mut Vec, text: &str, range_start: usize) { + for (char_index, char) in text.char_indices() { + let next_char = text[char_index..].chars().nth(1); + + if char != '#' || matches!(next_char, Some('#')) { + continue; + } + + let absolute_start_index = range_start + char_index; + + check_single_comment(diagnostics, &text[char_index..], absolute_start_index); + } +} + /// RUF104 pub(crate) fn unformatted_special_comment( diagnostics: &mut Vec, @@ -319,17 +333,7 @@ pub(crate) fn unformatted_special_comment( let text = locator.slice(range); let range_start: usize = range.start().into(); - for (char_index, char) in text.char_indices() { - let next_char = text[char_index..].chars().next(); - - if char != '#' || matches!(next_char, Some('#')) { - continue; - } - - let absolute_start_index = range_start + char_index; - - check_single_comment(diagnostics, &text[char_index..], absolute_start_index); - } + check_composite_comment(diagnostics, text, range_start); } } @@ -337,9 +341,9 @@ pub(crate) fn unformatted_special_comment( mod tests { use ruff_diagnostics::Diagnostic; - use super::check_single_comment; + use super::{check_composite_comment, check_single_comment}; - fn test(text: &str) -> Vec { + fn test_single(text: &str) -> Vec { let mut diagnostics = vec![]; let start_index = 0; @@ -348,18 +352,37 @@ mod tests { diagnostics } + fn test_composite(text: &str) -> Vec { + let mut diagnostics = vec![]; + let start_index = 0; + + check_composite_comment(&mut diagnostics, text, start_index); + + diagnostics + } + fn has_unformatted(text: &str) { - let diagnostics = test(text); + let diagnostics = test_single(text); - assert!(!diagnostics.is_empty()); + assert_eq!(diagnostics.len(), 1); + } + + fn composite_has_unformatted(text: &str, count: usize) { + let diagnostics = test_composite(text); + + assert_eq!(diagnostics.len(), count); } fn no_unformatted(text: &str) { - let diagnostics = test(text); + let diagnostics = test_single(text); assert!(diagnostics.is_empty()); } + fn composite_no_unformatted(text: &str) { + composite_has_unformatted(text, 0); + } + #[test] fn unknown() { no_unformatted("#foo"); @@ -487,7 +510,9 @@ mod tests { #[test] fn composite() { - has_unformatted("# type: ignore # noqa:A123"); - has_unformatted("# noqa:A123 - Lorem ipsum dolor sit amet"); + composite_no_unformatted("# type: ignore # noqa: A123, B456"); + + composite_has_unformatted("#pyright:ignore# noqa:A123", 2); + composite_has_unformatted("# noqa:A123 - Lorem ipsum dolor sit amet", 1); } } From 2c3efb7d281a4802f03d23e78fa91db6a42ebaca Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Sat, 9 Nov 2024 05:21:30 +0000 Subject: [PATCH 13/29] Rewrite again --- .../resources/test/fixtures/ruff/RUF104.py | 9 ++ .../ruff/rules/unformatted_special_comment.rs | 149 +++++++++++------- 2 files changed, 98 insertions(+), 60 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py index 4d3fb0f472c058..12eec796e6e606 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py @@ -81,3 +81,12 @@ # noqa: A123 ,B456 # ruff: noqa: A123 B456 # flake8: noqa: A123 B456 + + +# type: ignore # noqa: A123, B456 + +#pyright:ignore#noqa:A123 + +# nopycln:file# noqa: A123 + +# noqa:A123 - Lorem ipsum dolor sit amet diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index 436875936beb81..ff491c278f4c56 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -5,9 +5,11 @@ use ruff_macros::{derive_message_formats, violation}; use ruff_python_trivia::CommentRanges; use ruff_text_size::TextRange; use ruff_text_size::TextSize; +use std::ops::Range; use std::sync::LazyLock; -type EndIndex = usize; +type HintRelativeRange = Range; +type SpecialCommentDescriptor<'a> = Option<(HintRelativeRange, &'a str, SpecialComment)>; #[derive(Debug, Eq, PartialEq)] enum SpecialComment { @@ -115,22 +117,23 @@ impl AlwaysFixableViolation for UnformattedSpecialComment { fn add_diagnostic_if_applicable( diagnostics: &mut Vec, comment: SpecialComment, - original_comment_text: &str, - original_comment_text_range: TextRange, + comment_text: &str, + comment_range: TextRange, + hint_range: TextRange, ) { - let Some(formatted_comment_text) = comment.formatted() else { + let Some(formatted) = comment.formatted() else { return; }; - if original_comment_text == formatted_comment_text { + if comment_text == formatted { return; } - let edit = Edit::range_replacement(formatted_comment_text, original_comment_text_range); + let edit = Edit::range_replacement(formatted, comment_range); let fix = Fix::safe_edit(edit); let violation = UnformattedSpecialComment(comment); - let diagnostic = Diagnostic::new(violation, original_comment_text_range).with_fix(fix); + let diagnostic = Diagnostic::new(violation, hint_range).with_fix(fix); diagnostics.push(diagnostic); } @@ -148,21 +151,26 @@ macro_rules! try_parse_common { ($pattern:ident, $text:ident, $special_comment:expr) => {{ let result = $pattern.captures($text)?; - let end_index = result.get(0).unwrap().end(); - let rest = result.name("rest").unwrap().as_str().to_owned(); + let comment = result.get(0).unwrap(); + let hint = result.name("hint").unwrap(); + let rest = result.name("rest").unwrap(); - Some((end_index, $special_comment(rest))) + Some(( + hint.range(), + comment.as_str(), + $special_comment(rest.as_str().to_owned()), + )) }}; } -fn try_parse_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { +fn try_parse_noqa(text: &str) -> SpecialCommentDescriptor { // ruff_linter::noqa::Directive::try_extract static PATTERN: LazyLock = LazyLock::new(|| { Regex::new( r"(?x) ^ \#\s* - (?i:noqa) + (?(?i:noqa)) (?: :\s* (? @@ -170,7 +178,6 @@ fn try_parse_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { (?:[\s,]+[A-Z]+[A-Za-z0-9]+)* )? )? - $ ", ) .unwrap() @@ -178,15 +185,16 @@ fn try_parse_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { let result = PATTERN.captures(text)?; - let end_index = result.get(0).unwrap().end(); + let comment = result.get(0).unwrap(); + let hint = result.name("hint").unwrap(); let codes = result .name("code_list") .map(|it| parse_code_list(it.as_str())); - Some((end_index, SpecialComment::Noqa(codes))) + Some((hint.range(), comment.as_str(), SpecialComment::Noqa(codes))) } -fn try_parse_file_level_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { +fn try_parse_file_level_noqa(text: &str) -> SpecialCommentDescriptor { // ruff_linter::noqa::ParsedFileExemption::try_extract static PATTERN: LazyLock = LazyLock::new(|| { Regex::new( @@ -203,7 +211,6 @@ fn try_parse_file_level_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { )? \s* )? - $ ", ) .unwrap() @@ -211,87 +218,110 @@ fn try_parse_file_level_noqa(text: &str) -> Option<(EndIndex, SpecialComment)> { let result = PATTERN.captures(text)?; - let end_index = result.get(0).unwrap().end(); - let hint = result.name("hint").unwrap().as_str().to_owned(); + let comment = result.get(0).unwrap(); + let hint = result.name("hint").unwrap(); let codes = result .name("code_list") .map(|it| parse_code_list(it.as_str())); - Some((end_index, SpecialComment::FileLevelNoqa { hint, codes })) + let special_comment = SpecialComment::FileLevelNoqa { + hint: hint.as_str().to_owned(), + codes, + }; + + Some((hint.range(), comment.as_str(), special_comment)) } -fn try_parse_fmt(text: &str) -> Option<(EndIndex, SpecialComment)> { +fn try_parse_fmt(text: &str) -> SpecialCommentDescriptor { static PATTERN: LazyLock = - LazyLock::new(|| Regex::new(r"^#\s*fmt:\s*(?on|off|skip)").unwrap()); + LazyLock::new(|| Regex::new(r"^#\s*(?fmt):\s*(?on|off|skip)").unwrap()); try_parse_common!(PATTERN, text, SpecialComment::Fmt) } -fn try_parse_isort(text: &str) -> Option<(EndIndex, SpecialComment)> { +fn try_parse_isort(text: &str) -> SpecialCommentDescriptor { static PATTERN: LazyLock = - LazyLock::new(|| Regex::new(r"^# isort:(?skip_file|skip)").unwrap()); + LazyLock::new(|| Regex::new(r"^# (?isort):(?skip_file|skip)").unwrap()); try_parse_common!(PATTERN, text, SpecialComment::Isort) } -fn try_parse_mypy(text: &str) -> Option<(EndIndex, SpecialComment)> { +fn try_parse_mypy(text: &str) -> SpecialCommentDescriptor { // https://github.com/python/mypy/blob/3b00002acd/mypy/util.py#L228 static PATTERN: LazyLock = - LazyLock::new(|| Regex::new(r"^# mypy:\s*(?\S+)").unwrap()); + LazyLock::new(|| Regex::new(r"^# (?mypy):\s*(?\S)").unwrap()); try_parse_common!(PATTERN, text, SpecialComment::Mypy) } -fn try_parse_nopycln(text: &str) -> Option<(EndIndex, SpecialComment)> { +fn try_parse_nopycln(text: &str) -> SpecialCommentDescriptor { // https://github.com/hadialqattan/pycln/blob/d0aeb62860/pycln/utils/regexu.py#L18-L19 // https://github.com/hadialqattan/pycln/blob/d0aeb62860/pycln/utils/regexu.py#L127 // https://github.com/hadialqattan/pycln/blob/d0aeb62860/pycln/utils/regexu.py#L136 - static PATTERN: LazyLock = - LazyLock::new(|| Regex::new(r"(?i)^#\s*nopycln\s*:\s*(?file|import)").unwrap()); + static PATTERN: LazyLock = LazyLock::new(|| { + Regex::new(r"(?i)^#\s*(?nopycln)\s*:\s*(?file|import)").unwrap() + }); try_parse_common!(PATTERN, text, SpecialComment::Nopycln) } -fn try_parse_pyright(text: &str) -> Option<(EndIndex, SpecialComment)> { +fn try_parse_pyright(text: &str) -> SpecialCommentDescriptor { // https://github.com/microsoft/pyright/blob/9d60c434c4/packages/pyright-internal/src/parser/tokenizer.ts#L1314 // https://github.com/microsoft/pyright/blob/9d60c434c4/packages/pyright-internal/src/analyzer/commentUtils.ts#L138 static PATTERN: LazyLock = - LazyLock::new(|| Regex::new(r"^#\s*pyright:\s*(?\S+)").unwrap()); + LazyLock::new(|| Regex::new(r"^#\s*(?pyright):\s*(?\S)").unwrap()); try_parse_common!(PATTERN, text, SpecialComment::Pyright) } -fn try_parse_ruff_isort(text: &str) -> Option<(EndIndex, SpecialComment)> { +fn try_parse_ruff_isort(text: &str) -> SpecialCommentDescriptor { // ruff_linter::directives::extract_isort_directives static PATTERN: LazyLock = - LazyLock::new(|| Regex::new(r"^# ruff: isort: ?(?skip_file|skip)").unwrap()); + LazyLock::new(|| Regex::new(r"^# (?ruff): isort: ?(?skip_file|skip)").unwrap()); try_parse_common!(PATTERN, text, SpecialComment::RuffIsort) } -fn try_parse_type(text: &str) -> Option<(EndIndex, SpecialComment)> { +fn try_parse_type(text: &str) -> SpecialCommentDescriptor { // https://github.com/python/cpython/blob/c222441fa7/Parser/lexer/lexer.c#L45-L47 static PATTERN: LazyLock = - LazyLock::new(|| Regex::new(r"^#\s*type:\s*(?\S+)").unwrap()); + LazyLock::new(|| Regex::new(r"^#\s*(?type):\s*(?\S)").unwrap()); try_parse_common!(PATTERN, text, SpecialComment::Type) } -macro_rules! parse_and_handle_comment { - ($parse:ident, $text:ident, $diagnostics:ident, $absolute_start_index:ident) => { - if let Some((relative_end_index, comment)) = $parse($text) { - let comment_text = &$text[..relative_end_index]; - let absolute_end_index = $absolute_start_index + relative_end_index; +fn text_range(start: usize, end: usize) -> Option { + let Ok(start) = TextSize::try_from(start) else { + return None; + }; + let Ok(end) = TextSize::try_from(end) else { + return None; + }; + + Some(TextRange::new(start, end)) +} - let Ok(start) = TryInto::::try_into($absolute_start_index) else { +macro_rules! parse_and_handle_comment { + ($parse:ident, $text:ident, $diagnostics:ident, $comment_start:ident) => { + if let Some((hint_relative_range, comment_text, comment)) = $parse($text) { + let comment_end = $comment_start + comment_text.len(); + let Some(comment_range) = text_range($comment_start, comment_end) else { return; }; - let Ok(end) = TryInto::::try_into(absolute_end_index) else { + + let hint_start = $comment_start + hint_relative_range.start; + let hint_end = $comment_start + hint_relative_range.end; + let Some(hint_range) = text_range(hint_start, hint_end) else { return; }; - let range = TextRange::new(start, end); - add_diagnostic_if_applicable($diagnostics, comment, comment_text, range); + add_diagnostic_if_applicable( + $diagnostics, + comment, + comment_text, + comment_range, + hint_range, + ); return; } }; @@ -313,13 +343,11 @@ fn check_composite_comment(diagnostics: &mut Vec, text: &str, range_ for (char_index, char) in text.char_indices() { let next_char = text[char_index..].chars().nth(1); - if char != '#' || matches!(next_char, Some('#')) { - continue; - } - - let absolute_start_index = range_start + char_index; + if char == '#' && !matches!(next_char, Some('#')) { + let subcomment_absolute_index = range_start + char_index; - check_single_comment(diagnostics, &text[char_index..], absolute_start_index); + check_single_comment(diagnostics, &text[char_index..], subcomment_absolute_index); + } } } @@ -343,7 +371,7 @@ mod tests { use super::{check_composite_comment, check_single_comment}; - fn test_single(text: &str) -> Vec { + fn check_single(text: &str) -> Vec { let mut diagnostics = vec![]; let start_index = 0; @@ -352,7 +380,7 @@ mod tests { diagnostics } - fn test_composite(text: &str) -> Vec { + fn check_composite(text: &str) -> Vec { let mut diagnostics = vec![]; let start_index = 0; @@ -362,21 +390,21 @@ mod tests { } fn has_unformatted(text: &str) { - let diagnostics = test_single(text); + let diagnostics = check_single(text); assert_eq!(diagnostics.len(), 1); } - fn composite_has_unformatted(text: &str, count: usize) { - let diagnostics = test_composite(text); + fn no_unformatted(text: &str) { + let diagnostics = check_single(text); - assert_eq!(diagnostics.len(), count); + assert!(diagnostics.is_empty()); } - fn no_unformatted(text: &str) { - let diagnostics = test_single(text); + fn composite_has_unformatted(text: &str, count: usize) { + let diagnostics = check_composite(text); - assert!(diagnostics.is_empty()); + assert_eq!(diagnostics.len(), count); } fn composite_no_unformatted(text: &str) { @@ -512,7 +540,8 @@ mod tests { fn composite() { composite_no_unformatted("# type: ignore # noqa: A123, B456"); - composite_has_unformatted("#pyright:ignore# noqa:A123", 2); + composite_has_unformatted("#pyright:ignore#noqa:A123", 2); + composite_has_unformatted("# nopycln:file# noqa: A123", 2); composite_has_unformatted("# noqa:A123 - Lorem ipsum dolor sit amet", 1); } } From 66f77d22bf0ff0db1fdec90517f4474d5a8ab862 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Sun, 10 Nov 2024 08:12:10 +0000 Subject: [PATCH 14/29] Move `RUF014.py` to `preview_rules` --- crates/ruff_linter/src/rules/ruff/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ruff_linter/src/rules/ruff/mod.rs b/crates/ruff_linter/src/rules/ruff/mod.rs index f0c6dfc353b428..f729384ab39fc4 100644 --- a/crates/ruff_linter/src/rules/ruff/mod.rs +++ b/crates/ruff_linter/src/rules/ruff/mod.rs @@ -61,7 +61,6 @@ mod tests { #[test_case(Rule::PostInitDefault, Path::new("RUF033.py"))] #[test_case(Rule::UselessIfElse, Path::new("RUF034.py"))] #[test_case(Rule::RedirectedNOQA, Path::new("RUF101.py"))] - #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104.py"))] fn rules(rule_code: Rule, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( @@ -385,6 +384,7 @@ mod tests { } #[test_case(Rule::ZipInsteadOfPairwise, Path::new("RUF007.py"))] + #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104.py"))] fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> { let snapshot = format!( "preview__{}_{}", From 60e9da3fc61c44207b4ecfdf5bb33faf4aa0b994 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Sun, 10 Nov 2024 09:12:55 +0000 Subject: [PATCH 15/29] Update snapshots --- ...nter__rules__ruff__tests__preview__RUF104_RUF104.py.snap.new} | 1 + 1 file changed, 1 insertion(+) rename crates/ruff_linter/src/rules/ruff/snapshots/{ruff_linter__rules__ruff__tests__RUF104_RUF104.py.snap => ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap.new} (79%) diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF104_RUF104.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap.new similarity index 79% rename from crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF104_RUF104.py.snap rename to crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap.new index b3a37c09211090..182f6a06eb80f2 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF104_RUF104.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap.new @@ -1,5 +1,6 @@ --- source: crates/ruff_linter/src/rules/ruff/mod.rs +assertion_line: 401 snapshot_kind: text --- From 1d9c9dfe99219b5bfceeead7c9c6845c3f0d4e24 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Sun, 10 Nov 2024 10:06:53 +0000 Subject: [PATCH 16/29] Oops --- .../resources/test/fixtures/ruff/RUF104.py | 2 - ...uff__tests__preview__RUF104_RUF104.py.snap | 891 ++++++++++++++++++ ..._tests__preview__RUF104_RUF104.py.snap.new | 6 - 3 files changed, 891 insertions(+), 8 deletions(-) create mode 100644 crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap delete mode 100644 crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap.new diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py index 12eec796e6e606..a7242d55d175bf 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py @@ -13,10 +13,8 @@ # noqa # noqa: A123 # noqa: A123, B456 -# ruff: noqa # ruff: noqa: A123 # ruff: noqa: A123, B456 -# flake8: noqa # flake8: noqa: A123 # flake8: noqa: A123, B456 # fmt: on diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap new file mode 100644 index 00000000000000..64db032864dda8 --- /dev/null +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap @@ -0,0 +1,891 @@ +--- +source: crates/ruff_linter/src/rules/ruff/mod.rs +snapshot_kind: text +--- +RUF104.py:42:3: RUF104 [*] Unformatted special comment + | +40 | # type: list[str] +41 | +42 | # noqa:A123 + | ^^^^ RUF104 +43 | #noqa: A123 +44 | # type:ignore + | + = help: Format comment + +ℹ Safe fix +39 39 | # type: int +40 40 | # type: list[str] +41 41 | +42 |-# noqa:A123 + 42 |+# noqa: A123 +43 43 | #noqa: A123 +44 44 | # type:ignore +45 45 | #type: int + +RUF104.py:43:2: RUF104 [*] Unformatted special comment + | +42 | # noqa:A123 +43 | #noqa: A123 + | ^^^^ RUF104 +44 | # type:ignore +45 | #type: int + | + = help: Format comment + +ℹ Safe fix +40 40 | # type: list[str] +41 41 | +42 42 | # noqa:A123 +43 |-#noqa: A123 + 43 |+# noqa: A123 +44 44 | # type:ignore +45 45 | #type: int +46 46 | # fmt:off + +RUF104.py:44:6: RUF104 [*] Unformatted special comment + | +42 | # noqa:A123 +43 | #noqa: A123 +44 | # type:ignore + | ^^^^ RUF104 +45 | #type: int +46 | # fmt:off + | + = help: Format comment + +ℹ Safe fix +41 41 | +42 42 | # noqa:A123 +43 43 | #noqa: A123 +44 |-# type:ignore + 44 |+# type: ignore +45 45 | #type: int +46 46 | # fmt:off +47 47 | #fmt: on + +RUF104.py:45:2: RUF104 [*] Unformatted special comment + | +43 | #noqa: A123 +44 | # type:ignore +45 | #type: int + | ^^^^ RUF104 +46 | # fmt:off +47 | #fmt: on + | + = help: Format comment + +ℹ Safe fix +42 42 | # noqa:A123 +43 43 | #noqa: A123 +44 44 | # type:ignore +45 |-#type: int + 45 |+# type: int +46 46 | # fmt:off +47 47 | #fmt: on +48 48 | # fmt: skip + +RUF104.py:46:3: RUF104 [*] Unformatted special comment + | +44 | # type:ignore +45 | #type: int +46 | # fmt:off + | ^^^ RUF104 +47 | #fmt: on +48 | # fmt: skip + | + = help: Format comment + +ℹ Safe fix +43 43 | #noqa: A123 +44 44 | # type:ignore +45 45 | #type: int +46 |-# fmt:off + 46 |+# fmt: off +47 47 | #fmt: on +48 48 | # fmt: skip +49 49 | # isort:skip + +RUF104.py:47:2: RUF104 [*] Unformatted special comment + | +45 | #type: int +46 | # fmt:off +47 | #fmt: on + | ^^^ RUF104 +48 | # fmt: skip +49 | # isort:skip + | + = help: Format comment + +ℹ Safe fix +44 44 | # type:ignore +45 45 | #type: int +46 46 | # fmt:off +47 |-#fmt: on + 47 |+# fmt: on +48 48 | # fmt: skip +49 49 | # isort:skip +50 50 | # isort:skip_file + +RUF104.py:48:5: RUF104 [*] Unformatted special comment + | +46 | # fmt:off +47 | #fmt: on +48 | # fmt: skip + | ^^^ RUF104 +49 | # isort:skip +50 | # isort:skip_file + | + = help: Format comment + +ℹ Safe fix +45 45 | #type: int +46 46 | # fmt:off +47 47 | #fmt: on +48 |-# fmt: skip + 48 |+# fmt: skip +49 49 | # isort:skip +50 50 | # isort:skip_file +51 51 | # mypy: disallow-subclassing-any + +RUF104.py:49:3: RUF104 [*] Unformatted special comment + | +47 | #fmt: on +48 | # fmt: skip +49 | # isort:skip + | ^^^^^ RUF104 +50 | # isort:skip_file +51 | # mypy: disallow-subclassing-any + | + = help: Format comment + +ℹ Safe fix +46 46 | # fmt:off +47 47 | #fmt: on +48 48 | # fmt: skip +49 |-# isort:skip + 49 |+# isort: skip +50 50 | # isort:skip_file +51 51 | # mypy: disallow-subclassing-any +52 52 | # nopycln: file + +RUF104.py:50:3: RUF104 [*] Unformatted special comment + | +48 | # fmt: skip +49 | # isort:skip +50 | # isort:skip_file + | ^^^^^ RUF104 +51 | # mypy: disallow-subclassing-any +52 | # nopycln: file + | + = help: Format comment + +ℹ Safe fix +47 47 | #fmt: on +48 48 | # fmt: skip +49 49 | # isort:skip +50 |-# isort:skip_file + 50 |+# isort: skip_file +51 51 | # mypy: disallow-subclassing-any +52 52 | # nopycln: file +53 53 | # nopycln: import + +RUF104.py:51:3: RUF104 [*] Unformatted special comment + | +49 | # isort:skip +50 | # isort:skip_file +51 | # mypy: disallow-subclassing-any + | ^^^^ RUF104 +52 | # nopycln: file +53 | # nopycln: import + | + = help: Format comment + +ℹ Safe fix +48 48 | # fmt: skip +49 49 | # isort:skip +50 50 | # isort:skip_file +51 |-# mypy: disallow-subclassing-any + 51 |+# mypy: disallow-subclassing-any +52 52 | # nopycln: file +53 53 | # nopycln: import +54 54 | #pyright:ignore[] + +RUF104.py:52:5: RUF104 [*] Unformatted special comment + | +50 | # isort:skip_file +51 | # mypy: disallow-subclassing-any +52 | # nopycln: file + | ^^^^^^^ RUF104 +53 | # nopycln: import +54 | #pyright:ignore[] + | + = help: Format comment + +ℹ Safe fix +49 49 | # isort:skip +50 50 | # isort:skip_file +51 51 | # mypy: disallow-subclassing-any +52 |-# nopycln: file + 52 |+# nopycln: file +53 53 | # nopycln: import +54 54 | #pyright:ignore[] +55 55 | # pyright: ignore[] + +RUF104.py:53:4: RUF104 [*] Unformatted special comment + | +51 | # mypy: disallow-subclassing-any +52 | # nopycln: file +53 | # nopycln: import + | ^^^^^^^ RUF104 +54 | #pyright:ignore[] +55 | # pyright: ignore[] + | + = help: Format comment + +ℹ Safe fix +50 50 | # isort:skip_file +51 51 | # mypy: disallow-subclassing-any +52 52 | # nopycln: file +53 |-# nopycln: import + 53 |+# nopycln: import +54 54 | #pyright:ignore[] +55 55 | # pyright: ignore[] +56 56 | # ruff: isort:skip + +RUF104.py:54:2: RUF104 [*] Unformatted special comment + | +52 | # nopycln: file +53 | # nopycln: import +54 | #pyright:ignore[] + | ^^^^^^^ RUF104 +55 | # pyright: ignore[] +56 | # ruff: isort:skip + | + = help: Format comment + +ℹ Safe fix +51 51 | # mypy: disallow-subclassing-any +52 52 | # nopycln: file +53 53 | # nopycln: import +54 |-#pyright:ignore[] + 54 |+# pyright: ignore[] +55 55 | # pyright: ignore[] +56 56 | # ruff: isort:skip +57 57 | # ruff: isort:skip_file + +RUF104.py:55:5: RUF104 [*] Unformatted special comment + | +53 | # nopycln: import +54 | #pyright:ignore[] +55 | # pyright: ignore[] + | ^^^^^^^ RUF104 +56 | # ruff: isort:skip +57 | # ruff: isort:skip_file + | + = help: Format comment + +ℹ Safe fix +52 52 | # nopycln: file +53 53 | # nopycln: import +54 54 | #pyright:ignore[] +55 |-# pyright: ignore[] + 55 |+# pyright: ignore[] +56 56 | # ruff: isort:skip +57 57 | # ruff: isort:skip_file +58 58 | # type: ignore + +RUF104.py:56:3: RUF104 [*] Unformatted special comment + | +54 | #pyright:ignore[] +55 | # pyright: ignore[] +56 | # ruff: isort:skip + | ^^^^ RUF104 +57 | # ruff: isort:skip_file +58 | # type: ignore + | + = help: Format comment + +ℹ Safe fix +53 53 | # nopycln: import +54 54 | #pyright:ignore[] +55 55 | # pyright: ignore[] +56 |-# ruff: isort:skip + 56 |+# ruff: isort: skip +57 57 | # ruff: isort:skip_file +58 58 | # type: ignore +59 59 | # type: int + +RUF104.py:57:3: RUF104 [*] Unformatted special comment + | +55 | # pyright: ignore[] +56 | # ruff: isort:skip +57 | # ruff: isort:skip_file + | ^^^^ RUF104 +58 | # type: ignore +59 | # type: int + | + = help: Format comment + +ℹ Safe fix +54 54 | #pyright:ignore[] +55 55 | # pyright: ignore[] +56 56 | # ruff: isort:skip +57 |-# ruff: isort:skip_file + 57 |+# ruff: isort: skip_file +58 58 | # type: ignore +59 59 | # type: int +60 60 | + +RUF104.py:58:6: RUF104 [*] Unformatted special comment + | +56 | # ruff: isort:skip +57 | # ruff: isort:skip_file +58 | # type: ignore + | ^^^^ RUF104 +59 | # type: int + | + = help: Format comment + +ℹ Safe fix +55 55 | # pyright: ignore[] +56 56 | # ruff: isort:skip +57 57 | # ruff: isort:skip_file +58 |-# type: ignore + 58 |+# type: ignore +59 59 | # type: int +60 60 | +61 61 | # NoQA: A123, B456 + +RUF104.py:59:7: RUF104 [*] Unformatted special comment + | +57 | # ruff: isort:skip_file +58 | # type: ignore +59 | # type: int + | ^^^^ RUF104 +60 | +61 | # NoQA: A123, B456 + | + = help: Format comment + +ℹ Safe fix +56 56 | # ruff: isort:skip +57 57 | # ruff: isort:skip_file +58 58 | # type: ignore +59 |-# type: int + 59 |+# type: int +60 60 | +61 61 | # NoQA: A123, B456 +62 62 | # ruff: NoQA: A123, B456 + +RUF104.py:61:3: RUF104 [*] Unformatted special comment + | +59 | # type: int +60 | +61 | # NoQA: A123, B456 + | ^^^^ RUF104 +62 | # ruff: NoQA: A123, B456 +63 | # flake8: NoQA: A123, B456 + | + = help: Format comment + +ℹ Safe fix +58 58 | # type: ignore +59 59 | # type: int +60 60 | +61 |-# NoQA: A123, B456 + 61 |+# noqa: A123, B456 +62 62 | # ruff: NoQA: A123, B456 +63 63 | # flake8: NoQA: A123, B456 +64 64 | # NoPyCLN: File + +RUF104.py:62:3: RUF104 [*] Unformatted special comment + | +61 | # NoQA: A123, B456 +62 | # ruff: NoQA: A123, B456 + | ^^^^ RUF104 +63 | # flake8: NoQA: A123, B456 +64 | # NoPyCLN: File + | + = help: Format comment + +ℹ Safe fix +59 59 | # type: int +60 60 | +61 61 | # NoQA: A123, B456 +62 |-# ruff: NoQA: A123, B456 + 62 |+# ruff: noqa: A123, B456 +63 63 | # flake8: NoQA: A123, B456 +64 64 | # NoPyCLN: File +65 65 | # NoPycln: Import + +RUF104.py:63:3: RUF104 [*] Unformatted special comment + | +61 | # NoQA: A123, B456 +62 | # ruff: NoQA: A123, B456 +63 | # flake8: NoQA: A123, B456 + | ^^^^^^ RUF104 +64 | # NoPyCLN: File +65 | # NoPycln: Import + | + = help: Format comment + +ℹ Safe fix +60 60 | +61 61 | # NoQA: A123, B456 +62 62 | # ruff: NoQA: A123, B456 +63 |-# flake8: NoQA: A123, B456 + 63 |+# flake8: noqa: A123, B456 +64 64 | # NoPyCLN: File +65 65 | # NoPycln: Import +66 66 | # nOpYcLn: iMpOrT + +RUF104.py:64:3: RUF104 [*] Unformatted special comment + | +62 | # ruff: NoQA: A123, B456 +63 | # flake8: NoQA: A123, B456 +64 | # NoPyCLN: File + | ^^^^^^^ RUF104 +65 | # NoPycln: Import +66 | # nOpYcLn: iMpOrT + | + = help: Format comment + +ℹ Safe fix +61 61 | # NoQA: A123, B456 +62 62 | # ruff: NoQA: A123, B456 +63 63 | # flake8: NoQA: A123, B456 +64 |-# NoPyCLN: File + 64 |+# nopycln: file +65 65 | # NoPycln: Import +66 66 | # nOpYcLn: iMpOrT +67 67 | + +RUF104.py:65:3: RUF104 [*] Unformatted special comment + | +63 | # flake8: NoQA: A123, B456 +64 | # NoPyCLN: File +65 | # NoPycln: Import + | ^^^^^^^ RUF104 +66 | # nOpYcLn: iMpOrT + | + = help: Format comment + +ℹ Safe fix +62 62 | # ruff: NoQA: A123, B456 +63 63 | # flake8: NoQA: A123, B456 +64 64 | # NoPyCLN: File +65 |-# NoPycln: Import + 65 |+# nopycln: import +66 66 | # nOpYcLn: iMpOrT +67 67 | +68 68 | # noqa: A123 B456 + +RUF104.py:66:3: RUF104 [*] Unformatted special comment + | +64 | # NoPyCLN: File +65 | # NoPycln: Import +66 | # nOpYcLn: iMpOrT + | ^^^^^^^ RUF104 +67 | +68 | # noqa: A123 B456 + | + = help: Format comment + +ℹ Safe fix +63 63 | # flake8: NoQA: A123, B456 +64 64 | # NoPyCLN: File +65 65 | # NoPycln: Import +66 |-# nOpYcLn: iMpOrT + 66 |+# nopycln: import +67 67 | +68 68 | # noqa: A123 B456 +69 69 | # ruff: noqa: A123 B456 + +RUF104.py:68:3: RUF104 [*] Unformatted special comment + | +66 | # nOpYcLn: iMpOrT +67 | +68 | # noqa: A123 B456 + | ^^^^ RUF104 +69 | # ruff: noqa: A123 B456 +70 | # flake8: noqa: A123 B456 + | + = help: Format comment + +ℹ Safe fix +65 65 | # NoPycln: Import +66 66 | # nOpYcLn: iMpOrT +67 67 | +68 |-# noqa: A123 B456 + 68 |+# noqa: A123, B456 +69 69 | # ruff: noqa: A123 B456 +70 70 | # flake8: noqa: A123 B456 +71 71 | # noqa: A123,B456 + +RUF104.py:69:3: RUF104 [*] Unformatted special comment + | +68 | # noqa: A123 B456 +69 | # ruff: noqa: A123 B456 + | ^^^^ RUF104 +70 | # flake8: noqa: A123 B456 +71 | # noqa: A123,B456 + | + = help: Format comment + +ℹ Safe fix +66 66 | # nOpYcLn: iMpOrT +67 67 | +68 68 | # noqa: A123 B456 +69 |-# ruff: noqa: A123 B456 + 69 |+# ruff: noqa: A123, B456 +70 70 | # flake8: noqa: A123 B456 +71 71 | # noqa: A123,B456 +72 72 | # ruff: noqa: A123,B456 + +RUF104.py:70:3: RUF104 [*] Unformatted special comment + | +68 | # noqa: A123 B456 +69 | # ruff: noqa: A123 B456 +70 | # flake8: noqa: A123 B456 + | ^^^^^^ RUF104 +71 | # noqa: A123,B456 +72 | # ruff: noqa: A123,B456 + | + = help: Format comment + +ℹ Safe fix +67 67 | +68 68 | # noqa: A123 B456 +69 69 | # ruff: noqa: A123 B456 +70 |-# flake8: noqa: A123 B456 + 70 |+# flake8: noqa: A123, B456 +71 71 | # noqa: A123,B456 +72 72 | # ruff: noqa: A123,B456 +73 73 | # flake8: noqa: A123,B456 + +RUF104.py:71:3: RUF104 [*] Unformatted special comment + | +69 | # ruff: noqa: A123 B456 +70 | # flake8: noqa: A123 B456 +71 | # noqa: A123,B456 + | ^^^^ RUF104 +72 | # ruff: noqa: A123,B456 +73 | # flake8: noqa: A123,B456 + | + = help: Format comment + +ℹ Safe fix +68 68 | # noqa: A123 B456 +69 69 | # ruff: noqa: A123 B456 +70 70 | # flake8: noqa: A123 B456 +71 |-# noqa: A123,B456 + 71 |+# noqa: A123, B456 +72 72 | # ruff: noqa: A123,B456 +73 73 | # flake8: noqa: A123,B456 +74 74 | # noqa: A123,,B456 + +RUF104.py:72:3: RUF104 [*] Unformatted special comment + | +70 | # flake8: noqa: A123 B456 +71 | # noqa: A123,B456 +72 | # ruff: noqa: A123,B456 + | ^^^^ RUF104 +73 | # flake8: noqa: A123,B456 +74 | # noqa: A123,,B456 + | + = help: Format comment + +ℹ Safe fix +69 69 | # ruff: noqa: A123 B456 +70 70 | # flake8: noqa: A123 B456 +71 71 | # noqa: A123,B456 +72 |-# ruff: noqa: A123,B456 + 72 |+# ruff: noqa: A123, B456 +73 73 | # flake8: noqa: A123,B456 +74 74 | # noqa: A123,,B456 +75 75 | # noqa: A123 , , B456 + +RUF104.py:73:3: RUF104 [*] Unformatted special comment + | +71 | # noqa: A123,B456 +72 | # ruff: noqa: A123,B456 +73 | # flake8: noqa: A123,B456 + | ^^^^^^ RUF104 +74 | # noqa: A123,,B456 +75 | # noqa: A123 , , B456 + | + = help: Format comment + +ℹ Safe fix +70 70 | # flake8: noqa: A123 B456 +71 71 | # noqa: A123,B456 +72 72 | # ruff: noqa: A123,B456 +73 |-# flake8: noqa: A123,B456 + 73 |+# flake8: noqa: A123, B456 +74 74 | # noqa: A123,,B456 +75 75 | # noqa: A123 , , B456 +76 76 | # noqa: A123 B456 + +RUF104.py:74:3: RUF104 [*] Unformatted special comment + | +72 | # ruff: noqa: A123,B456 +73 | # flake8: noqa: A123,B456 +74 | # noqa: A123,,B456 + | ^^^^ RUF104 +75 | # noqa: A123 , , B456 +76 | # noqa: A123 B456 + | + = help: Format comment + +ℹ Safe fix +71 71 | # noqa: A123,B456 +72 72 | # ruff: noqa: A123,B456 +73 73 | # flake8: noqa: A123,B456 +74 |-# noqa: A123,,B456 + 74 |+# noqa: A123, B456 +75 75 | # noqa: A123 , , B456 +76 76 | # noqa: A123 B456 +77 77 | # noqa: A123 B456 + +RUF104.py:75:3: RUF104 [*] Unformatted special comment + | +73 | # flake8: noqa: A123,B456 +74 | # noqa: A123,,B456 +75 | # noqa: A123 , , B456 + | ^^^^ RUF104 +76 | # noqa: A123 B456 +77 | # noqa: A123 B456 + | + = help: Format comment + +ℹ Safe fix +72 72 | # ruff: noqa: A123,B456 +73 73 | # flake8: noqa: A123,B456 +74 74 | # noqa: A123,,B456 +75 |-# noqa: A123 , , B456 + 75 |+# noqa: A123, B456 +76 76 | # noqa: A123 B456 +77 77 | # noqa: A123 B456 +78 78 | # noqa: A123 B456 + +RUF104.py:76:3: RUF104 [*] Unformatted special comment + | +74 | # noqa: A123,,B456 +75 | # noqa: A123 , , B456 +76 | # noqa: A123 B456 + | ^^^^ RUF104 +77 | # noqa: A123 B456 +78 | # noqa: A123 B456 + | + = help: Format comment + +ℹ Safe fix +73 73 | # flake8: noqa: A123,B456 +74 74 | # noqa: A123,,B456 +75 75 | # noqa: A123 , , B456 +76 |-# noqa: A123 B456 + 76 |+# noqa: A123, B456 +77 77 | # noqa: A123 B456 +78 78 | # noqa: A123 B456 +79 79 | # noqa: A123 ,B456 + +RUF104.py:77:3: RUF104 [*] Unformatted special comment + | +75 | # noqa: A123 , , B456 +76 | # noqa: A123 B456 +77 | # noqa: A123 B456 + | ^^^^ RUF104 +78 | # noqa: A123 B456 +79 | # noqa: A123 ,B456 + | + = help: Format comment + +ℹ Safe fix +74 74 | # noqa: A123,,B456 +75 75 | # noqa: A123 , , B456 +76 76 | # noqa: A123 B456 +77 |-# noqa: A123 B456 + 77 |+# noqa: A123, B456 +78 78 | # noqa: A123 B456 +79 79 | # noqa: A123 ,B456 +80 80 | # ruff: noqa: A123 B456 + +RUF104.py:78:3: RUF104 [*] Unformatted special comment + | +76 | # noqa: A123 B456 +77 | # noqa: A123 B456 +78 | # noqa: A123 B456 + | ^^^^ RUF104 +79 | # noqa: A123 ,B456 +80 | # ruff: noqa: A123 B456 + | + = help: Format comment + +ℹ Safe fix +75 75 | # noqa: A123 , , B456 +76 76 | # noqa: A123 B456 +77 77 | # noqa: A123 B456 +78 |-# noqa: A123 B456 + 78 |+# noqa: A123, B456 +79 79 | # noqa: A123 ,B456 +80 80 | # ruff: noqa: A123 B456 +81 81 | # flake8: noqa: A123 B456 + +RUF104.py:79:3: RUF104 [*] Unformatted special comment + | +77 | # noqa: A123 B456 +78 | # noqa: A123 B456 +79 | # noqa: A123 ,B456 + | ^^^^ RUF104 +80 | # ruff: noqa: A123 B456 +81 | # flake8: noqa: A123 B456 + | + = help: Format comment + +ℹ Safe fix +76 76 | # noqa: A123 B456 +77 77 | # noqa: A123 B456 +78 78 | # noqa: A123 B456 +79 |-# noqa: A123 ,B456 + 79 |+# noqa: A123, B456 +80 80 | # ruff: noqa: A123 B456 +81 81 | # flake8: noqa: A123 B456 +82 82 | + +RUF104.py:80:3: RUF104 [*] Unformatted special comment + | +78 | # noqa: A123 B456 +79 | # noqa: A123 ,B456 +80 | # ruff: noqa: A123 B456 + | ^^^^ RUF104 +81 | # flake8: noqa: A123 B456 + | + = help: Format comment + +ℹ Safe fix +77 77 | # noqa: A123 B456 +78 78 | # noqa: A123 B456 +79 79 | # noqa: A123 ,B456 +80 |-# ruff: noqa: A123 B456 + 80 |+# ruff: noqa: A123, B456 +81 81 | # flake8: noqa: A123 B456 +82 82 | +83 83 | + +RUF104.py:81:3: RUF104 [*] Unformatted special comment + | +79 | # noqa: A123 ,B456 +80 | # ruff: noqa: A123 B456 +81 | # flake8: noqa: A123 B456 + | ^^^^^^ RUF104 + | + = help: Format comment + +ℹ Safe fix +78 78 | # noqa: A123 B456 +79 79 | # noqa: A123 ,B456 +80 80 | # ruff: noqa: A123 B456 +81 |-# flake8: noqa: A123 B456 + 81 |+# flake8: noqa: A123, B456 +82 82 | +83 83 | +84 84 | # type: ignore # noqa: A123, B456 + +RUF104.py:86:2: RUF104 [*] Unformatted special comment + | +84 | # type: ignore # noqa: A123, B456 +85 | +86 | #pyright:ignore#noqa:A123 + | ^^^^^^^ RUF104 +87 | +88 | # nopycln:file# noqa: A123 + | + = help: Format comment + +ℹ Safe fix +83 83 | +84 84 | # type: ignore # noqa: A123, B456 +85 85 | +86 |-#pyright:ignore#noqa:A123 + 86 |+# pyright: ignore#noqa:A123 +87 87 | +88 88 | # nopycln:file# noqa: A123 +89 89 | + +RUF104.py:86:17: RUF104 [*] Unformatted special comment + | +84 | # type: ignore # noqa: A123, B456 +85 | +86 | #pyright:ignore#noqa:A123 + | ^^^^ RUF104 +87 | +88 | # nopycln:file# noqa: A123 + | + = help: Format comment + +ℹ Safe fix +83 83 | +84 84 | # type: ignore # noqa: A123, B456 +85 85 | +86 |-#pyright:ignore#noqa:A123 + 86 |+#pyright:ignore# noqa: A123 +87 87 | +88 88 | # nopycln:file# noqa: A123 +89 89 | + +RUF104.py:88:3: RUF104 [*] Unformatted special comment + | +86 | #pyright:ignore#noqa:A123 +87 | +88 | # nopycln:file# noqa: A123 + | ^^^^^^^ RUF104 +89 | +90 | # noqa:A123 - Lorem ipsum dolor sit amet + | + = help: Format comment + +ℹ Safe fix +85 85 | +86 86 | #pyright:ignore#noqa:A123 +87 87 | +88 |-# nopycln:file# noqa: A123 + 88 |+# nopycln: file# noqa: A123 +89 89 | +90 90 | # noqa:A123 - Lorem ipsum dolor sit amet + +RUF104.py:88:19: RUF104 [*] Unformatted special comment + | +86 | #pyright:ignore#noqa:A123 +87 | +88 | # nopycln:file# noqa: A123 + | ^^^^ RUF104 +89 | +90 | # noqa:A123 - Lorem ipsum dolor sit amet + | + = help: Format comment + +ℹ Safe fix +85 85 | +86 86 | #pyright:ignore#noqa:A123 +87 87 | +88 |-# nopycln:file# noqa: A123 + 88 |+# nopycln:file# noqa: A123 +89 89 | +90 90 | # noqa:A123 - Lorem ipsum dolor sit amet + +RUF104.py:90:3: RUF104 [*] Unformatted special comment + | +88 | # nopycln:file# noqa: A123 +89 | +90 | # noqa:A123 - Lorem ipsum dolor sit amet + | ^^^^ RUF104 + | + = help: Format comment + +ℹ Safe fix +87 87 | +88 88 | # nopycln:file# noqa: A123 +89 89 | +90 |-# noqa:A123 - Lorem ipsum dolor sit amet + 90 |+# noqa: A123 - Lorem ipsum dolor sit amet diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap.new b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap.new deleted file mode 100644 index 182f6a06eb80f2..00000000000000 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap.new +++ /dev/null @@ -1,6 +0,0 @@ ---- -source: crates/ruff_linter/src/rules/ruff/mod.rs -assertion_line: 401 -snapshot_kind: text ---- - From 0e11a3e815f36ce99458a23930a2de236b295e4d Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Sun, 10 Nov 2024 10:50:48 +0000 Subject: [PATCH 17/29] Exclude `RUF104` from implicit suppressions --- .../resources/test/fixtures/ruff/RUF104.py | 2 + .../resources/test/fixtures/ruff/RUF104_1.py | 3 + .../resources/test/fixtures/ruff/RUF104_2.py | 3 + crates/ruff_linter/src/checkers/noqa.rs | 2 +- crates/ruff_linter/src/checkers/tokens.rs | 13 +- crates/ruff_linter/src/rules/ruff/mod.rs | 2 + ...uff__tests__preview__RUF104_RUF104.py.snap | 1152 ++++++++--------- ...f__tests__preview__RUF104_RUF104_1.py.snap | 33 + ...f__tests__preview__RUF104_RUF104_2.py.snap | 5 + 9 files changed, 636 insertions(+), 579 deletions(-) create mode 100644 crates/ruff_linter/resources/test/fixtures/ruff/RUF104_1.py create mode 100644 crates/ruff_linter/resources/test/fixtures/ruff/RUF104_2.py create mode 100644 crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_1.py.snap create mode 100644 crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_2.py.snap diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py index a7242d55d175bf..12eec796e6e606 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py @@ -13,8 +13,10 @@ # noqa # noqa: A123 # noqa: A123, B456 +# ruff: noqa # ruff: noqa: A123 # ruff: noqa: A123, B456 +# flake8: noqa # flake8: noqa: A123 # flake8: noqa: A123, B456 # fmt: on diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_1.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_1.py new file mode 100644 index 00000000000000..fbbd5fc4b7d25b --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_1.py @@ -0,0 +1,3 @@ +# ruff:noqa + +#noqa:A123 diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_2.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_2.py new file mode 100644 index 00000000000000..63232eb4bbf84d --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_2.py @@ -0,0 +1,3 @@ +# flake8:noqa:RUF104 + +#noqa:A123 diff --git a/crates/ruff_linter/src/checkers/noqa.rs b/crates/ruff_linter/src/checkers/noqa.rs index a2ecc7a34161ff..f9d768c65f9135 100644 --- a/crates/ruff_linter/src/checkers/noqa.rs +++ b/crates/ruff_linter/src/checkers/noqa.rs @@ -45,7 +45,7 @@ pub(crate) fn check_noqa( // Remove any ignored diagnostics. 'outer: for (index, diagnostic) in diagnostics.iter().enumerate() { - if matches!(diagnostic.kind.rule(), Rule::BlanketNOQA) { + if matches!(diagnostic.kind.rule(), Rule::BlanketNOQA | Rule::UnformattedSpecialComment) { continue; } diff --git a/crates/ruff_linter/src/checkers/tokens.rs b/crates/ruff_linter/src/checkers/tokens.rs index ac6b63858e3755..08a3048dc4cb47 100644 --- a/crates/ruff_linter/src/checkers/tokens.rs +++ b/crates/ruff_linter/src/checkers/tokens.rs @@ -11,6 +11,7 @@ use ruff_python_parser::Tokens; use ruff_text_size::Ranged; use crate::directives::TodoComment; +use crate::noqa::{FileExemption, FileNoqaDirectives}; use crate::registry::{AsRule, Rule}; use crate::rules::pycodestyle::rules::BlankLinesChecker; use crate::rules::{ @@ -18,7 +19,7 @@ use crate::rules::{ flake8_pyi, flake8_todos, pycodestyle, pygrep_hooks, pylint, pyupgrade, ruff, }; use crate::settings::LinterSettings; -use crate::Locator; +use crate::{fs, Locator}; #[allow(clippy::too_many_arguments)] pub(crate) fn check_tokens( @@ -34,6 +35,11 @@ pub(crate) fn check_tokens( let mut diagnostics: Vec = vec![]; let comment_ranges = indexer.comment_ranges(); + let per_file_ignores = fs::ignores_from_path(path, &settings.per_file_ignores); + let file_noqa_directives = + FileNoqaDirectives::extract(locator, comment_ranges, &settings.external, path); + let exemption = FileExemption::from(&file_noqa_directives); + if settings.rules.any_enabled(&[ Rule::BlankLineBetweenMethods, Rule::BlankLinesTopLevel, @@ -191,7 +197,10 @@ pub(crate) fn check_tokens( pycodestyle::rules::too_many_newlines_at_end_of_file(&mut diagnostics, tokens); } - if settings.rules.enabled(Rule::UnformattedSpecialComment) { + if settings.rules.enabled(Rule::UnformattedSpecialComment) + && !per_file_ignores.contains(Rule::UnformattedSpecialComment) + && !exemption.enumerates(Rule::UnformattedSpecialComment) + { ruff::rules::unformatted_special_comment(&mut diagnostics, locator, comment_ranges); } diff --git a/crates/ruff_linter/src/rules/ruff/mod.rs b/crates/ruff_linter/src/rules/ruff/mod.rs index f729384ab39fc4..7274e8cb2a5cf5 100644 --- a/crates/ruff_linter/src/rules/ruff/mod.rs +++ b/crates/ruff_linter/src/rules/ruff/mod.rs @@ -385,6 +385,8 @@ mod tests { #[test_case(Rule::ZipInsteadOfPairwise, Path::new("RUF007.py"))] #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104.py"))] + #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104_1.py"))] + #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104_2.py"))] fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> { let snapshot = format!( "preview__{}_{}", diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap index 64db032864dda8..51bf4e059dd5ef 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap @@ -2,890 +2,890 @@ source: crates/ruff_linter/src/rules/ruff/mod.rs snapshot_kind: text --- -RUF104.py:42:3: RUF104 [*] Unformatted special comment +RUF104.py:44:3: RUF104 [*] Unformatted special comment | -40 | # type: list[str] -41 | -42 | # noqa:A123 +42 | # type: list[str] +43 | +44 | # noqa:A123 | ^^^^ RUF104 -43 | #noqa: A123 -44 | # type:ignore +45 | #noqa: A123 +46 | # type:ignore | = help: Format comment ℹ Safe fix -39 39 | # type: int -40 40 | # type: list[str] -41 41 | -42 |-# noqa:A123 - 42 |+# noqa: A123 -43 43 | #noqa: A123 -44 44 | # type:ignore -45 45 | #type: int +41 41 | # type: int +42 42 | # type: list[str] +43 43 | +44 |-# noqa:A123 + 44 |+# noqa: A123 +45 45 | #noqa: A123 +46 46 | # type:ignore +47 47 | #type: int -RUF104.py:43:2: RUF104 [*] Unformatted special comment +RUF104.py:45:2: RUF104 [*] Unformatted special comment | -42 | # noqa:A123 -43 | #noqa: A123 +44 | # noqa:A123 +45 | #noqa: A123 | ^^^^ RUF104 -44 | # type:ignore -45 | #type: int +46 | # type:ignore +47 | #type: int | = help: Format comment ℹ Safe fix -40 40 | # type: list[str] -41 41 | -42 42 | # noqa:A123 -43 |-#noqa: A123 - 43 |+# noqa: A123 -44 44 | # type:ignore -45 45 | #type: int -46 46 | # fmt:off +42 42 | # type: list[str] +43 43 | +44 44 | # noqa:A123 +45 |-#noqa: A123 + 45 |+# noqa: A123 +46 46 | # type:ignore +47 47 | #type: int +48 48 | # fmt:off -RUF104.py:44:6: RUF104 [*] Unformatted special comment +RUF104.py:46:6: RUF104 [*] Unformatted special comment | -42 | # noqa:A123 -43 | #noqa: A123 -44 | # type:ignore +44 | # noqa:A123 +45 | #noqa: A123 +46 | # type:ignore | ^^^^ RUF104 -45 | #type: int -46 | # fmt:off +47 | #type: int +48 | # fmt:off | = help: Format comment ℹ Safe fix -41 41 | -42 42 | # noqa:A123 -43 43 | #noqa: A123 -44 |-# type:ignore - 44 |+# type: ignore -45 45 | #type: int -46 46 | # fmt:off -47 47 | #fmt: on +43 43 | +44 44 | # noqa:A123 +45 45 | #noqa: A123 +46 |-# type:ignore + 46 |+# type: ignore +47 47 | #type: int +48 48 | # fmt:off +49 49 | #fmt: on -RUF104.py:45:2: RUF104 [*] Unformatted special comment +RUF104.py:47:2: RUF104 [*] Unformatted special comment | -43 | #noqa: A123 -44 | # type:ignore -45 | #type: int +45 | #noqa: A123 +46 | # type:ignore +47 | #type: int | ^^^^ RUF104 -46 | # fmt:off -47 | #fmt: on +48 | # fmt:off +49 | #fmt: on | = help: Format comment ℹ Safe fix -42 42 | # noqa:A123 -43 43 | #noqa: A123 -44 44 | # type:ignore -45 |-#type: int - 45 |+# type: int -46 46 | # fmt:off -47 47 | #fmt: on -48 48 | # fmt: skip +44 44 | # noqa:A123 +45 45 | #noqa: A123 +46 46 | # type:ignore +47 |-#type: int + 47 |+# type: int +48 48 | # fmt:off +49 49 | #fmt: on +50 50 | # fmt: skip -RUF104.py:46:3: RUF104 [*] Unformatted special comment +RUF104.py:48:3: RUF104 [*] Unformatted special comment | -44 | # type:ignore -45 | #type: int -46 | # fmt:off +46 | # type:ignore +47 | #type: int +48 | # fmt:off | ^^^ RUF104 -47 | #fmt: on -48 | # fmt: skip +49 | #fmt: on +50 | # fmt: skip | = help: Format comment ℹ Safe fix -43 43 | #noqa: A123 -44 44 | # type:ignore -45 45 | #type: int -46 |-# fmt:off - 46 |+# fmt: off -47 47 | #fmt: on -48 48 | # fmt: skip -49 49 | # isort:skip +45 45 | #noqa: A123 +46 46 | # type:ignore +47 47 | #type: int +48 |-# fmt:off + 48 |+# fmt: off +49 49 | #fmt: on +50 50 | # fmt: skip +51 51 | # isort:skip -RUF104.py:47:2: RUF104 [*] Unformatted special comment +RUF104.py:49:2: RUF104 [*] Unformatted special comment | -45 | #type: int -46 | # fmt:off -47 | #fmt: on +47 | #type: int +48 | # fmt:off +49 | #fmt: on | ^^^ RUF104 -48 | # fmt: skip -49 | # isort:skip +50 | # fmt: skip +51 | # isort:skip | = help: Format comment ℹ Safe fix -44 44 | # type:ignore -45 45 | #type: int -46 46 | # fmt:off -47 |-#fmt: on - 47 |+# fmt: on -48 48 | # fmt: skip -49 49 | # isort:skip -50 50 | # isort:skip_file +46 46 | # type:ignore +47 47 | #type: int +48 48 | # fmt:off +49 |-#fmt: on + 49 |+# fmt: on +50 50 | # fmt: skip +51 51 | # isort:skip +52 52 | # isort:skip_file -RUF104.py:48:5: RUF104 [*] Unformatted special comment +RUF104.py:50:5: RUF104 [*] Unformatted special comment | -46 | # fmt:off -47 | #fmt: on -48 | # fmt: skip +48 | # fmt:off +49 | #fmt: on +50 | # fmt: skip | ^^^ RUF104 -49 | # isort:skip -50 | # isort:skip_file +51 | # isort:skip +52 | # isort:skip_file | = help: Format comment ℹ Safe fix -45 45 | #type: int -46 46 | # fmt:off -47 47 | #fmt: on -48 |-# fmt: skip - 48 |+# fmt: skip -49 49 | # isort:skip -50 50 | # isort:skip_file -51 51 | # mypy: disallow-subclassing-any +47 47 | #type: int +48 48 | # fmt:off +49 49 | #fmt: on +50 |-# fmt: skip + 50 |+# fmt: skip +51 51 | # isort:skip +52 52 | # isort:skip_file +53 53 | # mypy: disallow-subclassing-any -RUF104.py:49:3: RUF104 [*] Unformatted special comment +RUF104.py:51:3: RUF104 [*] Unformatted special comment | -47 | #fmt: on -48 | # fmt: skip -49 | # isort:skip +49 | #fmt: on +50 | # fmt: skip +51 | # isort:skip | ^^^^^ RUF104 -50 | # isort:skip_file -51 | # mypy: disallow-subclassing-any +52 | # isort:skip_file +53 | # mypy: disallow-subclassing-any | = help: Format comment ℹ Safe fix -46 46 | # fmt:off -47 47 | #fmt: on -48 48 | # fmt: skip -49 |-# isort:skip - 49 |+# isort: skip -50 50 | # isort:skip_file -51 51 | # mypy: disallow-subclassing-any -52 52 | # nopycln: file +48 48 | # fmt:off +49 49 | #fmt: on +50 50 | # fmt: skip +51 |-# isort:skip + 51 |+# isort: skip +52 52 | # isort:skip_file +53 53 | # mypy: disallow-subclassing-any +54 54 | # nopycln: file -RUF104.py:50:3: RUF104 [*] Unformatted special comment +RUF104.py:52:3: RUF104 [*] Unformatted special comment | -48 | # fmt: skip -49 | # isort:skip -50 | # isort:skip_file +50 | # fmt: skip +51 | # isort:skip +52 | # isort:skip_file | ^^^^^ RUF104 -51 | # mypy: disallow-subclassing-any -52 | # nopycln: file +53 | # mypy: disallow-subclassing-any +54 | # nopycln: file | = help: Format comment ℹ Safe fix -47 47 | #fmt: on -48 48 | # fmt: skip -49 49 | # isort:skip -50 |-# isort:skip_file - 50 |+# isort: skip_file -51 51 | # mypy: disallow-subclassing-any -52 52 | # nopycln: file -53 53 | # nopycln: import +49 49 | #fmt: on +50 50 | # fmt: skip +51 51 | # isort:skip +52 |-# isort:skip_file + 52 |+# isort: skip_file +53 53 | # mypy: disallow-subclassing-any +54 54 | # nopycln: file +55 55 | # nopycln: import -RUF104.py:51:3: RUF104 [*] Unformatted special comment +RUF104.py:53:3: RUF104 [*] Unformatted special comment | -49 | # isort:skip -50 | # isort:skip_file -51 | # mypy: disallow-subclassing-any +51 | # isort:skip +52 | # isort:skip_file +53 | # mypy: disallow-subclassing-any | ^^^^ RUF104 -52 | # nopycln: file -53 | # nopycln: import +54 | # nopycln: file +55 | # nopycln: import | = help: Format comment ℹ Safe fix -48 48 | # fmt: skip -49 49 | # isort:skip -50 50 | # isort:skip_file -51 |-# mypy: disallow-subclassing-any - 51 |+# mypy: disallow-subclassing-any -52 52 | # nopycln: file -53 53 | # nopycln: import -54 54 | #pyright:ignore[] +50 50 | # fmt: skip +51 51 | # isort:skip +52 52 | # isort:skip_file +53 |-# mypy: disallow-subclassing-any + 53 |+# mypy: disallow-subclassing-any +54 54 | # nopycln: file +55 55 | # nopycln: import +56 56 | #pyright:ignore[] -RUF104.py:52:5: RUF104 [*] Unformatted special comment +RUF104.py:54:5: RUF104 [*] Unformatted special comment | -50 | # isort:skip_file -51 | # mypy: disallow-subclassing-any -52 | # nopycln: file +52 | # isort:skip_file +53 | # mypy: disallow-subclassing-any +54 | # nopycln: file | ^^^^^^^ RUF104 -53 | # nopycln: import -54 | #pyright:ignore[] +55 | # nopycln: import +56 | #pyright:ignore[] | = help: Format comment ℹ Safe fix -49 49 | # isort:skip -50 50 | # isort:skip_file -51 51 | # mypy: disallow-subclassing-any -52 |-# nopycln: file - 52 |+# nopycln: file -53 53 | # nopycln: import -54 54 | #pyright:ignore[] -55 55 | # pyright: ignore[] +51 51 | # isort:skip +52 52 | # isort:skip_file +53 53 | # mypy: disallow-subclassing-any +54 |-# nopycln: file + 54 |+# nopycln: file +55 55 | # nopycln: import +56 56 | #pyright:ignore[] +57 57 | # pyright: ignore[] -RUF104.py:53:4: RUF104 [*] Unformatted special comment +RUF104.py:55:4: RUF104 [*] Unformatted special comment | -51 | # mypy: disallow-subclassing-any -52 | # nopycln: file -53 | # nopycln: import +53 | # mypy: disallow-subclassing-any +54 | # nopycln: file +55 | # nopycln: import | ^^^^^^^ RUF104 -54 | #pyright:ignore[] -55 | # pyright: ignore[] +56 | #pyright:ignore[] +57 | # pyright: ignore[] | = help: Format comment ℹ Safe fix -50 50 | # isort:skip_file -51 51 | # mypy: disallow-subclassing-any -52 52 | # nopycln: file -53 |-# nopycln: import - 53 |+# nopycln: import -54 54 | #pyright:ignore[] -55 55 | # pyright: ignore[] -56 56 | # ruff: isort:skip +52 52 | # isort:skip_file +53 53 | # mypy: disallow-subclassing-any +54 54 | # nopycln: file +55 |-# nopycln: import + 55 |+# nopycln: import +56 56 | #pyright:ignore[] +57 57 | # pyright: ignore[] +58 58 | # ruff: isort:skip -RUF104.py:54:2: RUF104 [*] Unformatted special comment +RUF104.py:56:2: RUF104 [*] Unformatted special comment | -52 | # nopycln: file -53 | # nopycln: import -54 | #pyright:ignore[] +54 | # nopycln: file +55 | # nopycln: import +56 | #pyright:ignore[] | ^^^^^^^ RUF104 -55 | # pyright: ignore[] -56 | # ruff: isort:skip +57 | # pyright: ignore[] +58 | # ruff: isort:skip | = help: Format comment ℹ Safe fix -51 51 | # mypy: disallow-subclassing-any -52 52 | # nopycln: file -53 53 | # nopycln: import -54 |-#pyright:ignore[] - 54 |+# pyright: ignore[] -55 55 | # pyright: ignore[] -56 56 | # ruff: isort:skip -57 57 | # ruff: isort:skip_file +53 53 | # mypy: disallow-subclassing-any +54 54 | # nopycln: file +55 55 | # nopycln: import +56 |-#pyright:ignore[] + 56 |+# pyright: ignore[] +57 57 | # pyright: ignore[] +58 58 | # ruff: isort:skip +59 59 | # ruff: isort:skip_file -RUF104.py:55:5: RUF104 [*] Unformatted special comment +RUF104.py:57:5: RUF104 [*] Unformatted special comment | -53 | # nopycln: import -54 | #pyright:ignore[] -55 | # pyright: ignore[] +55 | # nopycln: import +56 | #pyright:ignore[] +57 | # pyright: ignore[] | ^^^^^^^ RUF104 -56 | # ruff: isort:skip -57 | # ruff: isort:skip_file +58 | # ruff: isort:skip +59 | # ruff: isort:skip_file | = help: Format comment ℹ Safe fix -52 52 | # nopycln: file -53 53 | # nopycln: import -54 54 | #pyright:ignore[] -55 |-# pyright: ignore[] - 55 |+# pyright: ignore[] -56 56 | # ruff: isort:skip -57 57 | # ruff: isort:skip_file -58 58 | # type: ignore +54 54 | # nopycln: file +55 55 | # nopycln: import +56 56 | #pyright:ignore[] +57 |-# pyright: ignore[] + 57 |+# pyright: ignore[] +58 58 | # ruff: isort:skip +59 59 | # ruff: isort:skip_file +60 60 | # type: ignore -RUF104.py:56:3: RUF104 [*] Unformatted special comment +RUF104.py:58:3: RUF104 [*] Unformatted special comment | -54 | #pyright:ignore[] -55 | # pyright: ignore[] -56 | # ruff: isort:skip +56 | #pyright:ignore[] +57 | # pyright: ignore[] +58 | # ruff: isort:skip | ^^^^ RUF104 -57 | # ruff: isort:skip_file -58 | # type: ignore +59 | # ruff: isort:skip_file +60 | # type: ignore | = help: Format comment ℹ Safe fix -53 53 | # nopycln: import -54 54 | #pyright:ignore[] -55 55 | # pyright: ignore[] -56 |-# ruff: isort:skip - 56 |+# ruff: isort: skip -57 57 | # ruff: isort:skip_file -58 58 | # type: ignore -59 59 | # type: int +55 55 | # nopycln: import +56 56 | #pyright:ignore[] +57 57 | # pyright: ignore[] +58 |-# ruff: isort:skip + 58 |+# ruff: isort: skip +59 59 | # ruff: isort:skip_file +60 60 | # type: ignore +61 61 | # type: int -RUF104.py:57:3: RUF104 [*] Unformatted special comment +RUF104.py:59:3: RUF104 [*] Unformatted special comment | -55 | # pyright: ignore[] -56 | # ruff: isort:skip -57 | # ruff: isort:skip_file +57 | # pyright: ignore[] +58 | # ruff: isort:skip +59 | # ruff: isort:skip_file | ^^^^ RUF104 -58 | # type: ignore -59 | # type: int +60 | # type: ignore +61 | # type: int | = help: Format comment ℹ Safe fix -54 54 | #pyright:ignore[] -55 55 | # pyright: ignore[] -56 56 | # ruff: isort:skip -57 |-# ruff: isort:skip_file - 57 |+# ruff: isort: skip_file -58 58 | # type: ignore -59 59 | # type: int -60 60 | +56 56 | #pyright:ignore[] +57 57 | # pyright: ignore[] +58 58 | # ruff: isort:skip +59 |-# ruff: isort:skip_file + 59 |+# ruff: isort: skip_file +60 60 | # type: ignore +61 61 | # type: int +62 62 | -RUF104.py:58:6: RUF104 [*] Unformatted special comment +RUF104.py:60:6: RUF104 [*] Unformatted special comment | -56 | # ruff: isort:skip -57 | # ruff: isort:skip_file -58 | # type: ignore +58 | # ruff: isort:skip +59 | # ruff: isort:skip_file +60 | # type: ignore | ^^^^ RUF104 -59 | # type: int +61 | # type: int | = help: Format comment ℹ Safe fix -55 55 | # pyright: ignore[] -56 56 | # ruff: isort:skip -57 57 | # ruff: isort:skip_file -58 |-# type: ignore - 58 |+# type: ignore -59 59 | # type: int -60 60 | -61 61 | # NoQA: A123, B456 +57 57 | # pyright: ignore[] +58 58 | # ruff: isort:skip +59 59 | # ruff: isort:skip_file +60 |-# type: ignore + 60 |+# type: ignore +61 61 | # type: int +62 62 | +63 63 | # NoQA: A123, B456 -RUF104.py:59:7: RUF104 [*] Unformatted special comment +RUF104.py:61:7: RUF104 [*] Unformatted special comment | -57 | # ruff: isort:skip_file -58 | # type: ignore -59 | # type: int +59 | # ruff: isort:skip_file +60 | # type: ignore +61 | # type: int | ^^^^ RUF104 -60 | -61 | # NoQA: A123, B456 +62 | +63 | # NoQA: A123, B456 | = help: Format comment ℹ Safe fix -56 56 | # ruff: isort:skip -57 57 | # ruff: isort:skip_file -58 58 | # type: ignore -59 |-# type: int - 59 |+# type: int -60 60 | -61 61 | # NoQA: A123, B456 -62 62 | # ruff: NoQA: A123, B456 +58 58 | # ruff: isort:skip +59 59 | # ruff: isort:skip_file +60 60 | # type: ignore +61 |-# type: int + 61 |+# type: int +62 62 | +63 63 | # NoQA: A123, B456 +64 64 | # ruff: NoQA: A123, B456 -RUF104.py:61:3: RUF104 [*] Unformatted special comment +RUF104.py:63:3: RUF104 [*] Unformatted special comment | -59 | # type: int -60 | -61 | # NoQA: A123, B456 +61 | # type: int +62 | +63 | # NoQA: A123, B456 | ^^^^ RUF104 -62 | # ruff: NoQA: A123, B456 -63 | # flake8: NoQA: A123, B456 +64 | # ruff: NoQA: A123, B456 +65 | # flake8: NoQA: A123, B456 | = help: Format comment ℹ Safe fix -58 58 | # type: ignore -59 59 | # type: int -60 60 | -61 |-# NoQA: A123, B456 - 61 |+# noqa: A123, B456 -62 62 | # ruff: NoQA: A123, B456 -63 63 | # flake8: NoQA: A123, B456 -64 64 | # NoPyCLN: File +60 60 | # type: ignore +61 61 | # type: int +62 62 | +63 |-# NoQA: A123, B456 + 63 |+# noqa: A123, B456 +64 64 | # ruff: NoQA: A123, B456 +65 65 | # flake8: NoQA: A123, B456 +66 66 | # NoPyCLN: File -RUF104.py:62:3: RUF104 [*] Unformatted special comment +RUF104.py:64:3: RUF104 [*] Unformatted special comment | -61 | # NoQA: A123, B456 -62 | # ruff: NoQA: A123, B456 +63 | # NoQA: A123, B456 +64 | # ruff: NoQA: A123, B456 | ^^^^ RUF104 -63 | # flake8: NoQA: A123, B456 -64 | # NoPyCLN: File +65 | # flake8: NoQA: A123, B456 +66 | # NoPyCLN: File | = help: Format comment ℹ Safe fix -59 59 | # type: int -60 60 | -61 61 | # NoQA: A123, B456 -62 |-# ruff: NoQA: A123, B456 - 62 |+# ruff: noqa: A123, B456 -63 63 | # flake8: NoQA: A123, B456 -64 64 | # NoPyCLN: File -65 65 | # NoPycln: Import +61 61 | # type: int +62 62 | +63 63 | # NoQA: A123, B456 +64 |-# ruff: NoQA: A123, B456 + 64 |+# ruff: noqa: A123, B456 +65 65 | # flake8: NoQA: A123, B456 +66 66 | # NoPyCLN: File +67 67 | # NoPycln: Import -RUF104.py:63:3: RUF104 [*] Unformatted special comment +RUF104.py:65:3: RUF104 [*] Unformatted special comment | -61 | # NoQA: A123, B456 -62 | # ruff: NoQA: A123, B456 -63 | # flake8: NoQA: A123, B456 +63 | # NoQA: A123, B456 +64 | # ruff: NoQA: A123, B456 +65 | # flake8: NoQA: A123, B456 | ^^^^^^ RUF104 -64 | # NoPyCLN: File -65 | # NoPycln: Import +66 | # NoPyCLN: File +67 | # NoPycln: Import | = help: Format comment ℹ Safe fix -60 60 | -61 61 | # NoQA: A123, B456 -62 62 | # ruff: NoQA: A123, B456 -63 |-# flake8: NoQA: A123, B456 - 63 |+# flake8: noqa: A123, B456 -64 64 | # NoPyCLN: File -65 65 | # NoPycln: Import -66 66 | # nOpYcLn: iMpOrT +62 62 | +63 63 | # NoQA: A123, B456 +64 64 | # ruff: NoQA: A123, B456 +65 |-# flake8: NoQA: A123, B456 + 65 |+# flake8: noqa: A123, B456 +66 66 | # NoPyCLN: File +67 67 | # NoPycln: Import +68 68 | # nOpYcLn: iMpOrT -RUF104.py:64:3: RUF104 [*] Unformatted special comment +RUF104.py:66:3: RUF104 [*] Unformatted special comment | -62 | # ruff: NoQA: A123, B456 -63 | # flake8: NoQA: A123, B456 -64 | # NoPyCLN: File +64 | # ruff: NoQA: A123, B456 +65 | # flake8: NoQA: A123, B456 +66 | # NoPyCLN: File | ^^^^^^^ RUF104 -65 | # NoPycln: Import -66 | # nOpYcLn: iMpOrT +67 | # NoPycln: Import +68 | # nOpYcLn: iMpOrT | = help: Format comment ℹ Safe fix -61 61 | # NoQA: A123, B456 -62 62 | # ruff: NoQA: A123, B456 -63 63 | # flake8: NoQA: A123, B456 -64 |-# NoPyCLN: File - 64 |+# nopycln: file -65 65 | # NoPycln: Import -66 66 | # nOpYcLn: iMpOrT -67 67 | +63 63 | # NoQA: A123, B456 +64 64 | # ruff: NoQA: A123, B456 +65 65 | # flake8: NoQA: A123, B456 +66 |-# NoPyCLN: File + 66 |+# nopycln: file +67 67 | # NoPycln: Import +68 68 | # nOpYcLn: iMpOrT +69 69 | -RUF104.py:65:3: RUF104 [*] Unformatted special comment +RUF104.py:67:3: RUF104 [*] Unformatted special comment | -63 | # flake8: NoQA: A123, B456 -64 | # NoPyCLN: File -65 | # NoPycln: Import +65 | # flake8: NoQA: A123, B456 +66 | # NoPyCLN: File +67 | # NoPycln: Import | ^^^^^^^ RUF104 -66 | # nOpYcLn: iMpOrT +68 | # nOpYcLn: iMpOrT | = help: Format comment ℹ Safe fix -62 62 | # ruff: NoQA: A123, B456 -63 63 | # flake8: NoQA: A123, B456 -64 64 | # NoPyCLN: File -65 |-# NoPycln: Import - 65 |+# nopycln: import -66 66 | # nOpYcLn: iMpOrT -67 67 | -68 68 | # noqa: A123 B456 +64 64 | # ruff: NoQA: A123, B456 +65 65 | # flake8: NoQA: A123, B456 +66 66 | # NoPyCLN: File +67 |-# NoPycln: Import + 67 |+# nopycln: import +68 68 | # nOpYcLn: iMpOrT +69 69 | +70 70 | # noqa: A123 B456 -RUF104.py:66:3: RUF104 [*] Unformatted special comment +RUF104.py:68:3: RUF104 [*] Unformatted special comment | -64 | # NoPyCLN: File -65 | # NoPycln: Import -66 | # nOpYcLn: iMpOrT +66 | # NoPyCLN: File +67 | # NoPycln: Import +68 | # nOpYcLn: iMpOrT | ^^^^^^^ RUF104 -67 | -68 | # noqa: A123 B456 +69 | +70 | # noqa: A123 B456 | = help: Format comment ℹ Safe fix -63 63 | # flake8: NoQA: A123, B456 -64 64 | # NoPyCLN: File -65 65 | # NoPycln: Import -66 |-# nOpYcLn: iMpOrT - 66 |+# nopycln: import -67 67 | -68 68 | # noqa: A123 B456 -69 69 | # ruff: noqa: A123 B456 +65 65 | # flake8: NoQA: A123, B456 +66 66 | # NoPyCLN: File +67 67 | # NoPycln: Import +68 |-# nOpYcLn: iMpOrT + 68 |+# nopycln: import +69 69 | +70 70 | # noqa: A123 B456 +71 71 | # ruff: noqa: A123 B456 -RUF104.py:68:3: RUF104 [*] Unformatted special comment +RUF104.py:70:3: RUF104 [*] Unformatted special comment | -66 | # nOpYcLn: iMpOrT -67 | -68 | # noqa: A123 B456 +68 | # nOpYcLn: iMpOrT +69 | +70 | # noqa: A123 B456 | ^^^^ RUF104 -69 | # ruff: noqa: A123 B456 -70 | # flake8: noqa: A123 B456 +71 | # ruff: noqa: A123 B456 +72 | # flake8: noqa: A123 B456 | = help: Format comment ℹ Safe fix -65 65 | # NoPycln: Import -66 66 | # nOpYcLn: iMpOrT -67 67 | -68 |-# noqa: A123 B456 - 68 |+# noqa: A123, B456 -69 69 | # ruff: noqa: A123 B456 -70 70 | # flake8: noqa: A123 B456 -71 71 | # noqa: A123,B456 +67 67 | # NoPycln: Import +68 68 | # nOpYcLn: iMpOrT +69 69 | +70 |-# noqa: A123 B456 + 70 |+# noqa: A123, B456 +71 71 | # ruff: noqa: A123 B456 +72 72 | # flake8: noqa: A123 B456 +73 73 | # noqa: A123,B456 -RUF104.py:69:3: RUF104 [*] Unformatted special comment +RUF104.py:71:3: RUF104 [*] Unformatted special comment | -68 | # noqa: A123 B456 -69 | # ruff: noqa: A123 B456 +70 | # noqa: A123 B456 +71 | # ruff: noqa: A123 B456 | ^^^^ RUF104 -70 | # flake8: noqa: A123 B456 -71 | # noqa: A123,B456 +72 | # flake8: noqa: A123 B456 +73 | # noqa: A123,B456 | = help: Format comment ℹ Safe fix -66 66 | # nOpYcLn: iMpOrT -67 67 | -68 68 | # noqa: A123 B456 -69 |-# ruff: noqa: A123 B456 - 69 |+# ruff: noqa: A123, B456 -70 70 | # flake8: noqa: A123 B456 -71 71 | # noqa: A123,B456 -72 72 | # ruff: noqa: A123,B456 +68 68 | # nOpYcLn: iMpOrT +69 69 | +70 70 | # noqa: A123 B456 +71 |-# ruff: noqa: A123 B456 + 71 |+# ruff: noqa: A123, B456 +72 72 | # flake8: noqa: A123 B456 +73 73 | # noqa: A123,B456 +74 74 | # ruff: noqa: A123,B456 -RUF104.py:70:3: RUF104 [*] Unformatted special comment +RUF104.py:72:3: RUF104 [*] Unformatted special comment | -68 | # noqa: A123 B456 -69 | # ruff: noqa: A123 B456 -70 | # flake8: noqa: A123 B456 +70 | # noqa: A123 B456 +71 | # ruff: noqa: A123 B456 +72 | # flake8: noqa: A123 B456 | ^^^^^^ RUF104 -71 | # noqa: A123,B456 -72 | # ruff: noqa: A123,B456 +73 | # noqa: A123,B456 +74 | # ruff: noqa: A123,B456 | = help: Format comment ℹ Safe fix -67 67 | -68 68 | # noqa: A123 B456 -69 69 | # ruff: noqa: A123 B456 -70 |-# flake8: noqa: A123 B456 - 70 |+# flake8: noqa: A123, B456 -71 71 | # noqa: A123,B456 -72 72 | # ruff: noqa: A123,B456 -73 73 | # flake8: noqa: A123,B456 +69 69 | +70 70 | # noqa: A123 B456 +71 71 | # ruff: noqa: A123 B456 +72 |-# flake8: noqa: A123 B456 + 72 |+# flake8: noqa: A123, B456 +73 73 | # noqa: A123,B456 +74 74 | # ruff: noqa: A123,B456 +75 75 | # flake8: noqa: A123,B456 -RUF104.py:71:3: RUF104 [*] Unformatted special comment +RUF104.py:73:3: RUF104 [*] Unformatted special comment | -69 | # ruff: noqa: A123 B456 -70 | # flake8: noqa: A123 B456 -71 | # noqa: A123,B456 +71 | # ruff: noqa: A123 B456 +72 | # flake8: noqa: A123 B456 +73 | # noqa: A123,B456 | ^^^^ RUF104 -72 | # ruff: noqa: A123,B456 -73 | # flake8: noqa: A123,B456 +74 | # ruff: noqa: A123,B456 +75 | # flake8: noqa: A123,B456 | = help: Format comment ℹ Safe fix -68 68 | # noqa: A123 B456 -69 69 | # ruff: noqa: A123 B456 -70 70 | # flake8: noqa: A123 B456 -71 |-# noqa: A123,B456 - 71 |+# noqa: A123, B456 -72 72 | # ruff: noqa: A123,B456 -73 73 | # flake8: noqa: A123,B456 -74 74 | # noqa: A123,,B456 +70 70 | # noqa: A123 B456 +71 71 | # ruff: noqa: A123 B456 +72 72 | # flake8: noqa: A123 B456 +73 |-# noqa: A123,B456 + 73 |+# noqa: A123, B456 +74 74 | # ruff: noqa: A123,B456 +75 75 | # flake8: noqa: A123,B456 +76 76 | # noqa: A123,,B456 -RUF104.py:72:3: RUF104 [*] Unformatted special comment +RUF104.py:74:3: RUF104 [*] Unformatted special comment | -70 | # flake8: noqa: A123 B456 -71 | # noqa: A123,B456 -72 | # ruff: noqa: A123,B456 +72 | # flake8: noqa: A123 B456 +73 | # noqa: A123,B456 +74 | # ruff: noqa: A123,B456 | ^^^^ RUF104 -73 | # flake8: noqa: A123,B456 -74 | # noqa: A123,,B456 +75 | # flake8: noqa: A123,B456 +76 | # noqa: A123,,B456 | = help: Format comment ℹ Safe fix -69 69 | # ruff: noqa: A123 B456 -70 70 | # flake8: noqa: A123 B456 -71 71 | # noqa: A123,B456 -72 |-# ruff: noqa: A123,B456 - 72 |+# ruff: noqa: A123, B456 -73 73 | # flake8: noqa: A123,B456 -74 74 | # noqa: A123,,B456 -75 75 | # noqa: A123 , , B456 +71 71 | # ruff: noqa: A123 B456 +72 72 | # flake8: noqa: A123 B456 +73 73 | # noqa: A123,B456 +74 |-# ruff: noqa: A123,B456 + 74 |+# ruff: noqa: A123, B456 +75 75 | # flake8: noqa: A123,B456 +76 76 | # noqa: A123,,B456 +77 77 | # noqa: A123 , , B456 -RUF104.py:73:3: RUF104 [*] Unformatted special comment +RUF104.py:75:3: RUF104 [*] Unformatted special comment | -71 | # noqa: A123,B456 -72 | # ruff: noqa: A123,B456 -73 | # flake8: noqa: A123,B456 +73 | # noqa: A123,B456 +74 | # ruff: noqa: A123,B456 +75 | # flake8: noqa: A123,B456 | ^^^^^^ RUF104 -74 | # noqa: A123,,B456 -75 | # noqa: A123 , , B456 +76 | # noqa: A123,,B456 +77 | # noqa: A123 , , B456 | = help: Format comment ℹ Safe fix -70 70 | # flake8: noqa: A123 B456 -71 71 | # noqa: A123,B456 -72 72 | # ruff: noqa: A123,B456 -73 |-# flake8: noqa: A123,B456 - 73 |+# flake8: noqa: A123, B456 -74 74 | # noqa: A123,,B456 -75 75 | # noqa: A123 , , B456 -76 76 | # noqa: A123 B456 +72 72 | # flake8: noqa: A123 B456 +73 73 | # noqa: A123,B456 +74 74 | # ruff: noqa: A123,B456 +75 |-# flake8: noqa: A123,B456 + 75 |+# flake8: noqa: A123, B456 +76 76 | # noqa: A123,,B456 +77 77 | # noqa: A123 , , B456 +78 78 | # noqa: A123 B456 -RUF104.py:74:3: RUF104 [*] Unformatted special comment +RUF104.py:76:3: RUF104 [*] Unformatted special comment | -72 | # ruff: noqa: A123,B456 -73 | # flake8: noqa: A123,B456 -74 | # noqa: A123,,B456 +74 | # ruff: noqa: A123,B456 +75 | # flake8: noqa: A123,B456 +76 | # noqa: A123,,B456 | ^^^^ RUF104 -75 | # noqa: A123 , , B456 -76 | # noqa: A123 B456 +77 | # noqa: A123 , , B456 +78 | # noqa: A123 B456 | = help: Format comment ℹ Safe fix -71 71 | # noqa: A123,B456 -72 72 | # ruff: noqa: A123,B456 -73 73 | # flake8: noqa: A123,B456 -74 |-# noqa: A123,,B456 - 74 |+# noqa: A123, B456 -75 75 | # noqa: A123 , , B456 -76 76 | # noqa: A123 B456 -77 77 | # noqa: A123 B456 +73 73 | # noqa: A123,B456 +74 74 | # ruff: noqa: A123,B456 +75 75 | # flake8: noqa: A123,B456 +76 |-# noqa: A123,,B456 + 76 |+# noqa: A123, B456 +77 77 | # noqa: A123 , , B456 +78 78 | # noqa: A123 B456 +79 79 | # noqa: A123 B456 -RUF104.py:75:3: RUF104 [*] Unformatted special comment +RUF104.py:77:3: RUF104 [*] Unformatted special comment | -73 | # flake8: noqa: A123,B456 -74 | # noqa: A123,,B456 -75 | # noqa: A123 , , B456 +75 | # flake8: noqa: A123,B456 +76 | # noqa: A123,,B456 +77 | # noqa: A123 , , B456 | ^^^^ RUF104 -76 | # noqa: A123 B456 -77 | # noqa: A123 B456 +78 | # noqa: A123 B456 +79 | # noqa: A123 B456 | = help: Format comment ℹ Safe fix -72 72 | # ruff: noqa: A123,B456 -73 73 | # flake8: noqa: A123,B456 -74 74 | # noqa: A123,,B456 -75 |-# noqa: A123 , , B456 - 75 |+# noqa: A123, B456 -76 76 | # noqa: A123 B456 -77 77 | # noqa: A123 B456 -78 78 | # noqa: A123 B456 +74 74 | # ruff: noqa: A123,B456 +75 75 | # flake8: noqa: A123,B456 +76 76 | # noqa: A123,,B456 +77 |-# noqa: A123 , , B456 + 77 |+# noqa: A123, B456 +78 78 | # noqa: A123 B456 +79 79 | # noqa: A123 B456 +80 80 | # noqa: A123 B456 -RUF104.py:76:3: RUF104 [*] Unformatted special comment +RUF104.py:78:3: RUF104 [*] Unformatted special comment | -74 | # noqa: A123,,B456 -75 | # noqa: A123 , , B456 -76 | # noqa: A123 B456 +76 | # noqa: A123,,B456 +77 | # noqa: A123 , , B456 +78 | # noqa: A123 B456 | ^^^^ RUF104 -77 | # noqa: A123 B456 -78 | # noqa: A123 B456 +79 | # noqa: A123 B456 +80 | # noqa: A123 B456 | = help: Format comment ℹ Safe fix -73 73 | # flake8: noqa: A123,B456 -74 74 | # noqa: A123,,B456 -75 75 | # noqa: A123 , , B456 -76 |-# noqa: A123 B456 - 76 |+# noqa: A123, B456 -77 77 | # noqa: A123 B456 -78 78 | # noqa: A123 B456 -79 79 | # noqa: A123 ,B456 +75 75 | # flake8: noqa: A123,B456 +76 76 | # noqa: A123,,B456 +77 77 | # noqa: A123 , , B456 +78 |-# noqa: A123 B456 + 78 |+# noqa: A123, B456 +79 79 | # noqa: A123 B456 +80 80 | # noqa: A123 B456 +81 81 | # noqa: A123 ,B456 -RUF104.py:77:3: RUF104 [*] Unformatted special comment +RUF104.py:79:3: RUF104 [*] Unformatted special comment | -75 | # noqa: A123 , , B456 -76 | # noqa: A123 B456 -77 | # noqa: A123 B456 +77 | # noqa: A123 , , B456 +78 | # noqa: A123 B456 +79 | # noqa: A123 B456 | ^^^^ RUF104 -78 | # noqa: A123 B456 -79 | # noqa: A123 ,B456 +80 | # noqa: A123 B456 +81 | # noqa: A123 ,B456 | = help: Format comment ℹ Safe fix -74 74 | # noqa: A123,,B456 -75 75 | # noqa: A123 , , B456 -76 76 | # noqa: A123 B456 -77 |-# noqa: A123 B456 - 77 |+# noqa: A123, B456 -78 78 | # noqa: A123 B456 -79 79 | # noqa: A123 ,B456 -80 80 | # ruff: noqa: A123 B456 +76 76 | # noqa: A123,,B456 +77 77 | # noqa: A123 , , B456 +78 78 | # noqa: A123 B456 +79 |-# noqa: A123 B456 + 79 |+# noqa: A123, B456 +80 80 | # noqa: A123 B456 +81 81 | # noqa: A123 ,B456 +82 82 | # ruff: noqa: A123 B456 -RUF104.py:78:3: RUF104 [*] Unformatted special comment +RUF104.py:80:3: RUF104 [*] Unformatted special comment | -76 | # noqa: A123 B456 -77 | # noqa: A123 B456 -78 | # noqa: A123 B456 +78 | # noqa: A123 B456 +79 | # noqa: A123 B456 +80 | # noqa: A123 B456 | ^^^^ RUF104 -79 | # noqa: A123 ,B456 -80 | # ruff: noqa: A123 B456 +81 | # noqa: A123 ,B456 +82 | # ruff: noqa: A123 B456 | = help: Format comment ℹ Safe fix -75 75 | # noqa: A123 , , B456 -76 76 | # noqa: A123 B456 -77 77 | # noqa: A123 B456 -78 |-# noqa: A123 B456 - 78 |+# noqa: A123, B456 -79 79 | # noqa: A123 ,B456 -80 80 | # ruff: noqa: A123 B456 -81 81 | # flake8: noqa: A123 B456 +77 77 | # noqa: A123 , , B456 +78 78 | # noqa: A123 B456 +79 79 | # noqa: A123 B456 +80 |-# noqa: A123 B456 + 80 |+# noqa: A123, B456 +81 81 | # noqa: A123 ,B456 +82 82 | # ruff: noqa: A123 B456 +83 83 | # flake8: noqa: A123 B456 -RUF104.py:79:3: RUF104 [*] Unformatted special comment +RUF104.py:81:3: RUF104 [*] Unformatted special comment | -77 | # noqa: A123 B456 -78 | # noqa: A123 B456 -79 | # noqa: A123 ,B456 +79 | # noqa: A123 B456 +80 | # noqa: A123 B456 +81 | # noqa: A123 ,B456 | ^^^^ RUF104 -80 | # ruff: noqa: A123 B456 -81 | # flake8: noqa: A123 B456 +82 | # ruff: noqa: A123 B456 +83 | # flake8: noqa: A123 B456 | = help: Format comment ℹ Safe fix -76 76 | # noqa: A123 B456 -77 77 | # noqa: A123 B456 -78 78 | # noqa: A123 B456 -79 |-# noqa: A123 ,B456 - 79 |+# noqa: A123, B456 -80 80 | # ruff: noqa: A123 B456 -81 81 | # flake8: noqa: A123 B456 -82 82 | +78 78 | # noqa: A123 B456 +79 79 | # noqa: A123 B456 +80 80 | # noqa: A123 B456 +81 |-# noqa: A123 ,B456 + 81 |+# noqa: A123, B456 +82 82 | # ruff: noqa: A123 B456 +83 83 | # flake8: noqa: A123 B456 +84 84 | -RUF104.py:80:3: RUF104 [*] Unformatted special comment +RUF104.py:82:3: RUF104 [*] Unformatted special comment | -78 | # noqa: A123 B456 -79 | # noqa: A123 ,B456 -80 | # ruff: noqa: A123 B456 +80 | # noqa: A123 B456 +81 | # noqa: A123 ,B456 +82 | # ruff: noqa: A123 B456 | ^^^^ RUF104 -81 | # flake8: noqa: A123 B456 +83 | # flake8: noqa: A123 B456 | = help: Format comment ℹ Safe fix -77 77 | # noqa: A123 B456 -78 78 | # noqa: A123 B456 -79 79 | # noqa: A123 ,B456 -80 |-# ruff: noqa: A123 B456 - 80 |+# ruff: noqa: A123, B456 -81 81 | # flake8: noqa: A123 B456 -82 82 | -83 83 | +79 79 | # noqa: A123 B456 +80 80 | # noqa: A123 B456 +81 81 | # noqa: A123 ,B456 +82 |-# ruff: noqa: A123 B456 + 82 |+# ruff: noqa: A123, B456 +83 83 | # flake8: noqa: A123 B456 +84 84 | +85 85 | -RUF104.py:81:3: RUF104 [*] Unformatted special comment +RUF104.py:83:3: RUF104 [*] Unformatted special comment | -79 | # noqa: A123 ,B456 -80 | # ruff: noqa: A123 B456 -81 | # flake8: noqa: A123 B456 +81 | # noqa: A123 ,B456 +82 | # ruff: noqa: A123 B456 +83 | # flake8: noqa: A123 B456 | ^^^^^^ RUF104 | = help: Format comment ℹ Safe fix -78 78 | # noqa: A123 B456 -79 79 | # noqa: A123 ,B456 -80 80 | # ruff: noqa: A123 B456 -81 |-# flake8: noqa: A123 B456 - 81 |+# flake8: noqa: A123, B456 -82 82 | -83 83 | -84 84 | # type: ignore # noqa: A123, B456 +80 80 | # noqa: A123 B456 +81 81 | # noqa: A123 ,B456 +82 82 | # ruff: noqa: A123 B456 +83 |-# flake8: noqa: A123 B456 + 83 |+# flake8: noqa: A123, B456 +84 84 | +85 85 | +86 86 | # type: ignore # noqa: A123, B456 -RUF104.py:86:2: RUF104 [*] Unformatted special comment +RUF104.py:88:2: RUF104 [*] Unformatted special comment | -84 | # type: ignore # noqa: A123, B456 -85 | -86 | #pyright:ignore#noqa:A123 - | ^^^^^^^ RUF104 +86 | # type: ignore # noqa: A123, B456 87 | -88 | # nopycln:file# noqa: A123 +88 | #pyright:ignore#noqa:A123 + | ^^^^^^^ RUF104 +89 | +90 | # nopycln:file# noqa: A123 | = help: Format comment ℹ Safe fix -83 83 | -84 84 | # type: ignore # noqa: A123, B456 85 85 | -86 |-#pyright:ignore#noqa:A123 - 86 |+# pyright: ignore#noqa:A123 +86 86 | # type: ignore # noqa: A123, B456 87 87 | -88 88 | # nopycln:file# noqa: A123 +88 |-#pyright:ignore#noqa:A123 + 88 |+# pyright: ignore#noqa:A123 89 89 | +90 90 | # nopycln:file# noqa: A123 +91 91 | -RUF104.py:86:17: RUF104 [*] Unformatted special comment +RUF104.py:88:17: RUF104 [*] Unformatted special comment | -84 | # type: ignore # noqa: A123, B456 -85 | -86 | #pyright:ignore#noqa:A123 - | ^^^^ RUF104 +86 | # type: ignore # noqa: A123, B456 87 | -88 | # nopycln:file# noqa: A123 +88 | #pyright:ignore#noqa:A123 + | ^^^^ RUF104 +89 | +90 | # nopycln:file# noqa: A123 | = help: Format comment ℹ Safe fix -83 83 | -84 84 | # type: ignore # noqa: A123, B456 85 85 | -86 |-#pyright:ignore#noqa:A123 - 86 |+#pyright:ignore# noqa: A123 +86 86 | # type: ignore # noqa: A123, B456 87 87 | -88 88 | # nopycln:file# noqa: A123 +88 |-#pyright:ignore#noqa:A123 + 88 |+#pyright:ignore# noqa: A123 89 89 | +90 90 | # nopycln:file# noqa: A123 +91 91 | -RUF104.py:88:3: RUF104 [*] Unformatted special comment +RUF104.py:90:3: RUF104 [*] Unformatted special comment | -86 | #pyright:ignore#noqa:A123 -87 | -88 | # nopycln:file# noqa: A123 - | ^^^^^^^ RUF104 +88 | #pyright:ignore#noqa:A123 89 | -90 | # noqa:A123 - Lorem ipsum dolor sit amet +90 | # nopycln:file# noqa: A123 + | ^^^^^^^ RUF104 +91 | +92 | # noqa:A123 - Lorem ipsum dolor sit amet | = help: Format comment ℹ Safe fix -85 85 | -86 86 | #pyright:ignore#noqa:A123 87 87 | -88 |-# nopycln:file# noqa: A123 - 88 |+# nopycln: file# noqa: A123 +88 88 | #pyright:ignore#noqa:A123 89 89 | -90 90 | # noqa:A123 - Lorem ipsum dolor sit amet +90 |-# nopycln:file# noqa: A123 + 90 |+# nopycln: file# noqa: A123 +91 91 | +92 92 | # noqa:A123 - Lorem ipsum dolor sit amet -RUF104.py:88:19: RUF104 [*] Unformatted special comment +RUF104.py:90:19: RUF104 [*] Unformatted special comment | -86 | #pyright:ignore#noqa:A123 -87 | -88 | # nopycln:file# noqa: A123 - | ^^^^ RUF104 +88 | #pyright:ignore#noqa:A123 89 | -90 | # noqa:A123 - Lorem ipsum dolor sit amet +90 | # nopycln:file# noqa: A123 + | ^^^^ RUF104 +91 | +92 | # noqa:A123 - Lorem ipsum dolor sit amet | = help: Format comment ℹ Safe fix -85 85 | -86 86 | #pyright:ignore#noqa:A123 87 87 | -88 |-# nopycln:file# noqa: A123 - 88 |+# nopycln:file# noqa: A123 +88 88 | #pyright:ignore#noqa:A123 89 89 | -90 90 | # noqa:A123 - Lorem ipsum dolor sit amet +90 |-# nopycln:file# noqa: A123 + 90 |+# nopycln:file# noqa: A123 +91 91 | +92 92 | # noqa:A123 - Lorem ipsum dolor sit amet -RUF104.py:90:3: RUF104 [*] Unformatted special comment +RUF104.py:92:3: RUF104 [*] Unformatted special comment | -88 | # nopycln:file# noqa: A123 -89 | -90 | # noqa:A123 - Lorem ipsum dolor sit amet +90 | # nopycln:file# noqa: A123 +91 | +92 | # noqa:A123 - Lorem ipsum dolor sit amet | ^^^^ RUF104 | = help: Format comment ℹ Safe fix -87 87 | -88 88 | # nopycln:file# noqa: A123 89 89 | -90 |-# noqa:A123 - Lorem ipsum dolor sit amet - 90 |+# noqa: A123 - Lorem ipsum dolor sit amet +90 90 | # nopycln:file# noqa: A123 +91 91 | +92 |-# noqa:A123 - Lorem ipsum dolor sit amet + 92 |+# noqa: A123 - Lorem ipsum dolor sit amet diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_1.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_1.py.snap new file mode 100644 index 00000000000000..6997530a7c65d0 --- /dev/null +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_1.py.snap @@ -0,0 +1,33 @@ +--- +source: crates/ruff_linter/src/rules/ruff/mod.rs +snapshot_kind: text +--- +RUF104_1.py:1:3: RUF104 [*] Unformatted special comment + | +1 | # ruff:noqa + | ^^^^ RUF104 +2 | +3 | #noqa:A123 + | + = help: Format comment + +ℹ Safe fix +1 |-# ruff:noqa + 1 |+# ruff: noqa +2 2 | +3 3 | #noqa:A123 + +RUF104_1.py:3:2: RUF104 [*] Unformatted special comment + | +1 | # ruff:noqa +2 | +3 | #noqa:A123 + | ^^^^ RUF104 + | + = help: Format comment + +ℹ Safe fix +1 1 | # ruff:noqa +2 2 | +3 |-#noqa:A123 + 3 |+# noqa: A123 diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_2.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_2.py.snap new file mode 100644 index 00000000000000..b3a37c09211090 --- /dev/null +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_2.py.snap @@ -0,0 +1,5 @@ +--- +source: crates/ruff_linter/src/rules/ruff/mod.rs +snapshot_kind: text +--- + From a050fc7400dc161995ac8fefe3cf753c98607de6 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Sun, 10 Nov 2024 10:53:59 +0000 Subject: [PATCH 18/29] `rustfmt` --- crates/ruff_linter/src/checkers/noqa.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/ruff_linter/src/checkers/noqa.rs b/crates/ruff_linter/src/checkers/noqa.rs index f9d768c65f9135..5143aadcdf17a7 100644 --- a/crates/ruff_linter/src/checkers/noqa.rs +++ b/crates/ruff_linter/src/checkers/noqa.rs @@ -45,7 +45,10 @@ pub(crate) fn check_noqa( // Remove any ignored diagnostics. 'outer: for (index, diagnostic) in diagnostics.iter().enumerate() { - if matches!(diagnostic.kind.rule(), Rule::BlanketNOQA | Rule::UnformattedSpecialComment) { + if matches!( + diagnostic.kind.rule(), + Rule::BlanketNOQA | Rule::UnformattedSpecialComment + ) { continue; } From 42f9577fbf1aed453b8e8889c9fd3436f7c53067 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Sun, 10 Nov 2024 16:34:53 +0000 Subject: [PATCH 19/29] Update `# noqa` parsing algorithm to match that of `Directive::try_extract()` --- .../resources/test/fixtures/ruff/RUF104_3.py | 3 + crates/ruff_linter/src/checkers/tokens.rs | 13 +-- crates/ruff_linter/src/rules/ruff/mod.rs | 1 + .../ruff/rules/unformatted_special_comment.rs | 86 ++++++++++--------- ...f__tests__preview__RUF104_RUF104_3.py.snap | 48 +++++++++++ 5 files changed, 100 insertions(+), 51 deletions(-) create mode 100644 crates/ruff_linter/resources/test/fixtures/ruff/RUF104_3.py create mode 100644 crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_3.py.snap diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_3.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_3.py new file mode 100644 index 00000000000000..ee359932d8246b --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_3.py @@ -0,0 +1,3 @@ +#noqa: +#ruff:noqa: +#flake8:noqa: diff --git a/crates/ruff_linter/src/checkers/tokens.rs b/crates/ruff_linter/src/checkers/tokens.rs index 08a3048dc4cb47..ac6b63858e3755 100644 --- a/crates/ruff_linter/src/checkers/tokens.rs +++ b/crates/ruff_linter/src/checkers/tokens.rs @@ -11,7 +11,6 @@ use ruff_python_parser::Tokens; use ruff_text_size::Ranged; use crate::directives::TodoComment; -use crate::noqa::{FileExemption, FileNoqaDirectives}; use crate::registry::{AsRule, Rule}; use crate::rules::pycodestyle::rules::BlankLinesChecker; use crate::rules::{ @@ -19,7 +18,7 @@ use crate::rules::{ flake8_pyi, flake8_todos, pycodestyle, pygrep_hooks, pylint, pyupgrade, ruff, }; use crate::settings::LinterSettings; -use crate::{fs, Locator}; +use crate::Locator; #[allow(clippy::too_many_arguments)] pub(crate) fn check_tokens( @@ -35,11 +34,6 @@ pub(crate) fn check_tokens( let mut diagnostics: Vec = vec![]; let comment_ranges = indexer.comment_ranges(); - let per_file_ignores = fs::ignores_from_path(path, &settings.per_file_ignores); - let file_noqa_directives = - FileNoqaDirectives::extract(locator, comment_ranges, &settings.external, path); - let exemption = FileExemption::from(&file_noqa_directives); - if settings.rules.any_enabled(&[ Rule::BlankLineBetweenMethods, Rule::BlankLinesTopLevel, @@ -197,10 +191,7 @@ pub(crate) fn check_tokens( pycodestyle::rules::too_many_newlines_at_end_of_file(&mut diagnostics, tokens); } - if settings.rules.enabled(Rule::UnformattedSpecialComment) - && !per_file_ignores.contains(Rule::UnformattedSpecialComment) - && !exemption.enumerates(Rule::UnformattedSpecialComment) - { + if settings.rules.enabled(Rule::UnformattedSpecialComment) { ruff::rules::unformatted_special_comment(&mut diagnostics, locator, comment_ranges); } diff --git a/crates/ruff_linter/src/rules/ruff/mod.rs b/crates/ruff_linter/src/rules/ruff/mod.rs index 7274e8cb2a5cf5..693a49d21cc3ba 100644 --- a/crates/ruff_linter/src/rules/ruff/mod.rs +++ b/crates/ruff_linter/src/rules/ruff/mod.rs @@ -387,6 +387,7 @@ mod tests { #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104.py"))] #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104_1.py"))] #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104_2.py"))] + #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104_3.py"))] fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> { let snapshot = format!( "preview__{}_{}", diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index ff491c278f4c56..74262d2bb73dd0 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -39,37 +39,33 @@ enum SpecialComment { } impl SpecialComment { - fn formatted(&self) -> Option { + fn formatted(&self) -> String { match self { - SpecialComment::Noqa(None) => Some("# noqa".to_string()), + SpecialComment::Noqa(None) => "# noqa".to_string(), - // Avoid suggesting the unsafe fix - // `# noqa:` (ignore nothing) -> `# noqa` (ignore everything). - SpecialComment::Noqa(Some(codes)) if codes.is_empty() => None, + SpecialComment::Noqa(Some(codes)) if codes.is_empty() => "# noqa:".to_string(), - SpecialComment::Noqa(Some(codes)) => Some(format!("# noqa: {}", codes.join(", "))), + SpecialComment::Noqa(Some(codes)) => format!("# noqa: {}", codes.join(", ")), - SpecialComment::FileLevelNoqa { hint, codes: None } => Some(format!("# {hint}: noqa")), + SpecialComment::FileLevelNoqa { hint, codes: None } => format!("# {hint}: noqa"), - // Avoid suggesting the unsafe fix - // `# ruff: noqa:` (ignore nothing) -> `# ruff: noqa` (ignore everything). SpecialComment::FileLevelNoqa { - codes: Some(codes), .. - } if codes.is_empty() => None, + hint, codes: Some(codes) + } if codes.is_empty() => format!("# {hint}: noqa:"), SpecialComment::FileLevelNoqa { hint, codes: Some(codes), - } => Some(format!("# {hint}: noqa: {}", codes.join(", "))), + } => format!("# {hint}: noqa: {}", codes.join(", ")), - SpecialComment::Nopycln(rest) => Some(format!("# nopycln: {}", rest.to_lowercase())), + SpecialComment::Nopycln(rest) => format!("# nopycln: {}", rest.to_lowercase()), - SpecialComment::Fmt(rest) => Some(format!("# fmt: {rest}")), - SpecialComment::Isort(rest) => Some(format!("# isort: {rest}")), - SpecialComment::Mypy(rest) => Some(format!("# mypy: {rest}")), - SpecialComment::Pyright(rest) => Some(format!("# pyright: {rest}")), - SpecialComment::RuffIsort(rest) => Some(format!("# ruff: isort: {rest}")), - SpecialComment::Type(rest) => Some(format!("# type: {rest}")), + SpecialComment::Fmt(rest) => format!("# fmt: {rest}"), + SpecialComment::Isort(rest) => format!("# isort: {rest}"), + SpecialComment::Mypy(rest) => format!("# mypy: {rest}"), + SpecialComment::Pyright(rest) => format!("# pyright: {rest}"), + SpecialComment::RuffIsort(rest) => format!("# ruff: isort: {rest}"), + SpecialComment::Type(rest) => format!("# type: {rest}"), } } } @@ -121,9 +117,7 @@ fn add_diagnostic_if_applicable( comment_range: TextRange, hint_range: TextRange, ) { - let Some(formatted) = comment.formatted() else { - return; - }; + let formatted = comment.formatted(); if comment_text == formatted { return; @@ -138,15 +132,6 @@ fn add_diagnostic_if_applicable( diagnostics.push(diagnostic); } -fn parse_code_list(code_list: &str) -> Vec { - static PATTERN: LazyLock = LazyLock::new(|| Regex::new(r"[A-Z]+[A-Za-z0-9]+").unwrap()); - - PATTERN - .find_iter(code_list) - .map(|code| code.as_str().to_owned()) - .collect() -} - macro_rules! try_parse_common { ($pattern:ident, $text:ident, $special_comment:expr) => {{ let result = $pattern.captures($text)?; @@ -164,6 +149,16 @@ macro_rules! try_parse_common { } fn try_parse_noqa(text: &str) -> SpecialCommentDescriptor { + fn parse_code_list(code_list: &str) -> Vec { + static PATTERN: LazyLock = + LazyLock::new(|| Regex::new(r"[A-Z]+[0-9]+").unwrap()); + + PATTERN + .find_iter(code_list) + .map(|code| code.as_str().to_owned()) + .collect() + } + // ruff_linter::noqa::Directive::try_extract static PATTERN: LazyLock = LazyLock::new(|| { Regex::new( @@ -171,11 +166,12 @@ fn try_parse_noqa(text: &str) -> SpecialCommentDescriptor { ^ \#\s* (?(?i:noqa)) - (?: - :\s* - (? - [A-Z]+[A-Za-z0-9]+ - (?:[\s,]+[A-Z]+[A-Za-z0-9]+)* + (? + : + (?: + \s* + [A-Z]+[0-9]+ + (?:[\s,]+[A-Z]+[0-9]+)* )? )? ", @@ -195,6 +191,16 @@ fn try_parse_noqa(text: &str) -> SpecialCommentDescriptor { } fn try_parse_file_level_noqa(text: &str) -> SpecialCommentDescriptor { + fn parse_code_list(code_list: &str) -> Vec { + static PATTERN: LazyLock = + LazyLock::new(|| Regex::new(r"[A-Z]+[A-Za-z0-9]+").unwrap()); + + PATTERN + .find_iter(code_list) + .map(|code| code.as_str().to_owned()) + .collect() + } + // ruff_linter::noqa::ParsedFileExemption::try_extract static PATTERN: LazyLock = LazyLock::new(|| { Regex::new( @@ -203,13 +209,13 @@ fn try_parse_file_level_noqa(text: &str) -> SpecialCommentDescriptor { \#\s* (?flake8|ruff)\s*:\s* (?i:noqa)\s* - (?: - :\s* - (? + (? + : + (?: + \s* [A-Z]+[A-Za-z0-9]+ (?:[\s,]\s*[A-Z]+[A-Za-z0-9]+)* )? - \s* )? ", ) diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_3.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_3.py.snap new file mode 100644 index 00000000000000..dee275118a8773 --- /dev/null +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_3.py.snap @@ -0,0 +1,48 @@ +--- +source: crates/ruff_linter/src/rules/ruff/mod.rs +snapshot_kind: text +--- +RUF104_3.py:1:2: RUF104 [*] Unformatted special comment + | +1 | #noqa: + | ^^^^ RUF104 +2 | #ruff:noqa: +3 | #flake8:noqa: + | + = help: Format comment + +ℹ Safe fix +1 |-#noqa: + 1 |+# noqa: +2 2 | #ruff:noqa: +3 3 | #flake8:noqa: + +RUF104_3.py:2:2: RUF104 [*] Unformatted special comment + | +1 | #noqa: +2 | #ruff:noqa: + | ^^^^ RUF104 +3 | #flake8:noqa: + | + = help: Format comment + +ℹ Safe fix +1 1 | #noqa: +2 |-#ruff:noqa: + 2 |+# ruff: noqa: +3 3 | #flake8:noqa: + +RUF104_3.py:3:2: RUF104 [*] Unformatted special comment + | +1 | #noqa: +2 | #ruff:noqa: +3 | #flake8:noqa: + | ^^^^^^ RUF104 + | + = help: Format comment + +ℹ Safe fix +1 1 | #noqa: +2 2 | #ruff:noqa: +3 |-#flake8:noqa: + 3 |+# flake8: noqa: From 268edc3783991b8c0ce05a757833433d52e70f84 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Sun, 10 Nov 2024 16:41:32 +0000 Subject: [PATCH 20/29] Require that `RUF104` be suppressed correctly --- .../resources/test/fixtures/ruff/RUF104_1.py | 5 ++ .../resources/test/fixtures/ruff/RUF104_2.py | 5 ++ .../resources/test/fixtures/ruff/RUF104_3.py | 4 ++ crates/ruff_linter/src/checkers/noqa.rs | 16 ++++-- ...f__tests__preview__RUF104_RUF104_1.py.snap | 38 +++++++------ ...f__tests__preview__RUF104_RUF104_3.py.snap | 56 +++++++++++-------- 6 files changed, 78 insertions(+), 46 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_1.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_1.py index fbbd5fc4b7d25b..f95348f7941c32 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_1.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_1.py @@ -1,3 +1,8 @@ +### +# Both of these should trigger RUF104 +# as it is not explicitly suppressed. +### + # ruff:noqa #noqa:A123 diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_2.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_2.py index 63232eb4bbf84d..3c207b46a95e7a 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_2.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_2.py @@ -1,3 +1,8 @@ +### +# None of these should trigger RUF104 +# as it is explicitly suppressed for the entire file. +### + # flake8:noqa:RUF104 #noqa:A123 diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_3.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_3.py index ee359932d8246b..94129208af294a 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_3.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_3.py @@ -1,3 +1,7 @@ +### +# All of these should be reformatted. +### + #noqa: #ruff:noqa: #flake8:noqa: diff --git a/crates/ruff_linter/src/checkers/noqa.rs b/crates/ruff_linter/src/checkers/noqa.rs index 5143aadcdf17a7..f4eee0a90adef6 100644 --- a/crates/ruff_linter/src/checkers/noqa.rs +++ b/crates/ruff_linter/src/checkers/noqa.rs @@ -45,17 +45,21 @@ pub(crate) fn check_noqa( // Remove any ignored diagnostics. 'outer: for (index, diagnostic) in diagnostics.iter().enumerate() { - if matches!( - diagnostic.kind.rule(), - Rule::BlanketNOQA | Rule::UnformattedSpecialComment - ) { + if matches!(diagnostic.kind.rule(), Rule::BlanketNOQA) { continue; } match &exemption { FileExemption::All(_) => { - // If the file is exempted, ignore all diagnostics. - ignored_diagnostics.push(index); + // If the file is exempted, ignore all diagnostics, + // save for RUF104, which operates on `# noqa` comments + // and should thus need to be suppressed explicitly. + if !matches!(diagnostic.kind.rule(), Rule::UnformattedSpecialComment) + || per_file_ignores.contains(Rule::UnformattedSpecialComment) + || exemption.enumerates(Rule::UnformattedSpecialComment) + { + ignored_diagnostics.push(index); + } continue; } FileExemption::Codes(codes) => { diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_1.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_1.py.snap index 6997530a7c65d0..5a064931b349f9 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_1.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_1.py.snap @@ -2,32 +2,38 @@ source: crates/ruff_linter/src/rules/ruff/mod.rs snapshot_kind: text --- -RUF104_1.py:1:3: RUF104 [*] Unformatted special comment +RUF104_1.py:6:3: RUF104 [*] Unformatted special comment | -1 | # ruff:noqa +4 | ### +5 | +6 | # ruff:noqa | ^^^^ RUF104 -2 | -3 | #noqa:A123 +7 | +8 | #noqa:A123 | = help: Format comment ℹ Safe fix -1 |-# ruff:noqa - 1 |+# ruff: noqa -2 2 | -3 3 | #noqa:A123 +3 3 | # as it is not explicitly suppressed. +4 4 | ### +5 5 | +6 |-# ruff:noqa + 6 |+# ruff: noqa +7 7 | +8 8 | #noqa:A123 -RUF104_1.py:3:2: RUF104 [*] Unformatted special comment +RUF104_1.py:8:2: RUF104 [*] Unformatted special comment | -1 | # ruff:noqa -2 | -3 | #noqa:A123 +6 | # ruff:noqa +7 | +8 | #noqa:A123 | ^^^^ RUF104 | = help: Format comment ℹ Safe fix -1 1 | # ruff:noqa -2 2 | -3 |-#noqa:A123 - 3 |+# noqa: A123 +5 5 | +6 6 | # ruff:noqa +7 7 | +8 |-#noqa:A123 + 8 |+# noqa: A123 diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_3.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_3.py.snap index dee275118a8773..d20bae4421dff1 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_3.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_3.py.snap @@ -2,47 +2,55 @@ source: crates/ruff_linter/src/rules/ruff/mod.rs snapshot_kind: text --- -RUF104_3.py:1:2: RUF104 [*] Unformatted special comment +RUF104_3.py:5:2: RUF104 [*] Unformatted special comment | -1 | #noqa: +3 | ### +4 | +5 | #noqa: | ^^^^ RUF104 -2 | #ruff:noqa: -3 | #flake8:noqa: +6 | #ruff:noqa: +7 | #flake8:noqa: | = help: Format comment ℹ Safe fix -1 |-#noqa: - 1 |+# noqa: -2 2 | #ruff:noqa: -3 3 | #flake8:noqa: +2 2 | # All of these should be reformatted. +3 3 | ### +4 4 | +5 |-#noqa: + 5 |+# noqa: +6 6 | #ruff:noqa: +7 7 | #flake8:noqa: -RUF104_3.py:2:2: RUF104 [*] Unformatted special comment +RUF104_3.py:6:2: RUF104 [*] Unformatted special comment | -1 | #noqa: -2 | #ruff:noqa: +5 | #noqa: +6 | #ruff:noqa: | ^^^^ RUF104 -3 | #flake8:noqa: +7 | #flake8:noqa: | = help: Format comment ℹ Safe fix -1 1 | #noqa: -2 |-#ruff:noqa: - 2 |+# ruff: noqa: -3 3 | #flake8:noqa: +3 3 | ### +4 4 | +5 5 | #noqa: +6 |-#ruff:noqa: + 6 |+# ruff: noqa: +7 7 | #flake8:noqa: -RUF104_3.py:3:2: RUF104 [*] Unformatted special comment +RUF104_3.py:7:2: RUF104 [*] Unformatted special comment | -1 | #noqa: -2 | #ruff:noqa: -3 | #flake8:noqa: +5 | #noqa: +6 | #ruff:noqa: +7 | #flake8:noqa: | ^^^^^^ RUF104 | = help: Format comment ℹ Safe fix -1 1 | #noqa: -2 2 | #ruff:noqa: -3 |-#flake8:noqa: - 3 |+# flake8: noqa: +4 4 | +5 5 | #noqa: +6 6 | #ruff:noqa: +7 |-#flake8:noqa: + 7 |+# flake8: noqa: From e33b05c244a830746a25acbe3c74bb6f0d3adfa2 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Sun, 10 Nov 2024 16:45:43 +0000 Subject: [PATCH 21/29] `rustfmt` --- .../src/rules/ruff/rules/unformatted_special_comment.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index 74262d2bb73dd0..68b843aaadc899 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -50,7 +50,8 @@ impl SpecialComment { SpecialComment::FileLevelNoqa { hint, codes: None } => format!("# {hint}: noqa"), SpecialComment::FileLevelNoqa { - hint, codes: Some(codes) + hint, + codes: Some(codes), } if codes.is_empty() => format!("# {hint}: noqa:"), SpecialComment::FileLevelNoqa { @@ -150,8 +151,7 @@ macro_rules! try_parse_common { fn try_parse_noqa(text: &str) -> SpecialCommentDescriptor { fn parse_code_list(code_list: &str) -> Vec { - static PATTERN: LazyLock = - LazyLock::new(|| Regex::new(r"[A-Z]+[0-9]+").unwrap()); + static PATTERN: LazyLock = LazyLock::new(|| Regex::new(r"[A-Z]+[0-9]+").unwrap()); PATTERN .find_iter(code_list) From 9c5ec194216fd0bbe1e9b5b5be0476a122b72087 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Mon, 11 Nov 2024 06:05:46 +0000 Subject: [PATCH 22/29] Fix typo --- crates/ruff_linter/src/checkers/noqa.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ruff_linter/src/checkers/noqa.rs b/crates/ruff_linter/src/checkers/noqa.rs index f4eee0a90adef6..e01cb5ffea5874 100644 --- a/crates/ruff_linter/src/checkers/noqa.rs +++ b/crates/ruff_linter/src/checkers/noqa.rs @@ -53,7 +53,7 @@ pub(crate) fn check_noqa( FileExemption::All(_) => { // If the file is exempted, ignore all diagnostics, // save for RUF104, which operates on `# noqa` comments - // and should thus need to be suppressed explicitly. + // and thus needs to be suppressed explicitly. if !matches!(diagnostic.kind.rule(), Rule::UnformattedSpecialComment) || per_file_ignores.contains(Rule::UnformattedSpecialComment) || exemption.enumerates(Rule::UnformattedSpecialComment) From 1c1b7322268889eb624c9919488e4f8022274095 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Mon, 11 Nov 2024 13:51:20 +0000 Subject: [PATCH 23/29] Address review --- .../resources/test/fixtures/ruff/RUF104.py | 22 +- ...F104_3.py => RUF104_empty_suppressions.py} | 0 ...04_2.py => RUF104_explicit_suppression.py} | 0 ...04_1.py => RUF104_implicit_suppression.py} | 0 crates/ruff_linter/src/rules/ruff/mod.rs | 6 +- .../ruff/rules/unformatted_special_comment.rs | 67 +- ...uff__tests__preview__RUF104_RUF104.py.snap | 1121 +++++++---------- ..._RUF104_RUF104_empty_suppressions.py.snap} | 6 +- ...UF104_RUF104_explicit_suppression.py.snap} | 0 ...UF104_RUF104_implicit_suppression.py.snap} | 4 +- 10 files changed, 478 insertions(+), 748 deletions(-) rename crates/ruff_linter/resources/test/fixtures/ruff/{RUF104_3.py => RUF104_empty_suppressions.py} (100%) rename crates/ruff_linter/resources/test/fixtures/ruff/{RUF104_2.py => RUF104_explicit_suppression.py} (100%) rename crates/ruff_linter/resources/test/fixtures/ruff/{RUF104_1.py => RUF104_implicit_suppression.py} (100%) rename crates/ruff_linter/src/rules/ruff/snapshots/{ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_3.py.snap => ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_empty_suppressions.py.snap} (76%) rename crates/ruff_linter/src/rules/ruff/snapshots/{ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_2.py.snap => ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_explicit_suppression.py.snap} (100%) rename crates/ruff_linter/src/rules/ruff/snapshots/{ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_1.py.snap => ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_implicit_suppression.py.snap} (76%) diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py index 12eec796e6e606..3544f5bdac8b09 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py @@ -6,8 +6,6 @@ # FMT:OFF # isort: On -# Mypy: disallow-subclassing-any -# PyRight: basic # Type: ignore # noqa @@ -27,14 +25,6 @@ # isort: split # isort: skip # isort: skip_file -# mypy: enable-error-codes= -# nopycln: file -# nopycln: import -# pyright: basic -# pyright: standard -# pyright: strict -# pyright: ignore -# pyright: ignore [reportFoo] # ruff: isort: on # ruff: isort: skip_file # type: ignore @@ -50,11 +40,6 @@ # fmt: skip # isort:skip # isort:skip_file -# mypy: disallow-subclassing-any -# nopycln: file -# nopycln: import -#pyright:ignore[] -# pyright: ignore[] # ruff: isort:skip # ruff: isort:skip_file # type: ignore @@ -63,9 +48,6 @@ # NoQA: A123, B456 # ruff: NoQA: A123, B456 # flake8: NoQA: A123, B456 -# NoPyCLN: File -# NoPycln: Import -# nOpYcLn: iMpOrT # noqa: A123 B456 # ruff: noqa: A123 B456 @@ -85,8 +67,8 @@ # type: ignore # noqa: A123, B456 -#pyright:ignore#noqa:A123 +#isort:skip#noqa:A123 -# nopycln:file# noqa: A123 +# fmt:off# noqa: A123 # noqa:A123 - Lorem ipsum dolor sit amet diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_3.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_empty_suppressions.py similarity index 100% rename from crates/ruff_linter/resources/test/fixtures/ruff/RUF104_3.py rename to crates/ruff_linter/resources/test/fixtures/ruff/RUF104_empty_suppressions.py diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_2.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_explicit_suppression.py similarity index 100% rename from crates/ruff_linter/resources/test/fixtures/ruff/RUF104_2.py rename to crates/ruff_linter/resources/test/fixtures/ruff/RUF104_explicit_suppression.py diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_1.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_implicit_suppression.py similarity index 100% rename from crates/ruff_linter/resources/test/fixtures/ruff/RUF104_1.py rename to crates/ruff_linter/resources/test/fixtures/ruff/RUF104_implicit_suppression.py diff --git a/crates/ruff_linter/src/rules/ruff/mod.rs b/crates/ruff_linter/src/rules/ruff/mod.rs index 693a49d21cc3ba..14ada89e91f4fe 100644 --- a/crates/ruff_linter/src/rules/ruff/mod.rs +++ b/crates/ruff_linter/src/rules/ruff/mod.rs @@ -385,9 +385,9 @@ mod tests { #[test_case(Rule::ZipInsteadOfPairwise, Path::new("RUF007.py"))] #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104.py"))] - #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104_1.py"))] - #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104_2.py"))] - #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104_3.py"))] + #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104_implicit_suppression.py"))] + #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104_explicit_suppression.py"))] + #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104_empty_suppressions.py"))] fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> { let snapshot = format!( "preview__{}_{}", diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index 68b843aaadc899..0477a652aee67f 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -27,12 +27,6 @@ enum SpecialComment { /// `# isort: skip_file` Isort(String), /// `# mypy: ignore-errors` - Mypy(String), - /// `# nopycln: import` - Nopycln(String), - /// `# pyright: strict`, `# pyright: ignore[reportFoo]` - Pyright(String), - /// `# ruff: isort: skip_file` RuffIsort(String), /// `# type: int`, `# type: ignore` Type(String), @@ -59,12 +53,8 @@ impl SpecialComment { codes: Some(codes), } => format!("# {hint}: noqa: {}", codes.join(", ")), - SpecialComment::Nopycln(rest) => format!("# nopycln: {}", rest.to_lowercase()), - SpecialComment::Fmt(rest) => format!("# fmt: {rest}"), SpecialComment::Isort(rest) => format!("# isort: {rest}"), - SpecialComment::Mypy(rest) => format!("# mypy: {rest}"), - SpecialComment::Pyright(rest) => format!("# pyright: {rest}"), SpecialComment::RuffIsort(rest) => format!("# ruff: isort: {rest}"), SpecialComment::Type(rest) => format!("# type: {rest}"), } @@ -252,34 +242,6 @@ fn try_parse_isort(text: &str) -> SpecialCommentDescriptor { try_parse_common!(PATTERN, text, SpecialComment::Isort) } -fn try_parse_mypy(text: &str) -> SpecialCommentDescriptor { - // https://github.com/python/mypy/blob/3b00002acd/mypy/util.py#L228 - static PATTERN: LazyLock = - LazyLock::new(|| Regex::new(r"^# (?mypy):\s*(?\S)").unwrap()); - - try_parse_common!(PATTERN, text, SpecialComment::Mypy) -} - -fn try_parse_nopycln(text: &str) -> SpecialCommentDescriptor { - // https://github.com/hadialqattan/pycln/blob/d0aeb62860/pycln/utils/regexu.py#L18-L19 - // https://github.com/hadialqattan/pycln/blob/d0aeb62860/pycln/utils/regexu.py#L127 - // https://github.com/hadialqattan/pycln/blob/d0aeb62860/pycln/utils/regexu.py#L136 - static PATTERN: LazyLock = LazyLock::new(|| { - Regex::new(r"(?i)^#\s*(?nopycln)\s*:\s*(?file|import)").unwrap() - }); - - try_parse_common!(PATTERN, text, SpecialComment::Nopycln) -} - -fn try_parse_pyright(text: &str) -> SpecialCommentDescriptor { - // https://github.com/microsoft/pyright/blob/9d60c434c4/packages/pyright-internal/src/parser/tokenizer.ts#L1314 - // https://github.com/microsoft/pyright/blob/9d60c434c4/packages/pyright-internal/src/analyzer/commentUtils.ts#L138 - static PATTERN: LazyLock = - LazyLock::new(|| Regex::new(r"^#\s*(?pyright):\s*(?\S)").unwrap()); - - try_parse_common!(PATTERN, text, SpecialComment::Pyright) -} - fn try_parse_ruff_isort(text: &str) -> SpecialCommentDescriptor { // ruff_linter::directives::extract_isort_directives static PATTERN: LazyLock = @@ -338,9 +300,6 @@ fn check_single_comment(diagnostics: &mut Vec, text: &str, start_ind parse_and_handle_comment!(try_parse_file_level_noqa, text, diagnostics, start_index); parse_and_handle_comment!(try_parse_fmt, text, diagnostics, start_index); parse_and_handle_comment!(try_parse_isort, text, diagnostics, start_index); - parse_and_handle_comment!(try_parse_mypy, text, diagnostics, start_index); - parse_and_handle_comment!(try_parse_nopycln, text, diagnostics, start_index); - parse_and_handle_comment!(try_parse_pyright, text, diagnostics, start_index); parse_and_handle_comment!(try_parse_ruff_isort, text, diagnostics, start_index); parse_and_handle_comment!(try_parse_type, text, diagnostics, start_index); } @@ -432,8 +391,6 @@ mod tests { fn incorrect_casing() { no_unformatted("# FMT:OFF"); no_unformatted("# isort: On"); - no_unformatted("# Mypy: disallow-subclassing-any"); - no_unformatted("# PyRight: basic"); no_unformatted("# Type: ignore"); } @@ -461,17 +418,9 @@ mod tests { no_unformatted("# isort: skip"); no_unformatted("# isort: skip_file"); - no_unformatted("# mypy: enable-error-codes="); - no_unformatted("# nopycln: file"); no_unformatted("# nopycln: import"); - no_unformatted("# pyright: basic"); - no_unformatted("# pyright: standard"); - no_unformatted("# pyright: strict"); - no_unformatted("# pyright: ignore"); - no_unformatted("# pyright: ignore [reportFoo]"); - no_unformatted("# ruff: isort: on"); no_unformatted("# ruff: isort: skip_file"); @@ -495,14 +444,6 @@ mod tests { has_unformatted("# isort:skip"); has_unformatted("# isort:skip_file"); - has_unformatted("# mypy: disallow-subclassing-any"); - - has_unformatted("# nopycln: \t \t\tfile"); - has_unformatted("# \tnopycln:\t import"); - - has_unformatted("#pyright:ignore[]"); - has_unformatted("#\t\t\tpyright: ignore[]"); - has_unformatted("# ruff: isort:skip"); has_unformatted("# ruff: isort:skip_file"); @@ -515,10 +456,6 @@ mod tests { has_unformatted("# NoQA: A123, B456"); has_unformatted("# ruff: NoQA: A123, B456"); has_unformatted("# flake8: NoQA: A123, B456"); - - has_unformatted("# NoPyCLN: File"); - has_unformatted("# NoPycln: Import"); - has_unformatted("# nOpYcLn: iMpOrT"); } #[test] @@ -546,8 +483,8 @@ mod tests { fn composite() { composite_no_unformatted("# type: ignore # noqa: A123, B456"); - composite_has_unformatted("#pyright:ignore#noqa:A123", 2); - composite_has_unformatted("# nopycln:file# noqa: A123", 2); + composite_has_unformatted("#isort:skip#noqa:A123", 2); + composite_has_unformatted("# fmt:off# noqa: A123", 2); composite_has_unformatted("# noqa:A123 - Lorem ipsum dolor sit amet", 1); } } diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap index 51bf4e059dd5ef..9a37dfd7671319 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap @@ -2,890 +2,701 @@ source: crates/ruff_linter/src/rules/ruff/mod.rs snapshot_kind: text --- -RUF104.py:44:3: RUF104 [*] Unformatted special comment +RUF104.py:34:3: RUF104 [*] Unformatted special comment | -42 | # type: list[str] -43 | -44 | # noqa:A123 +32 | # type: list[str] +33 | +34 | # noqa:A123 | ^^^^ RUF104 -45 | #noqa: A123 -46 | # type:ignore +35 | #noqa: A123 +36 | # type:ignore | = help: Format comment ℹ Safe fix -41 41 | # type: int -42 42 | # type: list[str] -43 43 | -44 |-# noqa:A123 - 44 |+# noqa: A123 -45 45 | #noqa: A123 -46 46 | # type:ignore -47 47 | #type: int +31 31 | # type: int +32 32 | # type: list[str] +33 33 | +34 |-# noqa:A123 + 34 |+# noqa: A123 +35 35 | #noqa: A123 +36 36 | # type:ignore +37 37 | #type: int -RUF104.py:45:2: RUF104 [*] Unformatted special comment +RUF104.py:35:2: RUF104 [*] Unformatted special comment | -44 | # noqa:A123 -45 | #noqa: A123 +34 | # noqa:A123 +35 | #noqa: A123 | ^^^^ RUF104 -46 | # type:ignore -47 | #type: int +36 | # type:ignore +37 | #type: int | = help: Format comment ℹ Safe fix -42 42 | # type: list[str] -43 43 | -44 44 | # noqa:A123 -45 |-#noqa: A123 - 45 |+# noqa: A123 -46 46 | # type:ignore -47 47 | #type: int -48 48 | # fmt:off +32 32 | # type: list[str] +33 33 | +34 34 | # noqa:A123 +35 |-#noqa: A123 + 35 |+# noqa: A123 +36 36 | # type:ignore +37 37 | #type: int +38 38 | # fmt:off -RUF104.py:46:6: RUF104 [*] Unformatted special comment +RUF104.py:36:6: RUF104 [*] Unformatted special comment | -44 | # noqa:A123 -45 | #noqa: A123 -46 | # type:ignore +34 | # noqa:A123 +35 | #noqa: A123 +36 | # type:ignore | ^^^^ RUF104 -47 | #type: int -48 | # fmt:off +37 | #type: int +38 | # fmt:off | = help: Format comment ℹ Safe fix -43 43 | -44 44 | # noqa:A123 -45 45 | #noqa: A123 -46 |-# type:ignore - 46 |+# type: ignore -47 47 | #type: int -48 48 | # fmt:off -49 49 | #fmt: on +33 33 | +34 34 | # noqa:A123 +35 35 | #noqa: A123 +36 |-# type:ignore + 36 |+# type: ignore +37 37 | #type: int +38 38 | # fmt:off +39 39 | #fmt: on -RUF104.py:47:2: RUF104 [*] Unformatted special comment +RUF104.py:37:2: RUF104 [*] Unformatted special comment | -45 | #noqa: A123 -46 | # type:ignore -47 | #type: int +35 | #noqa: A123 +36 | # type:ignore +37 | #type: int | ^^^^ RUF104 -48 | # fmt:off -49 | #fmt: on +38 | # fmt:off +39 | #fmt: on | = help: Format comment ℹ Safe fix -44 44 | # noqa:A123 -45 45 | #noqa: A123 -46 46 | # type:ignore -47 |-#type: int - 47 |+# type: int -48 48 | # fmt:off -49 49 | #fmt: on -50 50 | # fmt: skip +34 34 | # noqa:A123 +35 35 | #noqa: A123 +36 36 | # type:ignore +37 |-#type: int + 37 |+# type: int +38 38 | # fmt:off +39 39 | #fmt: on +40 40 | # fmt: skip -RUF104.py:48:3: RUF104 [*] Unformatted special comment +RUF104.py:38:3: RUF104 [*] Unformatted special comment | -46 | # type:ignore -47 | #type: int -48 | # fmt:off +36 | # type:ignore +37 | #type: int +38 | # fmt:off | ^^^ RUF104 -49 | #fmt: on -50 | # fmt: skip +39 | #fmt: on +40 | # fmt: skip | = help: Format comment ℹ Safe fix -45 45 | #noqa: A123 -46 46 | # type:ignore -47 47 | #type: int -48 |-# fmt:off - 48 |+# fmt: off -49 49 | #fmt: on -50 50 | # fmt: skip -51 51 | # isort:skip +35 35 | #noqa: A123 +36 36 | # type:ignore +37 37 | #type: int +38 |-# fmt:off + 38 |+# fmt: off +39 39 | #fmt: on +40 40 | # fmt: skip +41 41 | # isort:skip -RUF104.py:49:2: RUF104 [*] Unformatted special comment +RUF104.py:39:2: RUF104 [*] Unformatted special comment | -47 | #type: int -48 | # fmt:off -49 | #fmt: on +37 | #type: int +38 | # fmt:off +39 | #fmt: on | ^^^ RUF104 -50 | # fmt: skip -51 | # isort:skip +40 | # fmt: skip +41 | # isort:skip | = help: Format comment ℹ Safe fix -46 46 | # type:ignore -47 47 | #type: int -48 48 | # fmt:off -49 |-#fmt: on - 49 |+# fmt: on -50 50 | # fmt: skip -51 51 | # isort:skip -52 52 | # isort:skip_file +36 36 | # type:ignore +37 37 | #type: int +38 38 | # fmt:off +39 |-#fmt: on + 39 |+# fmt: on +40 40 | # fmt: skip +41 41 | # isort:skip +42 42 | # isort:skip_file -RUF104.py:50:5: RUF104 [*] Unformatted special comment +RUF104.py:40:5: RUF104 [*] Unformatted special comment | -48 | # fmt:off -49 | #fmt: on -50 | # fmt: skip +38 | # fmt:off +39 | #fmt: on +40 | # fmt: skip | ^^^ RUF104 -51 | # isort:skip -52 | # isort:skip_file +41 | # isort:skip +42 | # isort:skip_file | = help: Format comment ℹ Safe fix -47 47 | #type: int -48 48 | # fmt:off -49 49 | #fmt: on -50 |-# fmt: skip - 50 |+# fmt: skip -51 51 | # isort:skip -52 52 | # isort:skip_file -53 53 | # mypy: disallow-subclassing-any +37 37 | #type: int +38 38 | # fmt:off +39 39 | #fmt: on +40 |-# fmt: skip + 40 |+# fmt: skip +41 41 | # isort:skip +42 42 | # isort:skip_file +43 43 | # ruff: isort:skip -RUF104.py:51:3: RUF104 [*] Unformatted special comment +RUF104.py:41:3: RUF104 [*] Unformatted special comment | -49 | #fmt: on -50 | # fmt: skip -51 | # isort:skip +39 | #fmt: on +40 | # fmt: skip +41 | # isort:skip | ^^^^^ RUF104 -52 | # isort:skip_file -53 | # mypy: disallow-subclassing-any +42 | # isort:skip_file +43 | # ruff: isort:skip | = help: Format comment ℹ Safe fix -48 48 | # fmt:off -49 49 | #fmt: on -50 50 | # fmt: skip -51 |-# isort:skip - 51 |+# isort: skip -52 52 | # isort:skip_file -53 53 | # mypy: disallow-subclassing-any -54 54 | # nopycln: file +38 38 | # fmt:off +39 39 | #fmt: on +40 40 | # fmt: skip +41 |-# isort:skip + 41 |+# isort: skip +42 42 | # isort:skip_file +43 43 | # ruff: isort:skip +44 44 | # ruff: isort:skip_file -RUF104.py:52:3: RUF104 [*] Unformatted special comment +RUF104.py:42:3: RUF104 [*] Unformatted special comment | -50 | # fmt: skip -51 | # isort:skip -52 | # isort:skip_file +40 | # fmt: skip +41 | # isort:skip +42 | # isort:skip_file | ^^^^^ RUF104 -53 | # mypy: disallow-subclassing-any -54 | # nopycln: file - | - = help: Format comment - -ℹ Safe fix -49 49 | #fmt: on -50 50 | # fmt: skip -51 51 | # isort:skip -52 |-# isort:skip_file - 52 |+# isort: skip_file -53 53 | # mypy: disallow-subclassing-any -54 54 | # nopycln: file -55 55 | # nopycln: import - -RUF104.py:53:3: RUF104 [*] Unformatted special comment - | -51 | # isort:skip -52 | # isort:skip_file -53 | # mypy: disallow-subclassing-any - | ^^^^ RUF104 -54 | # nopycln: file -55 | # nopycln: import - | - = help: Format comment - -ℹ Safe fix -50 50 | # fmt: skip -51 51 | # isort:skip -52 52 | # isort:skip_file -53 |-# mypy: disallow-subclassing-any - 53 |+# mypy: disallow-subclassing-any -54 54 | # nopycln: file -55 55 | # nopycln: import -56 56 | #pyright:ignore[] - -RUF104.py:54:5: RUF104 [*] Unformatted special comment - | -52 | # isort:skip_file -53 | # mypy: disallow-subclassing-any -54 | # nopycln: file - | ^^^^^^^ RUF104 -55 | # nopycln: import -56 | #pyright:ignore[] - | - = help: Format comment - -ℹ Safe fix -51 51 | # isort:skip -52 52 | # isort:skip_file -53 53 | # mypy: disallow-subclassing-any -54 |-# nopycln: file - 54 |+# nopycln: file -55 55 | # nopycln: import -56 56 | #pyright:ignore[] -57 57 | # pyright: ignore[] - -RUF104.py:55:4: RUF104 [*] Unformatted special comment - | -53 | # mypy: disallow-subclassing-any -54 | # nopycln: file -55 | # nopycln: import - | ^^^^^^^ RUF104 -56 | #pyright:ignore[] -57 | # pyright: ignore[] - | - = help: Format comment - -ℹ Safe fix -52 52 | # isort:skip_file -53 53 | # mypy: disallow-subclassing-any -54 54 | # nopycln: file -55 |-# nopycln: import - 55 |+# nopycln: import -56 56 | #pyright:ignore[] -57 57 | # pyright: ignore[] -58 58 | # ruff: isort:skip - -RUF104.py:56:2: RUF104 [*] Unformatted special comment - | -54 | # nopycln: file -55 | # nopycln: import -56 | #pyright:ignore[] - | ^^^^^^^ RUF104 -57 | # pyright: ignore[] -58 | # ruff: isort:skip +43 | # ruff: isort:skip +44 | # ruff: isort:skip_file | = help: Format comment ℹ Safe fix -53 53 | # mypy: disallow-subclassing-any -54 54 | # nopycln: file -55 55 | # nopycln: import -56 |-#pyright:ignore[] - 56 |+# pyright: ignore[] -57 57 | # pyright: ignore[] -58 58 | # ruff: isort:skip -59 59 | # ruff: isort:skip_file +39 39 | #fmt: on +40 40 | # fmt: skip +41 41 | # isort:skip +42 |-# isort:skip_file + 42 |+# isort: skip_file +43 43 | # ruff: isort:skip +44 44 | # ruff: isort:skip_file +45 45 | # type: ignore -RUF104.py:57:5: RUF104 [*] Unformatted special comment +RUF104.py:43:3: RUF104 [*] Unformatted special comment | -55 | # nopycln: import -56 | #pyright:ignore[] -57 | # pyright: ignore[] - | ^^^^^^^ RUF104 -58 | # ruff: isort:skip -59 | # ruff: isort:skip_file - | - = help: Format comment - -ℹ Safe fix -54 54 | # nopycln: file -55 55 | # nopycln: import -56 56 | #pyright:ignore[] -57 |-# pyright: ignore[] - 57 |+# pyright: ignore[] -58 58 | # ruff: isort:skip -59 59 | # ruff: isort:skip_file -60 60 | # type: ignore - -RUF104.py:58:3: RUF104 [*] Unformatted special comment - | -56 | #pyright:ignore[] -57 | # pyright: ignore[] -58 | # ruff: isort:skip +41 | # isort:skip +42 | # isort:skip_file +43 | # ruff: isort:skip | ^^^^ RUF104 -59 | # ruff: isort:skip_file -60 | # type: ignore +44 | # ruff: isort:skip_file +45 | # type: ignore | = help: Format comment ℹ Safe fix -55 55 | # nopycln: import -56 56 | #pyright:ignore[] -57 57 | # pyright: ignore[] -58 |-# ruff: isort:skip - 58 |+# ruff: isort: skip -59 59 | # ruff: isort:skip_file -60 60 | # type: ignore -61 61 | # type: int +40 40 | # fmt: skip +41 41 | # isort:skip +42 42 | # isort:skip_file +43 |-# ruff: isort:skip + 43 |+# ruff: isort: skip +44 44 | # ruff: isort:skip_file +45 45 | # type: ignore +46 46 | # type: int -RUF104.py:59:3: RUF104 [*] Unformatted special comment +RUF104.py:44:3: RUF104 [*] Unformatted special comment | -57 | # pyright: ignore[] -58 | # ruff: isort:skip -59 | # ruff: isort:skip_file +42 | # isort:skip_file +43 | # ruff: isort:skip +44 | # ruff: isort:skip_file | ^^^^ RUF104 -60 | # type: ignore -61 | # type: int +45 | # type: ignore +46 | # type: int | = help: Format comment ℹ Safe fix -56 56 | #pyright:ignore[] -57 57 | # pyright: ignore[] -58 58 | # ruff: isort:skip -59 |-# ruff: isort:skip_file - 59 |+# ruff: isort: skip_file -60 60 | # type: ignore -61 61 | # type: int -62 62 | +41 41 | # isort:skip +42 42 | # isort:skip_file +43 43 | # ruff: isort:skip +44 |-# ruff: isort:skip_file + 44 |+# ruff: isort: skip_file +45 45 | # type: ignore +46 46 | # type: int +47 47 | -RUF104.py:60:6: RUF104 [*] Unformatted special comment +RUF104.py:45:6: RUF104 [*] Unformatted special comment | -58 | # ruff: isort:skip -59 | # ruff: isort:skip_file -60 | # type: ignore +43 | # ruff: isort:skip +44 | # ruff: isort:skip_file +45 | # type: ignore | ^^^^ RUF104 -61 | # type: int +46 | # type: int | = help: Format comment ℹ Safe fix -57 57 | # pyright: ignore[] -58 58 | # ruff: isort:skip -59 59 | # ruff: isort:skip_file -60 |-# type: ignore - 60 |+# type: ignore -61 61 | # type: int -62 62 | -63 63 | # NoQA: A123, B456 +42 42 | # isort:skip_file +43 43 | # ruff: isort:skip +44 44 | # ruff: isort:skip_file +45 |-# type: ignore + 45 |+# type: ignore +46 46 | # type: int +47 47 | +48 48 | # NoQA: A123, B456 -RUF104.py:61:7: RUF104 [*] Unformatted special comment +RUF104.py:46:7: RUF104 [*] Unformatted special comment | -59 | # ruff: isort:skip_file -60 | # type: ignore -61 | # type: int +44 | # ruff: isort:skip_file +45 | # type: ignore +46 | # type: int | ^^^^ RUF104 -62 | -63 | # NoQA: A123, B456 +47 | +48 | # NoQA: A123, B456 | = help: Format comment ℹ Safe fix -58 58 | # ruff: isort:skip -59 59 | # ruff: isort:skip_file -60 60 | # type: ignore -61 |-# type: int - 61 |+# type: int -62 62 | -63 63 | # NoQA: A123, B456 -64 64 | # ruff: NoQA: A123, B456 +43 43 | # ruff: isort:skip +44 44 | # ruff: isort:skip_file +45 45 | # type: ignore +46 |-# type: int + 46 |+# type: int +47 47 | +48 48 | # NoQA: A123, B456 +49 49 | # ruff: NoQA: A123, B456 -RUF104.py:63:3: RUF104 [*] Unformatted special comment +RUF104.py:48:3: RUF104 [*] Unformatted special comment | -61 | # type: int -62 | -63 | # NoQA: A123, B456 +46 | # type: int +47 | +48 | # NoQA: A123, B456 | ^^^^ RUF104 -64 | # ruff: NoQA: A123, B456 -65 | # flake8: NoQA: A123, B456 +49 | # ruff: NoQA: A123, B456 +50 | # flake8: NoQA: A123, B456 | = help: Format comment ℹ Safe fix -60 60 | # type: ignore -61 61 | # type: int -62 62 | -63 |-# NoQA: A123, B456 - 63 |+# noqa: A123, B456 -64 64 | # ruff: NoQA: A123, B456 -65 65 | # flake8: NoQA: A123, B456 -66 66 | # NoPyCLN: File +45 45 | # type: ignore +46 46 | # type: int +47 47 | +48 |-# NoQA: A123, B456 + 48 |+# noqa: A123, B456 +49 49 | # ruff: NoQA: A123, B456 +50 50 | # flake8: NoQA: A123, B456 +51 51 | -RUF104.py:64:3: RUF104 [*] Unformatted special comment +RUF104.py:49:3: RUF104 [*] Unformatted special comment | -63 | # NoQA: A123, B456 -64 | # ruff: NoQA: A123, B456 +48 | # NoQA: A123, B456 +49 | # ruff: NoQA: A123, B456 | ^^^^ RUF104 -65 | # flake8: NoQA: A123, B456 -66 | # NoPyCLN: File +50 | # flake8: NoQA: A123, B456 | = help: Format comment ℹ Safe fix -61 61 | # type: int -62 62 | -63 63 | # NoQA: A123, B456 -64 |-# ruff: NoQA: A123, B456 - 64 |+# ruff: noqa: A123, B456 -65 65 | # flake8: NoQA: A123, B456 -66 66 | # NoPyCLN: File -67 67 | # NoPycln: Import +46 46 | # type: int +47 47 | +48 48 | # NoQA: A123, B456 +49 |-# ruff: NoQA: A123, B456 + 49 |+# ruff: noqa: A123, B456 +50 50 | # flake8: NoQA: A123, B456 +51 51 | +52 52 | # noqa: A123 B456 -RUF104.py:65:3: RUF104 [*] Unformatted special comment +RUF104.py:50:3: RUF104 [*] Unformatted special comment | -63 | # NoQA: A123, B456 -64 | # ruff: NoQA: A123, B456 -65 | # flake8: NoQA: A123, B456 +48 | # NoQA: A123, B456 +49 | # ruff: NoQA: A123, B456 +50 | # flake8: NoQA: A123, B456 | ^^^^^^ RUF104 -66 | # NoPyCLN: File -67 | # NoPycln: Import +51 | +52 | # noqa: A123 B456 | = help: Format comment ℹ Safe fix -62 62 | -63 63 | # NoQA: A123, B456 -64 64 | # ruff: NoQA: A123, B456 -65 |-# flake8: NoQA: A123, B456 - 65 |+# flake8: noqa: A123, B456 -66 66 | # NoPyCLN: File -67 67 | # NoPycln: Import -68 68 | # nOpYcLn: iMpOrT - -RUF104.py:66:3: RUF104 [*] Unformatted special comment - | -64 | # ruff: NoQA: A123, B456 -65 | # flake8: NoQA: A123, B456 -66 | # NoPyCLN: File - | ^^^^^^^ RUF104 -67 | # NoPycln: Import -68 | # nOpYcLn: iMpOrT - | - = help: Format comment +47 47 | +48 48 | # NoQA: A123, B456 +49 49 | # ruff: NoQA: A123, B456 +50 |-# flake8: NoQA: A123, B456 + 50 |+# flake8: noqa: A123, B456 +51 51 | +52 52 | # noqa: A123 B456 +53 53 | # ruff: noqa: A123 B456 -ℹ Safe fix -63 63 | # NoQA: A123, B456 -64 64 | # ruff: NoQA: A123, B456 -65 65 | # flake8: NoQA: A123, B456 -66 |-# NoPyCLN: File - 66 |+# nopycln: file -67 67 | # NoPycln: Import -68 68 | # nOpYcLn: iMpOrT -69 69 | - -RUF104.py:67:3: RUF104 [*] Unformatted special comment - | -65 | # flake8: NoQA: A123, B456 -66 | # NoPyCLN: File -67 | # NoPycln: Import - | ^^^^^^^ RUF104 -68 | # nOpYcLn: iMpOrT - | - = help: Format comment - -ℹ Safe fix -64 64 | # ruff: NoQA: A123, B456 -65 65 | # flake8: NoQA: A123, B456 -66 66 | # NoPyCLN: File -67 |-# NoPycln: Import - 67 |+# nopycln: import -68 68 | # nOpYcLn: iMpOrT -69 69 | -70 70 | # noqa: A123 B456 - -RUF104.py:68:3: RUF104 [*] Unformatted special comment - | -66 | # NoPyCLN: File -67 | # NoPycln: Import -68 | # nOpYcLn: iMpOrT - | ^^^^^^^ RUF104 -69 | -70 | # noqa: A123 B456 - | - = help: Format comment - -ℹ Safe fix -65 65 | # flake8: NoQA: A123, B456 -66 66 | # NoPyCLN: File -67 67 | # NoPycln: Import -68 |-# nOpYcLn: iMpOrT - 68 |+# nopycln: import -69 69 | -70 70 | # noqa: A123 B456 -71 71 | # ruff: noqa: A123 B456 - -RUF104.py:70:3: RUF104 [*] Unformatted special comment +RUF104.py:52:3: RUF104 [*] Unformatted special comment | -68 | # nOpYcLn: iMpOrT -69 | -70 | # noqa: A123 B456 +50 | # flake8: NoQA: A123, B456 +51 | +52 | # noqa: A123 B456 | ^^^^ RUF104 -71 | # ruff: noqa: A123 B456 -72 | # flake8: noqa: A123 B456 +53 | # ruff: noqa: A123 B456 +54 | # flake8: noqa: A123 B456 | = help: Format comment ℹ Safe fix -67 67 | # NoPycln: Import -68 68 | # nOpYcLn: iMpOrT -69 69 | -70 |-# noqa: A123 B456 - 70 |+# noqa: A123, B456 -71 71 | # ruff: noqa: A123 B456 -72 72 | # flake8: noqa: A123 B456 -73 73 | # noqa: A123,B456 +49 49 | # ruff: NoQA: A123, B456 +50 50 | # flake8: NoQA: A123, B456 +51 51 | +52 |-# noqa: A123 B456 + 52 |+# noqa: A123, B456 +53 53 | # ruff: noqa: A123 B456 +54 54 | # flake8: noqa: A123 B456 +55 55 | # noqa: A123,B456 -RUF104.py:71:3: RUF104 [*] Unformatted special comment +RUF104.py:53:3: RUF104 [*] Unformatted special comment | -70 | # noqa: A123 B456 -71 | # ruff: noqa: A123 B456 +52 | # noqa: A123 B456 +53 | # ruff: noqa: A123 B456 | ^^^^ RUF104 -72 | # flake8: noqa: A123 B456 -73 | # noqa: A123,B456 +54 | # flake8: noqa: A123 B456 +55 | # noqa: A123,B456 | = help: Format comment ℹ Safe fix -68 68 | # nOpYcLn: iMpOrT -69 69 | -70 70 | # noqa: A123 B456 -71 |-# ruff: noqa: A123 B456 - 71 |+# ruff: noqa: A123, B456 -72 72 | # flake8: noqa: A123 B456 -73 73 | # noqa: A123,B456 -74 74 | # ruff: noqa: A123,B456 +50 50 | # flake8: NoQA: A123, B456 +51 51 | +52 52 | # noqa: A123 B456 +53 |-# ruff: noqa: A123 B456 + 53 |+# ruff: noqa: A123, B456 +54 54 | # flake8: noqa: A123 B456 +55 55 | # noqa: A123,B456 +56 56 | # ruff: noqa: A123,B456 -RUF104.py:72:3: RUF104 [*] Unformatted special comment +RUF104.py:54:3: RUF104 [*] Unformatted special comment | -70 | # noqa: A123 B456 -71 | # ruff: noqa: A123 B456 -72 | # flake8: noqa: A123 B456 +52 | # noqa: A123 B456 +53 | # ruff: noqa: A123 B456 +54 | # flake8: noqa: A123 B456 | ^^^^^^ RUF104 -73 | # noqa: A123,B456 -74 | # ruff: noqa: A123,B456 +55 | # noqa: A123,B456 +56 | # ruff: noqa: A123,B456 | = help: Format comment ℹ Safe fix -69 69 | -70 70 | # noqa: A123 B456 -71 71 | # ruff: noqa: A123 B456 -72 |-# flake8: noqa: A123 B456 - 72 |+# flake8: noqa: A123, B456 -73 73 | # noqa: A123,B456 -74 74 | # ruff: noqa: A123,B456 -75 75 | # flake8: noqa: A123,B456 - -RUF104.py:73:3: RUF104 [*] Unformatted special comment - | -71 | # ruff: noqa: A123 B456 -72 | # flake8: noqa: A123 B456 -73 | # noqa: A123,B456 +51 51 | +52 52 | # noqa: A123 B456 +53 53 | # ruff: noqa: A123 B456 +54 |-# flake8: noqa: A123 B456 + 54 |+# flake8: noqa: A123, B456 +55 55 | # noqa: A123,B456 +56 56 | # ruff: noqa: A123,B456 +57 57 | # flake8: noqa: A123,B456 + +RUF104.py:55:3: RUF104 [*] Unformatted special comment + | +53 | # ruff: noqa: A123 B456 +54 | # flake8: noqa: A123 B456 +55 | # noqa: A123,B456 | ^^^^ RUF104 -74 | # ruff: noqa: A123,B456 -75 | # flake8: noqa: A123,B456 +56 | # ruff: noqa: A123,B456 +57 | # flake8: noqa: A123,B456 | = help: Format comment ℹ Safe fix -70 70 | # noqa: A123 B456 -71 71 | # ruff: noqa: A123 B456 -72 72 | # flake8: noqa: A123 B456 -73 |-# noqa: A123,B456 - 73 |+# noqa: A123, B456 -74 74 | # ruff: noqa: A123,B456 -75 75 | # flake8: noqa: A123,B456 -76 76 | # noqa: A123,,B456 +52 52 | # noqa: A123 B456 +53 53 | # ruff: noqa: A123 B456 +54 54 | # flake8: noqa: A123 B456 +55 |-# noqa: A123,B456 + 55 |+# noqa: A123, B456 +56 56 | # ruff: noqa: A123,B456 +57 57 | # flake8: noqa: A123,B456 +58 58 | # noqa: A123,,B456 -RUF104.py:74:3: RUF104 [*] Unformatted special comment +RUF104.py:56:3: RUF104 [*] Unformatted special comment | -72 | # flake8: noqa: A123 B456 -73 | # noqa: A123,B456 -74 | # ruff: noqa: A123,B456 +54 | # flake8: noqa: A123 B456 +55 | # noqa: A123,B456 +56 | # ruff: noqa: A123,B456 | ^^^^ RUF104 -75 | # flake8: noqa: A123,B456 -76 | # noqa: A123,,B456 +57 | # flake8: noqa: A123,B456 +58 | # noqa: A123,,B456 | = help: Format comment ℹ Safe fix -71 71 | # ruff: noqa: A123 B456 -72 72 | # flake8: noqa: A123 B456 -73 73 | # noqa: A123,B456 -74 |-# ruff: noqa: A123,B456 - 74 |+# ruff: noqa: A123, B456 -75 75 | # flake8: noqa: A123,B456 -76 76 | # noqa: A123,,B456 -77 77 | # noqa: A123 , , B456 +53 53 | # ruff: noqa: A123 B456 +54 54 | # flake8: noqa: A123 B456 +55 55 | # noqa: A123,B456 +56 |-# ruff: noqa: A123,B456 + 56 |+# ruff: noqa: A123, B456 +57 57 | # flake8: noqa: A123,B456 +58 58 | # noqa: A123,,B456 +59 59 | # noqa: A123 , , B456 -RUF104.py:75:3: RUF104 [*] Unformatted special comment +RUF104.py:57:3: RUF104 [*] Unformatted special comment | -73 | # noqa: A123,B456 -74 | # ruff: noqa: A123,B456 -75 | # flake8: noqa: A123,B456 +55 | # noqa: A123,B456 +56 | # ruff: noqa: A123,B456 +57 | # flake8: noqa: A123,B456 | ^^^^^^ RUF104 -76 | # noqa: A123,,B456 -77 | # noqa: A123 , , B456 +58 | # noqa: A123,,B456 +59 | # noqa: A123 , , B456 | = help: Format comment ℹ Safe fix -72 72 | # flake8: noqa: A123 B456 -73 73 | # noqa: A123,B456 -74 74 | # ruff: noqa: A123,B456 -75 |-# flake8: noqa: A123,B456 - 75 |+# flake8: noqa: A123, B456 -76 76 | # noqa: A123,,B456 -77 77 | # noqa: A123 , , B456 -78 78 | # noqa: A123 B456 +54 54 | # flake8: noqa: A123 B456 +55 55 | # noqa: A123,B456 +56 56 | # ruff: noqa: A123,B456 +57 |-# flake8: noqa: A123,B456 + 57 |+# flake8: noqa: A123, B456 +58 58 | # noqa: A123,,B456 +59 59 | # noqa: A123 , , B456 +60 60 | # noqa: A123 B456 -RUF104.py:76:3: RUF104 [*] Unformatted special comment +RUF104.py:58:3: RUF104 [*] Unformatted special comment | -74 | # ruff: noqa: A123,B456 -75 | # flake8: noqa: A123,B456 -76 | # noqa: A123,,B456 +56 | # ruff: noqa: A123,B456 +57 | # flake8: noqa: A123,B456 +58 | # noqa: A123,,B456 | ^^^^ RUF104 -77 | # noqa: A123 , , B456 -78 | # noqa: A123 B456 +59 | # noqa: A123 , , B456 +60 | # noqa: A123 B456 | = help: Format comment ℹ Safe fix -73 73 | # noqa: A123,B456 -74 74 | # ruff: noqa: A123,B456 -75 75 | # flake8: noqa: A123,B456 -76 |-# noqa: A123,,B456 - 76 |+# noqa: A123, B456 -77 77 | # noqa: A123 , , B456 -78 78 | # noqa: A123 B456 -79 79 | # noqa: A123 B456 +55 55 | # noqa: A123,B456 +56 56 | # ruff: noqa: A123,B456 +57 57 | # flake8: noqa: A123,B456 +58 |-# noqa: A123,,B456 + 58 |+# noqa: A123, B456 +59 59 | # noqa: A123 , , B456 +60 60 | # noqa: A123 B456 +61 61 | # noqa: A123 B456 -RUF104.py:77:3: RUF104 [*] Unformatted special comment +RUF104.py:59:3: RUF104 [*] Unformatted special comment | -75 | # flake8: noqa: A123,B456 -76 | # noqa: A123,,B456 -77 | # noqa: A123 , , B456 +57 | # flake8: noqa: A123,B456 +58 | # noqa: A123,,B456 +59 | # noqa: A123 , , B456 | ^^^^ RUF104 -78 | # noqa: A123 B456 -79 | # noqa: A123 B456 +60 | # noqa: A123 B456 +61 | # noqa: A123 B456 | = help: Format comment ℹ Safe fix -74 74 | # ruff: noqa: A123,B456 -75 75 | # flake8: noqa: A123,B456 -76 76 | # noqa: A123,,B456 -77 |-# noqa: A123 , , B456 - 77 |+# noqa: A123, B456 -78 78 | # noqa: A123 B456 -79 79 | # noqa: A123 B456 -80 80 | # noqa: A123 B456 +56 56 | # ruff: noqa: A123,B456 +57 57 | # flake8: noqa: A123,B456 +58 58 | # noqa: A123,,B456 +59 |-# noqa: A123 , , B456 + 59 |+# noqa: A123, B456 +60 60 | # noqa: A123 B456 +61 61 | # noqa: A123 B456 +62 62 | # noqa: A123 B456 -RUF104.py:78:3: RUF104 [*] Unformatted special comment +RUF104.py:60:3: RUF104 [*] Unformatted special comment | -76 | # noqa: A123,,B456 -77 | # noqa: A123 , , B456 -78 | # noqa: A123 B456 +58 | # noqa: A123,,B456 +59 | # noqa: A123 , , B456 +60 | # noqa: A123 B456 | ^^^^ RUF104 -79 | # noqa: A123 B456 -80 | # noqa: A123 B456 +61 | # noqa: A123 B456 +62 | # noqa: A123 B456 | = help: Format comment ℹ Safe fix -75 75 | # flake8: noqa: A123,B456 -76 76 | # noqa: A123,,B456 -77 77 | # noqa: A123 , , B456 -78 |-# noqa: A123 B456 - 78 |+# noqa: A123, B456 -79 79 | # noqa: A123 B456 -80 80 | # noqa: A123 B456 -81 81 | # noqa: A123 ,B456 +57 57 | # flake8: noqa: A123,B456 +58 58 | # noqa: A123,,B456 +59 59 | # noqa: A123 , , B456 +60 |-# noqa: A123 B456 + 60 |+# noqa: A123, B456 +61 61 | # noqa: A123 B456 +62 62 | # noqa: A123 B456 +63 63 | # noqa: A123 ,B456 -RUF104.py:79:3: RUF104 [*] Unformatted special comment +RUF104.py:61:3: RUF104 [*] Unformatted special comment | -77 | # noqa: A123 , , B456 -78 | # noqa: A123 B456 -79 | # noqa: A123 B456 +59 | # noqa: A123 , , B456 +60 | # noqa: A123 B456 +61 | # noqa: A123 B456 | ^^^^ RUF104 -80 | # noqa: A123 B456 -81 | # noqa: A123 ,B456 +62 | # noqa: A123 B456 +63 | # noqa: A123 ,B456 | = help: Format comment ℹ Safe fix -76 76 | # noqa: A123,,B456 -77 77 | # noqa: A123 , , B456 -78 78 | # noqa: A123 B456 -79 |-# noqa: A123 B456 - 79 |+# noqa: A123, B456 -80 80 | # noqa: A123 B456 -81 81 | # noqa: A123 ,B456 -82 82 | # ruff: noqa: A123 B456 +58 58 | # noqa: A123,,B456 +59 59 | # noqa: A123 , , B456 +60 60 | # noqa: A123 B456 +61 |-# noqa: A123 B456 + 61 |+# noqa: A123, B456 +62 62 | # noqa: A123 B456 +63 63 | # noqa: A123 ,B456 +64 64 | # ruff: noqa: A123 B456 -RUF104.py:80:3: RUF104 [*] Unformatted special comment +RUF104.py:62:3: RUF104 [*] Unformatted special comment | -78 | # noqa: A123 B456 -79 | # noqa: A123 B456 -80 | # noqa: A123 B456 +60 | # noqa: A123 B456 +61 | # noqa: A123 B456 +62 | # noqa: A123 B456 | ^^^^ RUF104 -81 | # noqa: A123 ,B456 -82 | # ruff: noqa: A123 B456 +63 | # noqa: A123 ,B456 +64 | # ruff: noqa: A123 B456 | = help: Format comment ℹ Safe fix -77 77 | # noqa: A123 , , B456 -78 78 | # noqa: A123 B456 -79 79 | # noqa: A123 B456 -80 |-# noqa: A123 B456 - 80 |+# noqa: A123, B456 -81 81 | # noqa: A123 ,B456 -82 82 | # ruff: noqa: A123 B456 -83 83 | # flake8: noqa: A123 B456 +59 59 | # noqa: A123 , , B456 +60 60 | # noqa: A123 B456 +61 61 | # noqa: A123 B456 +62 |-# noqa: A123 B456 + 62 |+# noqa: A123, B456 +63 63 | # noqa: A123 ,B456 +64 64 | # ruff: noqa: A123 B456 +65 65 | # flake8: noqa: A123 B456 -RUF104.py:81:3: RUF104 [*] Unformatted special comment +RUF104.py:63:3: RUF104 [*] Unformatted special comment | -79 | # noqa: A123 B456 -80 | # noqa: A123 B456 -81 | # noqa: A123 ,B456 +61 | # noqa: A123 B456 +62 | # noqa: A123 B456 +63 | # noqa: A123 ,B456 | ^^^^ RUF104 -82 | # ruff: noqa: A123 B456 -83 | # flake8: noqa: A123 B456 +64 | # ruff: noqa: A123 B456 +65 | # flake8: noqa: A123 B456 | = help: Format comment ℹ Safe fix -78 78 | # noqa: A123 B456 -79 79 | # noqa: A123 B456 -80 80 | # noqa: A123 B456 -81 |-# noqa: A123 ,B456 - 81 |+# noqa: A123, B456 -82 82 | # ruff: noqa: A123 B456 -83 83 | # flake8: noqa: A123 B456 -84 84 | +60 60 | # noqa: A123 B456 +61 61 | # noqa: A123 B456 +62 62 | # noqa: A123 B456 +63 |-# noqa: A123 ,B456 + 63 |+# noqa: A123, B456 +64 64 | # ruff: noqa: A123 B456 +65 65 | # flake8: noqa: A123 B456 +66 66 | -RUF104.py:82:3: RUF104 [*] Unformatted special comment +RUF104.py:64:3: RUF104 [*] Unformatted special comment | -80 | # noqa: A123 B456 -81 | # noqa: A123 ,B456 -82 | # ruff: noqa: A123 B456 +62 | # noqa: A123 B456 +63 | # noqa: A123 ,B456 +64 | # ruff: noqa: A123 B456 | ^^^^ RUF104 -83 | # flake8: noqa: A123 B456 +65 | # flake8: noqa: A123 B456 | = help: Format comment ℹ Safe fix -79 79 | # noqa: A123 B456 -80 80 | # noqa: A123 B456 -81 81 | # noqa: A123 ,B456 -82 |-# ruff: noqa: A123 B456 - 82 |+# ruff: noqa: A123, B456 -83 83 | # flake8: noqa: A123 B456 -84 84 | -85 85 | +61 61 | # noqa: A123 B456 +62 62 | # noqa: A123 B456 +63 63 | # noqa: A123 ,B456 +64 |-# ruff: noqa: A123 B456 + 64 |+# ruff: noqa: A123, B456 +65 65 | # flake8: noqa: A123 B456 +66 66 | +67 67 | -RUF104.py:83:3: RUF104 [*] Unformatted special comment +RUF104.py:65:3: RUF104 [*] Unformatted special comment | -81 | # noqa: A123 ,B456 -82 | # ruff: noqa: A123 B456 -83 | # flake8: noqa: A123 B456 +63 | # noqa: A123 ,B456 +64 | # ruff: noqa: A123 B456 +65 | # flake8: noqa: A123 B456 | ^^^^^^ RUF104 | = help: Format comment ℹ Safe fix -80 80 | # noqa: A123 B456 -81 81 | # noqa: A123 ,B456 -82 82 | # ruff: noqa: A123 B456 -83 |-# flake8: noqa: A123 B456 - 83 |+# flake8: noqa: A123, B456 -84 84 | -85 85 | -86 86 | # type: ignore # noqa: A123, B456 - -RUF104.py:88:2: RUF104 [*] Unformatted special comment - | -86 | # type: ignore # noqa: A123, B456 -87 | -88 | #pyright:ignore#noqa:A123 - | ^^^^^^^ RUF104 -89 | -90 | # nopycln:file# noqa: A123 - | - = help: Format comment - -ℹ Safe fix -85 85 | -86 86 | # type: ignore # noqa: A123, B456 -87 87 | -88 |-#pyright:ignore#noqa:A123 - 88 |+# pyright: ignore#noqa:A123 -89 89 | -90 90 | # nopycln:file# noqa: A123 -91 91 | +62 62 | # noqa: A123 B456 +63 63 | # noqa: A123 ,B456 +64 64 | # ruff: noqa: A123 B456 +65 |-# flake8: noqa: A123 B456 + 65 |+# flake8: noqa: A123, B456 +66 66 | +67 67 | +68 68 | # type: ignore # noqa: A123, B456 -RUF104.py:88:17: RUF104 [*] Unformatted special comment +RUF104.py:70:13: RUF104 [*] Unformatted special comment | -86 | # type: ignore # noqa: A123, B456 -87 | -88 | #pyright:ignore#noqa:A123 - | ^^^^ RUF104 -89 | -90 | # nopycln:file# noqa: A123 +68 | # type: ignore # noqa: A123, B456 +69 | +70 | #isort:skip#noqa:A123 + | ^^^^ RUF104 +71 | +72 | # fmt:off# noqa: A123 | = help: Format comment ℹ Safe fix -85 85 | -86 86 | # type: ignore # noqa: A123, B456 -87 87 | -88 |-#pyright:ignore#noqa:A123 - 88 |+#pyright:ignore# noqa: A123 -89 89 | -90 90 | # nopycln:file# noqa: A123 -91 91 | +67 67 | +68 68 | # type: ignore # noqa: A123, B456 +69 69 | +70 |-#isort:skip#noqa:A123 + 70 |+#isort:skip# noqa: A123 +71 71 | +72 72 | # fmt:off# noqa: A123 +73 73 | -RUF104.py:90:3: RUF104 [*] Unformatted special comment +RUF104.py:72:3: RUF104 [*] Unformatted special comment | -88 | #pyright:ignore#noqa:A123 -89 | -90 | # nopycln:file# noqa: A123 - | ^^^^^^^ RUF104 -91 | -92 | # noqa:A123 - Lorem ipsum dolor sit amet +70 | #isort:skip#noqa:A123 +71 | +72 | # fmt:off# noqa: A123 + | ^^^ RUF104 +73 | +74 | # noqa:A123 - Lorem ipsum dolor sit amet | = help: Format comment ℹ Safe fix -87 87 | -88 88 | #pyright:ignore#noqa:A123 -89 89 | -90 |-# nopycln:file# noqa: A123 - 90 |+# nopycln: file# noqa: A123 -91 91 | -92 92 | # noqa:A123 - Lorem ipsum dolor sit amet +69 69 | +70 70 | #isort:skip#noqa:A123 +71 71 | +72 |-# fmt:off# noqa: A123 + 72 |+# fmt: off# noqa: A123 +73 73 | +74 74 | # noqa:A123 - Lorem ipsum dolor sit amet -RUF104.py:90:19: RUF104 [*] Unformatted special comment +RUF104.py:72:14: RUF104 [*] Unformatted special comment | -88 | #pyright:ignore#noqa:A123 -89 | -90 | # nopycln:file# noqa: A123 - | ^^^^ RUF104 -91 | -92 | # noqa:A123 - Lorem ipsum dolor sit amet +70 | #isort:skip#noqa:A123 +71 | +72 | # fmt:off# noqa: A123 + | ^^^^ RUF104 +73 | +74 | # noqa:A123 - Lorem ipsum dolor sit amet | = help: Format comment ℹ Safe fix -87 87 | -88 88 | #pyright:ignore#noqa:A123 -89 89 | -90 |-# nopycln:file# noqa: A123 - 90 |+# nopycln:file# noqa: A123 -91 91 | -92 92 | # noqa:A123 - Lorem ipsum dolor sit amet +69 69 | +70 70 | #isort:skip#noqa:A123 +71 71 | +72 |-# fmt:off# noqa: A123 + 72 |+# fmt:off# noqa: A123 +73 73 | +74 74 | # noqa:A123 - Lorem ipsum dolor sit amet -RUF104.py:92:3: RUF104 [*] Unformatted special comment +RUF104.py:74:3: RUF104 [*] Unformatted special comment | -90 | # nopycln:file# noqa: A123 -91 | -92 | # noqa:A123 - Lorem ipsum dolor sit amet +72 | # fmt:off# noqa: A123 +73 | +74 | # noqa:A123 - Lorem ipsum dolor sit amet | ^^^^ RUF104 | = help: Format comment ℹ Safe fix -89 89 | -90 90 | # nopycln:file# noqa: A123 -91 91 | -92 |-# noqa:A123 - Lorem ipsum dolor sit amet - 92 |+# noqa: A123 - Lorem ipsum dolor sit amet +71 71 | +72 72 | # fmt:off# noqa: A123 +73 73 | +74 |-# noqa:A123 - Lorem ipsum dolor sit amet + 74 |+# noqa: A123 - Lorem ipsum dolor sit amet diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_3.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_empty_suppressions.py.snap similarity index 76% rename from crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_3.py.snap rename to crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_empty_suppressions.py.snap index d20bae4421dff1..8589032badccba 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_3.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_empty_suppressions.py.snap @@ -2,7 +2,7 @@ source: crates/ruff_linter/src/rules/ruff/mod.rs snapshot_kind: text --- -RUF104_3.py:5:2: RUF104 [*] Unformatted special comment +RUF104_empty_suppressions.py:5:2: RUF104 [*] Unformatted special comment | 3 | ### 4 | @@ -22,7 +22,7 @@ RUF104_3.py:5:2: RUF104 [*] Unformatted special comment 6 6 | #ruff:noqa: 7 7 | #flake8:noqa: -RUF104_3.py:6:2: RUF104 [*] Unformatted special comment +RUF104_empty_suppressions.py:6:2: RUF104 [*] Unformatted special comment | 5 | #noqa: 6 | #ruff:noqa: @@ -39,7 +39,7 @@ RUF104_3.py:6:2: RUF104 [*] Unformatted special comment 6 |+# ruff: noqa: 7 7 | #flake8:noqa: -RUF104_3.py:7:2: RUF104 [*] Unformatted special comment +RUF104_empty_suppressions.py:7:2: RUF104 [*] Unformatted special comment | 5 | #noqa: 6 | #ruff:noqa: diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_2.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_explicit_suppression.py.snap similarity index 100% rename from crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_2.py.snap rename to crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_explicit_suppression.py.snap diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_1.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_implicit_suppression.py.snap similarity index 76% rename from crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_1.py.snap rename to crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_implicit_suppression.py.snap index 5a064931b349f9..9b65bddb503d4b 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_1.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_implicit_suppression.py.snap @@ -2,7 +2,7 @@ source: crates/ruff_linter/src/rules/ruff/mod.rs snapshot_kind: text --- -RUF104_1.py:6:3: RUF104 [*] Unformatted special comment +RUF104_implicit_suppression.py:6:3: RUF104 [*] Unformatted special comment | 4 | ### 5 | @@ -22,7 +22,7 @@ RUF104_1.py:6:3: RUF104 [*] Unformatted special comment 7 7 | 8 8 | #noqa:A123 -RUF104_1.py:8:2: RUF104 [*] Unformatted special comment +RUF104_implicit_suppression.py:8:2: RUF104 [*] Unformatted special comment | 6 | # ruff:noqa 7 | From ee6dc395c7a55758f0c30996200f08a5b37c6eb0 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Mon, 11 Nov 2024 13:53:36 +0000 Subject: [PATCH 24/29] `rustfmt` --- crates/ruff_linter/src/rules/ruff/mod.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/ruff_linter/src/rules/ruff/mod.rs b/crates/ruff_linter/src/rules/ruff/mod.rs index 14ada89e91f4fe..345822b3b01b68 100644 --- a/crates/ruff_linter/src/rules/ruff/mod.rs +++ b/crates/ruff_linter/src/rules/ruff/mod.rs @@ -385,9 +385,18 @@ mod tests { #[test_case(Rule::ZipInsteadOfPairwise, Path::new("RUF007.py"))] #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104.py"))] - #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104_implicit_suppression.py"))] - #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104_explicit_suppression.py"))] - #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104_empty_suppressions.py"))] + #[test_case( + Rule::UnformattedSpecialComment, + Path::new("RUF104_implicit_suppression.py") + )] + #[test_case( + Rule::UnformattedSpecialComment, + Path::new("RUF104_explicit_suppression.py") + )] + #[test_case( + Rule::UnformattedSpecialComment, + Path::new("RUF104_empty_suppressions.py") + )] fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> { let snapshot = format!( "preview__{}_{}", From 78327f09437e371f1f2be46bf61b78f1ffe5dfc9 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Mon, 11 Nov 2024 14:38:53 +0000 Subject: [PATCH 25/29] Fix failing testcase --- .../src/rules/ruff/rules/unformatted_special_comment.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index 0477a652aee67f..dca92b15159c97 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -245,7 +245,7 @@ fn try_parse_isort(text: &str) -> SpecialCommentDescriptor { fn try_parse_ruff_isort(text: &str) -> SpecialCommentDescriptor { // ruff_linter::directives::extract_isort_directives static PATTERN: LazyLock = - LazyLock::new(|| Regex::new(r"^# (?ruff): isort: ?(?skip_file|skip)").unwrap()); + LazyLock::new(|| Regex::new(r"^# (?ruff): isort:(?skip_file|skip)").unwrap()); try_parse_common!(PATTERN, text, SpecialComment::RuffIsort) } @@ -483,7 +483,7 @@ mod tests { fn composite() { composite_no_unformatted("# type: ignore # noqa: A123, B456"); - composite_has_unformatted("#isort:skip#noqa:A123", 2); + composite_has_unformatted("# isort:skip#noqa:A123", 2); composite_has_unformatted("# fmt:off# noqa: A123", 2); composite_has_unformatted("# noqa:A123 - Lorem ipsum dolor sit amet", 1); } From c899ead9ac9f0cba4d7027c91b98f17107a87fec Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Wed, 13 Nov 2024 17:28:28 +0000 Subject: [PATCH 26/29] Rename to `RUF037` --- .../fixtures/ruff/{RUF104.py => RUF037.py} | 0 ...sion.py => RUF037_explicit_suppression.py} | 4 +- ...sion.py => RUF037_implicit_suppression.py} | 2 +- crates/ruff_linter/src/checkers/noqa.rs | 2 +- crates/ruff_linter/src/codes.rs | 2 +- crates/ruff_linter/src/rules/ruff/mod.rs | 8 +- .../ruff/rules/unformatted_special_comment.rs | 6 +- ...ff__tests__preview__RUF037_RUF037.py.snap} | 136 +++++++++--------- ..._RUF037_RUF037_empty_suppressions.py.snap} | 12 +- ...UF037_RUF037_implicit_suppression.py.snap} | 8 +- ruff.schema.json | 2 +- 11 files changed, 91 insertions(+), 91 deletions(-) rename crates/ruff_linter/resources/test/fixtures/ruff/{RUF104.py => RUF037.py} (100%) rename crates/ruff_linter/resources/test/fixtures/ruff/{RUF104_explicit_suppression.py => RUF037_explicit_suppression.py} (55%) rename crates/ruff_linter/resources/test/fixtures/ruff/{RUF104_implicit_suppression.py => RUF037_implicit_suppression.py} (65%) rename crates/ruff_linter/src/rules/ruff/snapshots/{ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap => ruff_linter__rules__ruff__tests__preview__RUF037_RUF037.py.snap} (83%) rename crates/ruff_linter/src/rules/ruff/snapshots/{ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_empty_suppressions.py.snap => ruff_linter__rules__ruff__tests__preview__RUF037_RUF037_empty_suppressions.py.snap} (73%) rename crates/ruff_linter/src/rules/ruff/snapshots/{ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_implicit_suppression.py.snap => ruff_linter__rules__ruff__tests__preview__RUF037_RUF037_implicit_suppression.py.snap} (74%) diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF037.py similarity index 100% rename from crates/ruff_linter/resources/test/fixtures/ruff/RUF104.py rename to crates/ruff_linter/resources/test/fixtures/ruff/RUF037.py diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_explicit_suppression.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF037_explicit_suppression.py similarity index 55% rename from crates/ruff_linter/resources/test/fixtures/ruff/RUF104_explicit_suppression.py rename to crates/ruff_linter/resources/test/fixtures/ruff/RUF037_explicit_suppression.py index 3c207b46a95e7a..1efdf9830bd188 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_explicit_suppression.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF037_explicit_suppression.py @@ -1,8 +1,8 @@ ### -# None of these should trigger RUF104 +# None of these should trigger RUF037 # as it is explicitly suppressed for the entire file. ### -# flake8:noqa:RUF104 +# flake8:noqa:RUF037 #noqa:A123 diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_implicit_suppression.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF037_implicit_suppression.py similarity index 65% rename from crates/ruff_linter/resources/test/fixtures/ruff/RUF104_implicit_suppression.py rename to crates/ruff_linter/resources/test/fixtures/ruff/RUF037_implicit_suppression.py index f95348f7941c32..40401b1df92dec 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_implicit_suppression.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF037_implicit_suppression.py @@ -1,5 +1,5 @@ ### -# Both of these should trigger RUF104 +# Both of these should trigger RUF037 # as it is not explicitly suppressed. ### diff --git a/crates/ruff_linter/src/checkers/noqa.rs b/crates/ruff_linter/src/checkers/noqa.rs index e01cb5ffea5874..9f318aa4e08533 100644 --- a/crates/ruff_linter/src/checkers/noqa.rs +++ b/crates/ruff_linter/src/checkers/noqa.rs @@ -52,7 +52,7 @@ pub(crate) fn check_noqa( match &exemption { FileExemption::All(_) => { // If the file is exempted, ignore all diagnostics, - // save for RUF104, which operates on `# noqa` comments + // save for RUF037, which operates on `# noqa` comments // and thus needs to be suppressed explicitly. if !matches!(diagnostic.kind.rule(), Rule::UnformattedSpecialComment) || per_file_ignores.contains(Rule::UnformattedSpecialComment) diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index db55b0ff21b520..f0e20190f2c892 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -967,9 +967,9 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Ruff, "033") => (RuleGroup::Preview, rules::ruff::rules::PostInitDefault), (Ruff, "034") => (RuleGroup::Preview, rules::ruff::rules::UselessIfElse), (Ruff, "035") => (RuleGroup::Preview, rules::ruff::rules::UnsafeMarkupUse), + (Ruff, "037") => (RuleGroup::Preview, rules::ruff::rules::UnformattedSpecialComment), (Ruff, "100") => (RuleGroup::Stable, rules::ruff::rules::UnusedNOQA), (Ruff, "101") => (RuleGroup::Stable, rules::ruff::rules::RedirectedNOQA), - (Ruff, "104") => (RuleGroup::Preview, rules::ruff::rules::UnformattedSpecialComment), (Ruff, "200") => (RuleGroup::Stable, rules::ruff::rules::InvalidPyprojectToml), #[cfg(any(feature = "test-rules", test))] diff --git a/crates/ruff_linter/src/rules/ruff/mod.rs b/crates/ruff_linter/src/rules/ruff/mod.rs index 29200989975a5e..28cc02a7a672da 100644 --- a/crates/ruff_linter/src/rules/ruff/mod.rs +++ b/crates/ruff_linter/src/rules/ruff/mod.rs @@ -388,18 +388,18 @@ mod tests { #[test_case(Rule::ZipInsteadOfPairwise, Path::new("RUF007.py"))] #[test_case(Rule::UnsafeMarkupUse, Path::new("RUF035.py"))] - #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF104.py"))] + #[test_case(Rule::UnformattedSpecialComment, Path::new("RUF037.py"))] #[test_case( Rule::UnformattedSpecialComment, - Path::new("RUF104_implicit_suppression.py") + Path::new("RUF037_implicit_suppression.py") )] #[test_case( Rule::UnformattedSpecialComment, - Path::new("RUF104_explicit_suppression.py") + Path::new("RUF037_explicit_suppression.py") )] #[test_case( Rule::UnformattedSpecialComment, - Path::new("RUF104_empty_suppressions.py") + Path::new("RUF037_empty_suppressions.py") )] fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> { let snapshot = format!( diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index dca92b15159c97..135299512c5d0c 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -24,9 +24,9 @@ enum SpecialComment { /// `# fmt: on`, `# fmt: off`, `fmt: skip` Fmt(String), - /// `# isort: skip_file` + /// `# isort: skip`, `# isort: skip_file` Isort(String), - /// `# mypy: ignore-errors` + /// `# ruff: isort: skip`, `# ruff: isort: skip_file` RuffIsort(String), /// `# type: int`, `# type: ignore` Type(String), @@ -316,7 +316,7 @@ fn check_composite_comment(diagnostics: &mut Vec, text: &str, range_ } } -/// RUF104 +/// RUF037 pub(crate) fn unformatted_special_comment( diagnostics: &mut Vec, locator: &Locator, diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037.py.snap similarity index 83% rename from crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap rename to crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037.py.snap index 9a37dfd7671319..bf35ba38113c63 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037.py.snap @@ -2,12 +2,12 @@ source: crates/ruff_linter/src/rules/ruff/mod.rs snapshot_kind: text --- -RUF104.py:34:3: RUF104 [*] Unformatted special comment +RUF037.py:34:3: RUF037 [*] Unformatted special comment | 32 | # type: list[str] 33 | 34 | # noqa:A123 - | ^^^^ RUF104 + | ^^^^ RUF037 35 | #noqa: A123 36 | # type:ignore | @@ -23,11 +23,11 @@ RUF104.py:34:3: RUF104 [*] Unformatted special comment 36 36 | # type:ignore 37 37 | #type: int -RUF104.py:35:2: RUF104 [*] Unformatted special comment +RUF037.py:35:2: RUF037 [*] Unformatted special comment | 34 | # noqa:A123 35 | #noqa: A123 - | ^^^^ RUF104 + | ^^^^ RUF037 36 | # type:ignore 37 | #type: int | @@ -43,12 +43,12 @@ RUF104.py:35:2: RUF104 [*] Unformatted special comment 37 37 | #type: int 38 38 | # fmt:off -RUF104.py:36:6: RUF104 [*] Unformatted special comment +RUF037.py:36:6: RUF037 [*] Unformatted special comment | 34 | # noqa:A123 35 | #noqa: A123 36 | # type:ignore - | ^^^^ RUF104 + | ^^^^ RUF037 37 | #type: int 38 | # fmt:off | @@ -64,12 +64,12 @@ RUF104.py:36:6: RUF104 [*] Unformatted special comment 38 38 | # fmt:off 39 39 | #fmt: on -RUF104.py:37:2: RUF104 [*] Unformatted special comment +RUF037.py:37:2: RUF037 [*] Unformatted special comment | 35 | #noqa: A123 36 | # type:ignore 37 | #type: int - | ^^^^ RUF104 + | ^^^^ RUF037 38 | # fmt:off 39 | #fmt: on | @@ -85,12 +85,12 @@ RUF104.py:37:2: RUF104 [*] Unformatted special comment 39 39 | #fmt: on 40 40 | # fmt: skip -RUF104.py:38:3: RUF104 [*] Unformatted special comment +RUF037.py:38:3: RUF037 [*] Unformatted special comment | 36 | # type:ignore 37 | #type: int 38 | # fmt:off - | ^^^ RUF104 + | ^^^ RUF037 39 | #fmt: on 40 | # fmt: skip | @@ -106,12 +106,12 @@ RUF104.py:38:3: RUF104 [*] Unformatted special comment 40 40 | # fmt: skip 41 41 | # isort:skip -RUF104.py:39:2: RUF104 [*] Unformatted special comment +RUF037.py:39:2: RUF037 [*] Unformatted special comment | 37 | #type: int 38 | # fmt:off 39 | #fmt: on - | ^^^ RUF104 + | ^^^ RUF037 40 | # fmt: skip 41 | # isort:skip | @@ -127,12 +127,12 @@ RUF104.py:39:2: RUF104 [*] Unformatted special comment 41 41 | # isort:skip 42 42 | # isort:skip_file -RUF104.py:40:5: RUF104 [*] Unformatted special comment +RUF037.py:40:5: RUF037 [*] Unformatted special comment | 38 | # fmt:off 39 | #fmt: on 40 | # fmt: skip - | ^^^ RUF104 + | ^^^ RUF037 41 | # isort:skip 42 | # isort:skip_file | @@ -148,12 +148,12 @@ RUF104.py:40:5: RUF104 [*] Unformatted special comment 42 42 | # isort:skip_file 43 43 | # ruff: isort:skip -RUF104.py:41:3: RUF104 [*] Unformatted special comment +RUF037.py:41:3: RUF037 [*] Unformatted special comment | 39 | #fmt: on 40 | # fmt: skip 41 | # isort:skip - | ^^^^^ RUF104 + | ^^^^^ RUF037 42 | # isort:skip_file 43 | # ruff: isort:skip | @@ -169,12 +169,12 @@ RUF104.py:41:3: RUF104 [*] Unformatted special comment 43 43 | # ruff: isort:skip 44 44 | # ruff: isort:skip_file -RUF104.py:42:3: RUF104 [*] Unformatted special comment +RUF037.py:42:3: RUF037 [*] Unformatted special comment | 40 | # fmt: skip 41 | # isort:skip 42 | # isort:skip_file - | ^^^^^ RUF104 + | ^^^^^ RUF037 43 | # ruff: isort:skip 44 | # ruff: isort:skip_file | @@ -190,12 +190,12 @@ RUF104.py:42:3: RUF104 [*] Unformatted special comment 44 44 | # ruff: isort:skip_file 45 45 | # type: ignore -RUF104.py:43:3: RUF104 [*] Unformatted special comment +RUF037.py:43:3: RUF037 [*] Unformatted special comment | 41 | # isort:skip 42 | # isort:skip_file 43 | # ruff: isort:skip - | ^^^^ RUF104 + | ^^^^ RUF037 44 | # ruff: isort:skip_file 45 | # type: ignore | @@ -211,12 +211,12 @@ RUF104.py:43:3: RUF104 [*] Unformatted special comment 45 45 | # type: ignore 46 46 | # type: int -RUF104.py:44:3: RUF104 [*] Unformatted special comment +RUF037.py:44:3: RUF037 [*] Unformatted special comment | 42 | # isort:skip_file 43 | # ruff: isort:skip 44 | # ruff: isort:skip_file - | ^^^^ RUF104 + | ^^^^ RUF037 45 | # type: ignore 46 | # type: int | @@ -232,12 +232,12 @@ RUF104.py:44:3: RUF104 [*] Unformatted special comment 46 46 | # type: int 47 47 | -RUF104.py:45:6: RUF104 [*] Unformatted special comment +RUF037.py:45:6: RUF037 [*] Unformatted special comment | 43 | # ruff: isort:skip 44 | # ruff: isort:skip_file 45 | # type: ignore - | ^^^^ RUF104 + | ^^^^ RUF037 46 | # type: int | = help: Format comment @@ -252,12 +252,12 @@ RUF104.py:45:6: RUF104 [*] Unformatted special comment 47 47 | 48 48 | # NoQA: A123, B456 -RUF104.py:46:7: RUF104 [*] Unformatted special comment +RUF037.py:46:7: RUF037 [*] Unformatted special comment | 44 | # ruff: isort:skip_file 45 | # type: ignore 46 | # type: int - | ^^^^ RUF104 + | ^^^^ RUF037 47 | 48 | # NoQA: A123, B456 | @@ -273,12 +273,12 @@ RUF104.py:46:7: RUF104 [*] Unformatted special comment 48 48 | # NoQA: A123, B456 49 49 | # ruff: NoQA: A123, B456 -RUF104.py:48:3: RUF104 [*] Unformatted special comment +RUF037.py:48:3: RUF037 [*] Unformatted special comment | 46 | # type: int 47 | 48 | # NoQA: A123, B456 - | ^^^^ RUF104 + | ^^^^ RUF037 49 | # ruff: NoQA: A123, B456 50 | # flake8: NoQA: A123, B456 | @@ -294,11 +294,11 @@ RUF104.py:48:3: RUF104 [*] Unformatted special comment 50 50 | # flake8: NoQA: A123, B456 51 51 | -RUF104.py:49:3: RUF104 [*] Unformatted special comment +RUF037.py:49:3: RUF037 [*] Unformatted special comment | 48 | # NoQA: A123, B456 49 | # ruff: NoQA: A123, B456 - | ^^^^ RUF104 + | ^^^^ RUF037 50 | # flake8: NoQA: A123, B456 | = help: Format comment @@ -313,12 +313,12 @@ RUF104.py:49:3: RUF104 [*] Unformatted special comment 51 51 | 52 52 | # noqa: A123 B456 -RUF104.py:50:3: RUF104 [*] Unformatted special comment +RUF037.py:50:3: RUF037 [*] Unformatted special comment | 48 | # NoQA: A123, B456 49 | # ruff: NoQA: A123, B456 50 | # flake8: NoQA: A123, B456 - | ^^^^^^ RUF104 + | ^^^^^^ RUF037 51 | 52 | # noqa: A123 B456 | @@ -334,12 +334,12 @@ RUF104.py:50:3: RUF104 [*] Unformatted special comment 52 52 | # noqa: A123 B456 53 53 | # ruff: noqa: A123 B456 -RUF104.py:52:3: RUF104 [*] Unformatted special comment +RUF037.py:52:3: RUF037 [*] Unformatted special comment | 50 | # flake8: NoQA: A123, B456 51 | 52 | # noqa: A123 B456 - | ^^^^ RUF104 + | ^^^^ RUF037 53 | # ruff: noqa: A123 B456 54 | # flake8: noqa: A123 B456 | @@ -355,11 +355,11 @@ RUF104.py:52:3: RUF104 [*] Unformatted special comment 54 54 | # flake8: noqa: A123 B456 55 55 | # noqa: A123,B456 -RUF104.py:53:3: RUF104 [*] Unformatted special comment +RUF037.py:53:3: RUF037 [*] Unformatted special comment | 52 | # noqa: A123 B456 53 | # ruff: noqa: A123 B456 - | ^^^^ RUF104 + | ^^^^ RUF037 54 | # flake8: noqa: A123 B456 55 | # noqa: A123,B456 | @@ -375,12 +375,12 @@ RUF104.py:53:3: RUF104 [*] Unformatted special comment 55 55 | # noqa: A123,B456 56 56 | # ruff: noqa: A123,B456 -RUF104.py:54:3: RUF104 [*] Unformatted special comment +RUF037.py:54:3: RUF037 [*] Unformatted special comment | 52 | # noqa: A123 B456 53 | # ruff: noqa: A123 B456 54 | # flake8: noqa: A123 B456 - | ^^^^^^ RUF104 + | ^^^^^^ RUF037 55 | # noqa: A123,B456 56 | # ruff: noqa: A123,B456 | @@ -396,12 +396,12 @@ RUF104.py:54:3: RUF104 [*] Unformatted special comment 56 56 | # ruff: noqa: A123,B456 57 57 | # flake8: noqa: A123,B456 -RUF104.py:55:3: RUF104 [*] Unformatted special comment +RUF037.py:55:3: RUF037 [*] Unformatted special comment | 53 | # ruff: noqa: A123 B456 54 | # flake8: noqa: A123 B456 55 | # noqa: A123,B456 - | ^^^^ RUF104 + | ^^^^ RUF037 56 | # ruff: noqa: A123,B456 57 | # flake8: noqa: A123,B456 | @@ -417,12 +417,12 @@ RUF104.py:55:3: RUF104 [*] Unformatted special comment 57 57 | # flake8: noqa: A123,B456 58 58 | # noqa: A123,,B456 -RUF104.py:56:3: RUF104 [*] Unformatted special comment +RUF037.py:56:3: RUF037 [*] Unformatted special comment | 54 | # flake8: noqa: A123 B456 55 | # noqa: A123,B456 56 | # ruff: noqa: A123,B456 - | ^^^^ RUF104 + | ^^^^ RUF037 57 | # flake8: noqa: A123,B456 58 | # noqa: A123,,B456 | @@ -438,12 +438,12 @@ RUF104.py:56:3: RUF104 [*] Unformatted special comment 58 58 | # noqa: A123,,B456 59 59 | # noqa: A123 , , B456 -RUF104.py:57:3: RUF104 [*] Unformatted special comment +RUF037.py:57:3: RUF037 [*] Unformatted special comment | 55 | # noqa: A123,B456 56 | # ruff: noqa: A123,B456 57 | # flake8: noqa: A123,B456 - | ^^^^^^ RUF104 + | ^^^^^^ RUF037 58 | # noqa: A123,,B456 59 | # noqa: A123 , , B456 | @@ -459,12 +459,12 @@ RUF104.py:57:3: RUF104 [*] Unformatted special comment 59 59 | # noqa: A123 , , B456 60 60 | # noqa: A123 B456 -RUF104.py:58:3: RUF104 [*] Unformatted special comment +RUF037.py:58:3: RUF037 [*] Unformatted special comment | 56 | # ruff: noqa: A123,B456 57 | # flake8: noqa: A123,B456 58 | # noqa: A123,,B456 - | ^^^^ RUF104 + | ^^^^ RUF037 59 | # noqa: A123 , , B456 60 | # noqa: A123 B456 | @@ -480,12 +480,12 @@ RUF104.py:58:3: RUF104 [*] Unformatted special comment 60 60 | # noqa: A123 B456 61 61 | # noqa: A123 B456 -RUF104.py:59:3: RUF104 [*] Unformatted special comment +RUF037.py:59:3: RUF037 [*] Unformatted special comment | 57 | # flake8: noqa: A123,B456 58 | # noqa: A123,,B456 59 | # noqa: A123 , , B456 - | ^^^^ RUF104 + | ^^^^ RUF037 60 | # noqa: A123 B456 61 | # noqa: A123 B456 | @@ -501,12 +501,12 @@ RUF104.py:59:3: RUF104 [*] Unformatted special comment 61 61 | # noqa: A123 B456 62 62 | # noqa: A123 B456 -RUF104.py:60:3: RUF104 [*] Unformatted special comment +RUF037.py:60:3: RUF037 [*] Unformatted special comment | 58 | # noqa: A123,,B456 59 | # noqa: A123 , , B456 60 | # noqa: A123 B456 - | ^^^^ RUF104 + | ^^^^ RUF037 61 | # noqa: A123 B456 62 | # noqa: A123 B456 | @@ -522,12 +522,12 @@ RUF104.py:60:3: RUF104 [*] Unformatted special comment 62 62 | # noqa: A123 B456 63 63 | # noqa: A123 ,B456 -RUF104.py:61:3: RUF104 [*] Unformatted special comment +RUF037.py:61:3: RUF037 [*] Unformatted special comment | 59 | # noqa: A123 , , B456 60 | # noqa: A123 B456 61 | # noqa: A123 B456 - | ^^^^ RUF104 + | ^^^^ RUF037 62 | # noqa: A123 B456 63 | # noqa: A123 ,B456 | @@ -543,12 +543,12 @@ RUF104.py:61:3: RUF104 [*] Unformatted special comment 63 63 | # noqa: A123 ,B456 64 64 | # ruff: noqa: A123 B456 -RUF104.py:62:3: RUF104 [*] Unformatted special comment +RUF037.py:62:3: RUF037 [*] Unformatted special comment | 60 | # noqa: A123 B456 61 | # noqa: A123 B456 62 | # noqa: A123 B456 - | ^^^^ RUF104 + | ^^^^ RUF037 63 | # noqa: A123 ,B456 64 | # ruff: noqa: A123 B456 | @@ -564,12 +564,12 @@ RUF104.py:62:3: RUF104 [*] Unformatted special comment 64 64 | # ruff: noqa: A123 B456 65 65 | # flake8: noqa: A123 B456 -RUF104.py:63:3: RUF104 [*] Unformatted special comment +RUF037.py:63:3: RUF037 [*] Unformatted special comment | 61 | # noqa: A123 B456 62 | # noqa: A123 B456 63 | # noqa: A123 ,B456 - | ^^^^ RUF104 + | ^^^^ RUF037 64 | # ruff: noqa: A123 B456 65 | # flake8: noqa: A123 B456 | @@ -585,12 +585,12 @@ RUF104.py:63:3: RUF104 [*] Unformatted special comment 65 65 | # flake8: noqa: A123 B456 66 66 | -RUF104.py:64:3: RUF104 [*] Unformatted special comment +RUF037.py:64:3: RUF037 [*] Unformatted special comment | 62 | # noqa: A123 B456 63 | # noqa: A123 ,B456 64 | # ruff: noqa: A123 B456 - | ^^^^ RUF104 + | ^^^^ RUF037 65 | # flake8: noqa: A123 B456 | = help: Format comment @@ -605,12 +605,12 @@ RUF104.py:64:3: RUF104 [*] Unformatted special comment 66 66 | 67 67 | -RUF104.py:65:3: RUF104 [*] Unformatted special comment +RUF037.py:65:3: RUF037 [*] Unformatted special comment | 63 | # noqa: A123 ,B456 64 | # ruff: noqa: A123 B456 65 | # flake8: noqa: A123 B456 - | ^^^^^^ RUF104 + | ^^^^^^ RUF037 | = help: Format comment @@ -624,12 +624,12 @@ RUF104.py:65:3: RUF104 [*] Unformatted special comment 67 67 | 68 68 | # type: ignore # noqa: A123, B456 -RUF104.py:70:13: RUF104 [*] Unformatted special comment +RUF037.py:70:13: RUF037 [*] Unformatted special comment | 68 | # type: ignore # noqa: A123, B456 69 | 70 | #isort:skip#noqa:A123 - | ^^^^ RUF104 + | ^^^^ RUF037 71 | 72 | # fmt:off# noqa: A123 | @@ -645,12 +645,12 @@ RUF104.py:70:13: RUF104 [*] Unformatted special comment 72 72 | # fmt:off# noqa: A123 73 73 | -RUF104.py:72:3: RUF104 [*] Unformatted special comment +RUF037.py:72:3: RUF037 [*] Unformatted special comment | 70 | #isort:skip#noqa:A123 71 | 72 | # fmt:off# noqa: A123 - | ^^^ RUF104 + | ^^^ RUF037 73 | 74 | # noqa:A123 - Lorem ipsum dolor sit amet | @@ -665,12 +665,12 @@ RUF104.py:72:3: RUF104 [*] Unformatted special comment 73 73 | 74 74 | # noqa:A123 - Lorem ipsum dolor sit amet -RUF104.py:72:14: RUF104 [*] Unformatted special comment +RUF037.py:72:14: RUF037 [*] Unformatted special comment | 70 | #isort:skip#noqa:A123 71 | 72 | # fmt:off# noqa: A123 - | ^^^^ RUF104 + | ^^^^ RUF037 73 | 74 | # noqa:A123 - Lorem ipsum dolor sit amet | @@ -685,12 +685,12 @@ RUF104.py:72:14: RUF104 [*] Unformatted special comment 73 73 | 74 74 | # noqa:A123 - Lorem ipsum dolor sit amet -RUF104.py:74:3: RUF104 [*] Unformatted special comment +RUF037.py:74:3: RUF037 [*] Unformatted special comment | 72 | # fmt:off# noqa: A123 73 | 74 | # noqa:A123 - Lorem ipsum dolor sit amet - | ^^^^ RUF104 + | ^^^^ RUF037 | = help: Format comment diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_empty_suppressions.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037_empty_suppressions.py.snap similarity index 73% rename from crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_empty_suppressions.py.snap rename to crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037_empty_suppressions.py.snap index 8589032badccba..02390bb0c1eef4 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_empty_suppressions.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037_empty_suppressions.py.snap @@ -2,12 +2,12 @@ source: crates/ruff_linter/src/rules/ruff/mod.rs snapshot_kind: text --- -RUF104_empty_suppressions.py:5:2: RUF104 [*] Unformatted special comment +RUF037_empty_suppressions.py:5:2: RUF037 [*] Unformatted special comment | 3 | ### 4 | 5 | #noqa: - | ^^^^ RUF104 + | ^^^^ RUF037 6 | #ruff:noqa: 7 | #flake8:noqa: | @@ -22,11 +22,11 @@ RUF104_empty_suppressions.py:5:2: RUF104 [*] Unformatted special comment 6 6 | #ruff:noqa: 7 7 | #flake8:noqa: -RUF104_empty_suppressions.py:6:2: RUF104 [*] Unformatted special comment +RUF037_empty_suppressions.py:6:2: RUF037 [*] Unformatted special comment | 5 | #noqa: 6 | #ruff:noqa: - | ^^^^ RUF104 + | ^^^^ RUF037 7 | #flake8:noqa: | = help: Format comment @@ -39,12 +39,12 @@ RUF104_empty_suppressions.py:6:2: RUF104 [*] Unformatted special comment 6 |+# ruff: noqa: 7 7 | #flake8:noqa: -RUF104_empty_suppressions.py:7:2: RUF104 [*] Unformatted special comment +RUF037_empty_suppressions.py:7:2: RUF037 [*] Unformatted special comment | 5 | #noqa: 6 | #ruff:noqa: 7 | #flake8:noqa: - | ^^^^^^ RUF104 + | ^^^^^^ RUF037 | = help: Format comment diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_implicit_suppression.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037_implicit_suppression.py.snap similarity index 74% rename from crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_implicit_suppression.py.snap rename to crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037_implicit_suppression.py.snap index 9b65bddb503d4b..31ee81c85c50d6 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_implicit_suppression.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037_implicit_suppression.py.snap @@ -2,12 +2,12 @@ source: crates/ruff_linter/src/rules/ruff/mod.rs snapshot_kind: text --- -RUF104_implicit_suppression.py:6:3: RUF104 [*] Unformatted special comment +RUF037_implicit_suppression.py:6:3: RUF037 [*] Unformatted special comment | 4 | ### 5 | 6 | # ruff:noqa - | ^^^^ RUF104 + | ^^^^ RUF037 7 | 8 | #noqa:A123 | @@ -22,12 +22,12 @@ RUF104_implicit_suppression.py:6:3: RUF104 [*] Unformatted special comment 7 7 | 8 8 | #noqa:A123 -RUF104_implicit_suppression.py:8:2: RUF104 [*] Unformatted special comment +RUF037_implicit_suppression.py:8:2: RUF037 [*] Unformatted special comment | 6 | # ruff:noqa 7 | 8 | #noqa:A123 - | ^^^^ RUF104 + | ^^^^ RUF037 | = help: Format comment diff --git a/ruff.schema.json b/ruff.schema.json index 5e706bd06a872c..0d8a68bb305bc3 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -3828,11 +3828,11 @@ "RUF033", "RUF034", "RUF035", + "RUF037", "RUF1", "RUF10", "RUF100", "RUF101", - "RUF104", "RUF2", "RUF20", "RUF200", From 7cdf2d35119dc3e81bc7d6e54afd7a0df21ba93d Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Wed, 13 Nov 2024 17:41:44 +0000 Subject: [PATCH 27/29] Missed two --- ...{RUF104_empty_suppressions.py => RUF037_empty_suppressions.py} | 0 ...f__tests__preview__RUF037_RUF037_explicit_suppression.py.snap} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename crates/ruff_linter/resources/test/fixtures/ruff/{RUF104_empty_suppressions.py => RUF037_empty_suppressions.py} (100%) rename crates/ruff_linter/src/rules/ruff/snapshots/{ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_explicit_suppression.py.snap => ruff_linter__rules__ruff__tests__preview__RUF037_RUF037_explicit_suppression.py.snap} (100%) diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF104_empty_suppressions.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF037_empty_suppressions.py similarity index 100% rename from crates/ruff_linter/resources/test/fixtures/ruff/RUF104_empty_suppressions.py rename to crates/ruff_linter/resources/test/fixtures/ruff/RUF037_empty_suppressions.py diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_explicit_suppression.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037_explicit_suppression.py.snap similarity index 100% rename from crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF104_RUF104_explicit_suppression.py.snap rename to crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037_explicit_suppression.py.snap From 7bc3a844920e3d9cdd5a2d84c4c81d65b6d10325 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Wed, 13 Nov 2024 19:01:24 +0000 Subject: [PATCH 28/29] Add `# yapf` --- .../resources/test/fixtures/ruff/RUF037.py | 18 +- .../ruff/rules/unformatted_special_comment.rs | 37 +- ...uff__tests__preview__RUF037_RUF037.py.snap | 1002 +++++++++-------- 3 files changed, 588 insertions(+), 469 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF037.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF037.py index 3544f5bdac8b09..8bcb883a68fdb8 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF037.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF037.py @@ -3,10 +3,18 @@ #ruff: foo-bar # flake8:foo-bar # black:skip - +# fmt: foo +# isort: skip_entire +# ruff: isort: skipfile +# yapf: off # FMT:OFF # isort: On # Type: ignore +# yapf: Disable +# Yapf: disable +#yapf: enable +# yapf : enable +# yapf:disable # noqa # noqa: A123 @@ -30,7 +38,8 @@ # type: ignore # type: int # type: list[str] - +# yapf: enable +# yapf: disable # noqa:A123 #noqa: A123 # type:ignore @@ -44,6 +53,8 @@ # ruff: isort:skip_file # type: ignore # type: int +# yapf: enable +# yapf: disable # NoQA: A123, B456 # ruff: NoQA: A123, B456 @@ -70,5 +81,4 @@ #isort:skip#noqa:A123 # fmt:off# noqa: A123 - -# noqa:A123 - Lorem ipsum dolor sit amet +# noqa:A123, B456 - Lorem ipsum dolor sit amet diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index 135299512c5d0c..170fe61d3f2644 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -30,6 +30,8 @@ enum SpecialComment { RuffIsort(String), /// `# type: int`, `# type: ignore` Type(String), + /// `# yapf: enable`, `# yapf: disable` + Yapf(String), } impl SpecialComment { @@ -57,6 +59,7 @@ impl SpecialComment { SpecialComment::Isort(rest) => format!("# isort: {rest}"), SpecialComment::RuffIsort(rest) => format!("# ruff: isort: {rest}"), SpecialComment::Type(rest) => format!("# type: {rest}"), + SpecialComment::Yapf(rest) => format!("# yapf: {rest}"), } } } @@ -258,6 +261,14 @@ fn try_parse_type(text: &str) -> SpecialCommentDescriptor { try_parse_common!(PATTERN, text, SpecialComment::Type) } +fn try_parse_yapf(text: &str) -> SpecialCommentDescriptor { + // https://github.com/astral-sh/ruff/blob/78e4753d74/crates/ruff_python_trivia/src/comments.rs#L18-L38 + static PATTERN: LazyLock = + LazyLock::new(|| Regex::new(r"#\s*(?yapf):\s*(?enable|disable)").unwrap()); + + try_parse_common!(PATTERN, text, SpecialComment::Yapf) +} + fn text_range(start: usize, end: usize) -> Option { let Ok(start) = TextSize::try_from(start) else { return None; @@ -302,6 +313,7 @@ fn check_single_comment(diagnostics: &mut Vec, text: &str, start_ind parse_and_handle_comment!(try_parse_isort, text, diagnostics, start_index); parse_and_handle_comment!(try_parse_ruff_isort, text, diagnostics, start_index); parse_and_handle_comment!(try_parse_type, text, diagnostics, start_index); + parse_and_handle_comment!(try_parse_yapf, text, diagnostics, start_index); } fn check_composite_comment(diagnostics: &mut Vec, text: &str, range_start: usize) { @@ -385,6 +397,11 @@ mod tests { no_unformatted("# flake8:foo-bar"); no_unformatted("# black:skip"); + + no_unformatted("# fmt: foo"); + no_unformatted("# isort: skip_entire"); + no_unformatted("# ruff: isort: skipfile"); + no_unformatted("# yapf: off"); } #[test] @@ -392,6 +409,15 @@ mod tests { no_unformatted("# FMT:OFF"); no_unformatted("# isort: On"); no_unformatted("# Type: ignore"); + no_unformatted("# yapf: Disable"); + no_unformatted("# Yapf: disable"); + } + + #[test] + fn incorrect_whitespace() { + no_unformatted("#yapf: enable"); + no_unformatted("# yapf : enable"); + no_unformatted("# yapf:disable"); } #[test] @@ -418,15 +444,15 @@ mod tests { no_unformatted("# isort: skip"); no_unformatted("# isort: skip_file"); - no_unformatted("# nopycln: file"); - no_unformatted("# nopycln: import"); - no_unformatted("# ruff: isort: on"); no_unformatted("# ruff: isort: skip_file"); no_unformatted("# type: ignore"); no_unformatted("# type: int"); no_unformatted("# type: list[str]"); + + no_unformatted("# yapf: enable"); + no_unformatted("# yapf: disable"); } #[test] @@ -449,6 +475,9 @@ mod tests { has_unformatted("# type:\t\t\tignore"); has_unformatted("#\t \t \ttype:\t\t \tint"); + + has_unformatted("#\t \tyapf: \t \tenable"); + has_unformatted("#\t\tyapf: \t\tdisable"); } #[test] @@ -485,6 +514,6 @@ mod tests { composite_has_unformatted("# isort:skip#noqa:A123", 2); composite_has_unformatted("# fmt:off# noqa: A123", 2); - composite_has_unformatted("# noqa:A123 - Lorem ipsum dolor sit amet", 1); + composite_has_unformatted("# noqa:A123, B456 - Lorem ipsum dolor sit amet", 1); } } diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037.py.snap index bf35ba38113c63..0af64a9276e1c0 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037.py.snap @@ -2,701 +2,781 @@ source: crates/ruff_linter/src/rules/ruff/mod.rs snapshot_kind: text --- -RUF037.py:34:3: RUF037 [*] Unformatted special comment +RUF037.py:15:2: RUF037 [*] Unformatted special comment | -32 | # type: list[str] -33 | -34 | # noqa:A123 +13 | # yapf: Disable +14 | # Yapf: disable +15 | #yapf: enable + | ^^^^ RUF037 +16 | # yapf : enable +17 | # yapf:disable + | + = help: Format comment + +ℹ Safe fix +12 12 | # Type: ignore +13 13 | # yapf: Disable +14 14 | # Yapf: disable +15 |-#yapf: enable + 15 |+# yapf: enable +16 16 | # yapf : enable +17 17 | # yapf:disable +18 18 | + +RUF037.py:17:3: RUF037 [*] Unformatted special comment + | +15 | #yapf: enable +16 | # yapf : enable +17 | # yapf:disable + | ^^^^ RUF037 +18 | +19 | # noqa + | + = help: Format comment + +ℹ Safe fix +14 14 | # Yapf: disable +15 15 | #yapf: enable +16 16 | # yapf : enable +17 |-# yapf:disable + 17 |+# yapf: disable +18 18 | +19 19 | # noqa +20 20 | # noqa: A123 + +RUF037.py:43:3: RUF037 [*] Unformatted special comment + | +41 | # yapf: enable +42 | # yapf: disable +43 | # noqa:A123 | ^^^^ RUF037 -35 | #noqa: A123 -36 | # type:ignore +44 | #noqa: A123 +45 | # type:ignore | = help: Format comment ℹ Safe fix -31 31 | # type: int -32 32 | # type: list[str] -33 33 | -34 |-# noqa:A123 - 34 |+# noqa: A123 -35 35 | #noqa: A123 -36 36 | # type:ignore -37 37 | #type: int +40 40 | # type: list[str] +41 41 | # yapf: enable +42 42 | # yapf: disable +43 |-# noqa:A123 + 43 |+# noqa: A123 +44 44 | #noqa: A123 +45 45 | # type:ignore +46 46 | #type: int -RUF037.py:35:2: RUF037 [*] Unformatted special comment +RUF037.py:44:2: RUF037 [*] Unformatted special comment | -34 | # noqa:A123 -35 | #noqa: A123 +42 | # yapf: disable +43 | # noqa:A123 +44 | #noqa: A123 | ^^^^ RUF037 -36 | # type:ignore -37 | #type: int +45 | # type:ignore +46 | #type: int | = help: Format comment ℹ Safe fix -32 32 | # type: list[str] -33 33 | -34 34 | # noqa:A123 -35 |-#noqa: A123 - 35 |+# noqa: A123 -36 36 | # type:ignore -37 37 | #type: int -38 38 | # fmt:off +41 41 | # yapf: enable +42 42 | # yapf: disable +43 43 | # noqa:A123 +44 |-#noqa: A123 + 44 |+# noqa: A123 +45 45 | # type:ignore +46 46 | #type: int +47 47 | # fmt:off -RUF037.py:36:6: RUF037 [*] Unformatted special comment +RUF037.py:45:6: RUF037 [*] Unformatted special comment | -34 | # noqa:A123 -35 | #noqa: A123 -36 | # type:ignore +43 | # noqa:A123 +44 | #noqa: A123 +45 | # type:ignore | ^^^^ RUF037 -37 | #type: int -38 | # fmt:off +46 | #type: int +47 | # fmt:off | = help: Format comment ℹ Safe fix -33 33 | -34 34 | # noqa:A123 -35 35 | #noqa: A123 -36 |-# type:ignore - 36 |+# type: ignore -37 37 | #type: int -38 38 | # fmt:off -39 39 | #fmt: on +42 42 | # yapf: disable +43 43 | # noqa:A123 +44 44 | #noqa: A123 +45 |-# type:ignore + 45 |+# type: ignore +46 46 | #type: int +47 47 | # fmt:off +48 48 | #fmt: on -RUF037.py:37:2: RUF037 [*] Unformatted special comment +RUF037.py:46:2: RUF037 [*] Unformatted special comment | -35 | #noqa: A123 -36 | # type:ignore -37 | #type: int +44 | #noqa: A123 +45 | # type:ignore +46 | #type: int | ^^^^ RUF037 -38 | # fmt:off -39 | #fmt: on +47 | # fmt:off +48 | #fmt: on | = help: Format comment ℹ Safe fix -34 34 | # noqa:A123 -35 35 | #noqa: A123 -36 36 | # type:ignore -37 |-#type: int - 37 |+# type: int -38 38 | # fmt:off -39 39 | #fmt: on -40 40 | # fmt: skip +43 43 | # noqa:A123 +44 44 | #noqa: A123 +45 45 | # type:ignore +46 |-#type: int + 46 |+# type: int +47 47 | # fmt:off +48 48 | #fmt: on +49 49 | # fmt: skip -RUF037.py:38:3: RUF037 [*] Unformatted special comment +RUF037.py:47:3: RUF037 [*] Unformatted special comment | -36 | # type:ignore -37 | #type: int -38 | # fmt:off +45 | # type:ignore +46 | #type: int +47 | # fmt:off | ^^^ RUF037 -39 | #fmt: on -40 | # fmt: skip +48 | #fmt: on +49 | # fmt: skip | = help: Format comment ℹ Safe fix -35 35 | #noqa: A123 -36 36 | # type:ignore -37 37 | #type: int -38 |-# fmt:off - 38 |+# fmt: off -39 39 | #fmt: on -40 40 | # fmt: skip -41 41 | # isort:skip +44 44 | #noqa: A123 +45 45 | # type:ignore +46 46 | #type: int +47 |-# fmt:off + 47 |+# fmt: off +48 48 | #fmt: on +49 49 | # fmt: skip +50 50 | # isort:skip -RUF037.py:39:2: RUF037 [*] Unformatted special comment +RUF037.py:48:2: RUF037 [*] Unformatted special comment | -37 | #type: int -38 | # fmt:off -39 | #fmt: on +46 | #type: int +47 | # fmt:off +48 | #fmt: on | ^^^ RUF037 -40 | # fmt: skip -41 | # isort:skip +49 | # fmt: skip +50 | # isort:skip | = help: Format comment ℹ Safe fix -36 36 | # type:ignore -37 37 | #type: int -38 38 | # fmt:off -39 |-#fmt: on - 39 |+# fmt: on -40 40 | # fmt: skip -41 41 | # isort:skip -42 42 | # isort:skip_file +45 45 | # type:ignore +46 46 | #type: int +47 47 | # fmt:off +48 |-#fmt: on + 48 |+# fmt: on +49 49 | # fmt: skip +50 50 | # isort:skip +51 51 | # isort:skip_file -RUF037.py:40:5: RUF037 [*] Unformatted special comment +RUF037.py:49:5: RUF037 [*] Unformatted special comment | -38 | # fmt:off -39 | #fmt: on -40 | # fmt: skip +47 | # fmt:off +48 | #fmt: on +49 | # fmt: skip | ^^^ RUF037 -41 | # isort:skip -42 | # isort:skip_file +50 | # isort:skip +51 | # isort:skip_file | = help: Format comment ℹ Safe fix -37 37 | #type: int -38 38 | # fmt:off -39 39 | #fmt: on -40 |-# fmt: skip - 40 |+# fmt: skip -41 41 | # isort:skip -42 42 | # isort:skip_file -43 43 | # ruff: isort:skip +46 46 | #type: int +47 47 | # fmt:off +48 48 | #fmt: on +49 |-# fmt: skip + 49 |+# fmt: skip +50 50 | # isort:skip +51 51 | # isort:skip_file +52 52 | # ruff: isort:skip -RUF037.py:41:3: RUF037 [*] Unformatted special comment +RUF037.py:50:3: RUF037 [*] Unformatted special comment | -39 | #fmt: on -40 | # fmt: skip -41 | # isort:skip +48 | #fmt: on +49 | # fmt: skip +50 | # isort:skip | ^^^^^ RUF037 -42 | # isort:skip_file -43 | # ruff: isort:skip +51 | # isort:skip_file +52 | # ruff: isort:skip | = help: Format comment ℹ Safe fix -38 38 | # fmt:off -39 39 | #fmt: on -40 40 | # fmt: skip -41 |-# isort:skip - 41 |+# isort: skip -42 42 | # isort:skip_file -43 43 | # ruff: isort:skip -44 44 | # ruff: isort:skip_file +47 47 | # fmt:off +48 48 | #fmt: on +49 49 | # fmt: skip +50 |-# isort:skip + 50 |+# isort: skip +51 51 | # isort:skip_file +52 52 | # ruff: isort:skip +53 53 | # ruff: isort:skip_file -RUF037.py:42:3: RUF037 [*] Unformatted special comment +RUF037.py:51:3: RUF037 [*] Unformatted special comment | -40 | # fmt: skip -41 | # isort:skip -42 | # isort:skip_file +49 | # fmt: skip +50 | # isort:skip +51 | # isort:skip_file | ^^^^^ RUF037 -43 | # ruff: isort:skip -44 | # ruff: isort:skip_file +52 | # ruff: isort:skip +53 | # ruff: isort:skip_file | = help: Format comment ℹ Safe fix -39 39 | #fmt: on -40 40 | # fmt: skip -41 41 | # isort:skip -42 |-# isort:skip_file - 42 |+# isort: skip_file -43 43 | # ruff: isort:skip -44 44 | # ruff: isort:skip_file -45 45 | # type: ignore +48 48 | #fmt: on +49 49 | # fmt: skip +50 50 | # isort:skip +51 |-# isort:skip_file + 51 |+# isort: skip_file +52 52 | # ruff: isort:skip +53 53 | # ruff: isort:skip_file +54 54 | # type: ignore -RUF037.py:43:3: RUF037 [*] Unformatted special comment +RUF037.py:52:3: RUF037 [*] Unformatted special comment | -41 | # isort:skip -42 | # isort:skip_file -43 | # ruff: isort:skip +50 | # isort:skip +51 | # isort:skip_file +52 | # ruff: isort:skip | ^^^^ RUF037 -44 | # ruff: isort:skip_file -45 | # type: ignore +53 | # ruff: isort:skip_file +54 | # type: ignore | = help: Format comment ℹ Safe fix -40 40 | # fmt: skip -41 41 | # isort:skip -42 42 | # isort:skip_file -43 |-# ruff: isort:skip - 43 |+# ruff: isort: skip -44 44 | # ruff: isort:skip_file -45 45 | # type: ignore -46 46 | # type: int +49 49 | # fmt: skip +50 50 | # isort:skip +51 51 | # isort:skip_file +52 |-# ruff: isort:skip + 52 |+# ruff: isort: skip +53 53 | # ruff: isort:skip_file +54 54 | # type: ignore +55 55 | # type: int -RUF037.py:44:3: RUF037 [*] Unformatted special comment +RUF037.py:53:3: RUF037 [*] Unformatted special comment | -42 | # isort:skip_file -43 | # ruff: isort:skip -44 | # ruff: isort:skip_file +51 | # isort:skip_file +52 | # ruff: isort:skip +53 | # ruff: isort:skip_file | ^^^^ RUF037 -45 | # type: ignore -46 | # type: int +54 | # type: ignore +55 | # type: int | = help: Format comment ℹ Safe fix -41 41 | # isort:skip -42 42 | # isort:skip_file -43 43 | # ruff: isort:skip -44 |-# ruff: isort:skip_file - 44 |+# ruff: isort: skip_file -45 45 | # type: ignore -46 46 | # type: int -47 47 | +50 50 | # isort:skip +51 51 | # isort:skip_file +52 52 | # ruff: isort:skip +53 |-# ruff: isort:skip_file + 53 |+# ruff: isort: skip_file +54 54 | # type: ignore +55 55 | # type: int +56 56 | # yapf: enable -RUF037.py:45:6: RUF037 [*] Unformatted special comment +RUF037.py:54:6: RUF037 [*] Unformatted special comment | -43 | # ruff: isort:skip -44 | # ruff: isort:skip_file -45 | # type: ignore +52 | # ruff: isort:skip +53 | # ruff: isort:skip_file +54 | # type: ignore | ^^^^ RUF037 -46 | # type: int +55 | # type: int +56 | # yapf: enable | = help: Format comment ℹ Safe fix -42 42 | # isort:skip_file -43 43 | # ruff: isort:skip -44 44 | # ruff: isort:skip_file -45 |-# type: ignore - 45 |+# type: ignore -46 46 | # type: int -47 47 | -48 48 | # NoQA: A123, B456 +51 51 | # isort:skip_file +52 52 | # ruff: isort:skip +53 53 | # ruff: isort:skip_file +54 |-# type: ignore + 54 |+# type: ignore +55 55 | # type: int +56 56 | # yapf: enable +57 57 | # yapf: disable -RUF037.py:46:7: RUF037 [*] Unformatted special comment +RUF037.py:55:7: RUF037 [*] Unformatted special comment | -44 | # ruff: isort:skip_file -45 | # type: ignore -46 | # type: int +53 | # ruff: isort:skip_file +54 | # type: ignore +55 | # type: int | ^^^^ RUF037 -47 | -48 | # NoQA: A123, B456 +56 | # yapf: enable +57 | # yapf: disable | = help: Format comment ℹ Safe fix -43 43 | # ruff: isort:skip -44 44 | # ruff: isort:skip_file -45 45 | # type: ignore -46 |-# type: int - 46 |+# type: int -47 47 | -48 48 | # NoQA: A123, B456 -49 49 | # ruff: NoQA: A123, B456 +52 52 | # ruff: isort:skip +53 53 | # ruff: isort:skip_file +54 54 | # type: ignore +55 |-# type: int + 55 |+# type: int +56 56 | # yapf: enable +57 57 | # yapf: disable +58 58 | + +RUF037.py:56:6: RUF037 [*] Unformatted special comment + | +54 | # type: ignore +55 | # type: int +56 | # yapf: enable + | ^^^^ RUF037 +57 | # yapf: disable + | + = help: Format comment + +ℹ Safe fix +53 53 | # ruff: isort:skip_file +54 54 | # type: ignore +55 55 | # type: int +56 |-# yapf: enable + 56 |+# yapf: enable +57 57 | # yapf: disable +58 58 | +59 59 | # NoQA: A123, B456 + +RUF037.py:57:4: RUF037 [*] Unformatted special comment + | +55 | # type: int +56 | # yapf: enable +57 | # yapf: disable + | ^^^^ RUF037 +58 | +59 | # NoQA: A123, B456 + | + = help: Format comment + +ℹ Safe fix +54 54 | # type: ignore +55 55 | # type: int +56 56 | # yapf: enable +57 |-# yapf: disable + 57 |+# yapf: disable +58 58 | +59 59 | # NoQA: A123, B456 +60 60 | # ruff: NoQA: A123, B456 -RUF037.py:48:3: RUF037 [*] Unformatted special comment +RUF037.py:59:3: RUF037 [*] Unformatted special comment | -46 | # type: int -47 | -48 | # NoQA: A123, B456 +57 | # yapf: disable +58 | +59 | # NoQA: A123, B456 | ^^^^ RUF037 -49 | # ruff: NoQA: A123, B456 -50 | # flake8: NoQA: A123, B456 +60 | # ruff: NoQA: A123, B456 +61 | # flake8: NoQA: A123, B456 | = help: Format comment ℹ Safe fix -45 45 | # type: ignore -46 46 | # type: int -47 47 | -48 |-# NoQA: A123, B456 - 48 |+# noqa: A123, B456 -49 49 | # ruff: NoQA: A123, B456 -50 50 | # flake8: NoQA: A123, B456 -51 51 | +56 56 | # yapf: enable +57 57 | # yapf: disable +58 58 | +59 |-# NoQA: A123, B456 + 59 |+# noqa: A123, B456 +60 60 | # ruff: NoQA: A123, B456 +61 61 | # flake8: NoQA: A123, B456 +62 62 | -RUF037.py:49:3: RUF037 [*] Unformatted special comment +RUF037.py:60:3: RUF037 [*] Unformatted special comment | -48 | # NoQA: A123, B456 -49 | # ruff: NoQA: A123, B456 +59 | # NoQA: A123, B456 +60 | # ruff: NoQA: A123, B456 | ^^^^ RUF037 -50 | # flake8: NoQA: A123, B456 +61 | # flake8: NoQA: A123, B456 | = help: Format comment ℹ Safe fix -46 46 | # type: int -47 47 | -48 48 | # NoQA: A123, B456 -49 |-# ruff: NoQA: A123, B456 - 49 |+# ruff: noqa: A123, B456 -50 50 | # flake8: NoQA: A123, B456 -51 51 | -52 52 | # noqa: A123 B456 +57 57 | # yapf: disable +58 58 | +59 59 | # NoQA: A123, B456 +60 |-# ruff: NoQA: A123, B456 + 60 |+# ruff: noqa: A123, B456 +61 61 | # flake8: NoQA: A123, B456 +62 62 | +63 63 | # noqa: A123 B456 -RUF037.py:50:3: RUF037 [*] Unformatted special comment +RUF037.py:61:3: RUF037 [*] Unformatted special comment | -48 | # NoQA: A123, B456 -49 | # ruff: NoQA: A123, B456 -50 | # flake8: NoQA: A123, B456 +59 | # NoQA: A123, B456 +60 | # ruff: NoQA: A123, B456 +61 | # flake8: NoQA: A123, B456 | ^^^^^^ RUF037 -51 | -52 | # noqa: A123 B456 +62 | +63 | # noqa: A123 B456 | = help: Format comment ℹ Safe fix -47 47 | -48 48 | # NoQA: A123, B456 -49 49 | # ruff: NoQA: A123, B456 -50 |-# flake8: NoQA: A123, B456 - 50 |+# flake8: noqa: A123, B456 -51 51 | -52 52 | # noqa: A123 B456 -53 53 | # ruff: noqa: A123 B456 +58 58 | +59 59 | # NoQA: A123, B456 +60 60 | # ruff: NoQA: A123, B456 +61 |-# flake8: NoQA: A123, B456 + 61 |+# flake8: noqa: A123, B456 +62 62 | +63 63 | # noqa: A123 B456 +64 64 | # ruff: noqa: A123 B456 -RUF037.py:52:3: RUF037 [*] Unformatted special comment +RUF037.py:63:3: RUF037 [*] Unformatted special comment | -50 | # flake8: NoQA: A123, B456 -51 | -52 | # noqa: A123 B456 +61 | # flake8: NoQA: A123, B456 +62 | +63 | # noqa: A123 B456 | ^^^^ RUF037 -53 | # ruff: noqa: A123 B456 -54 | # flake8: noqa: A123 B456 +64 | # ruff: noqa: A123 B456 +65 | # flake8: noqa: A123 B456 | = help: Format comment ℹ Safe fix -49 49 | # ruff: NoQA: A123, B456 -50 50 | # flake8: NoQA: A123, B456 -51 51 | -52 |-# noqa: A123 B456 - 52 |+# noqa: A123, B456 -53 53 | # ruff: noqa: A123 B456 -54 54 | # flake8: noqa: A123 B456 -55 55 | # noqa: A123,B456 +60 60 | # ruff: NoQA: A123, B456 +61 61 | # flake8: NoQA: A123, B456 +62 62 | +63 |-# noqa: A123 B456 + 63 |+# noqa: A123, B456 +64 64 | # ruff: noqa: A123 B456 +65 65 | # flake8: noqa: A123 B456 +66 66 | # noqa: A123,B456 -RUF037.py:53:3: RUF037 [*] Unformatted special comment +RUF037.py:64:3: RUF037 [*] Unformatted special comment | -52 | # noqa: A123 B456 -53 | # ruff: noqa: A123 B456 +63 | # noqa: A123 B456 +64 | # ruff: noqa: A123 B456 | ^^^^ RUF037 -54 | # flake8: noqa: A123 B456 -55 | # noqa: A123,B456 +65 | # flake8: noqa: A123 B456 +66 | # noqa: A123,B456 | = help: Format comment ℹ Safe fix -50 50 | # flake8: NoQA: A123, B456 -51 51 | -52 52 | # noqa: A123 B456 -53 |-# ruff: noqa: A123 B456 - 53 |+# ruff: noqa: A123, B456 -54 54 | # flake8: noqa: A123 B456 -55 55 | # noqa: A123,B456 -56 56 | # ruff: noqa: A123,B456 +61 61 | # flake8: NoQA: A123, B456 +62 62 | +63 63 | # noqa: A123 B456 +64 |-# ruff: noqa: A123 B456 + 64 |+# ruff: noqa: A123, B456 +65 65 | # flake8: noqa: A123 B456 +66 66 | # noqa: A123,B456 +67 67 | # ruff: noqa: A123,B456 -RUF037.py:54:3: RUF037 [*] Unformatted special comment +RUF037.py:65:3: RUF037 [*] Unformatted special comment | -52 | # noqa: A123 B456 -53 | # ruff: noqa: A123 B456 -54 | # flake8: noqa: A123 B456 +63 | # noqa: A123 B456 +64 | # ruff: noqa: A123 B456 +65 | # flake8: noqa: A123 B456 | ^^^^^^ RUF037 -55 | # noqa: A123,B456 -56 | # ruff: noqa: A123,B456 +66 | # noqa: A123,B456 +67 | # ruff: noqa: A123,B456 | = help: Format comment ℹ Safe fix -51 51 | -52 52 | # noqa: A123 B456 -53 53 | # ruff: noqa: A123 B456 -54 |-# flake8: noqa: A123 B456 - 54 |+# flake8: noqa: A123, B456 -55 55 | # noqa: A123,B456 -56 56 | # ruff: noqa: A123,B456 -57 57 | # flake8: noqa: A123,B456 +62 62 | +63 63 | # noqa: A123 B456 +64 64 | # ruff: noqa: A123 B456 +65 |-# flake8: noqa: A123 B456 + 65 |+# flake8: noqa: A123, B456 +66 66 | # noqa: A123,B456 +67 67 | # ruff: noqa: A123,B456 +68 68 | # flake8: noqa: A123,B456 -RUF037.py:55:3: RUF037 [*] Unformatted special comment +RUF037.py:66:3: RUF037 [*] Unformatted special comment | -53 | # ruff: noqa: A123 B456 -54 | # flake8: noqa: A123 B456 -55 | # noqa: A123,B456 +64 | # ruff: noqa: A123 B456 +65 | # flake8: noqa: A123 B456 +66 | # noqa: A123,B456 | ^^^^ RUF037 -56 | # ruff: noqa: A123,B456 -57 | # flake8: noqa: A123,B456 +67 | # ruff: noqa: A123,B456 +68 | # flake8: noqa: A123,B456 | = help: Format comment ℹ Safe fix -52 52 | # noqa: A123 B456 -53 53 | # ruff: noqa: A123 B456 -54 54 | # flake8: noqa: A123 B456 -55 |-# noqa: A123,B456 - 55 |+# noqa: A123, B456 -56 56 | # ruff: noqa: A123,B456 -57 57 | # flake8: noqa: A123,B456 -58 58 | # noqa: A123,,B456 +63 63 | # noqa: A123 B456 +64 64 | # ruff: noqa: A123 B456 +65 65 | # flake8: noqa: A123 B456 +66 |-# noqa: A123,B456 + 66 |+# noqa: A123, B456 +67 67 | # ruff: noqa: A123,B456 +68 68 | # flake8: noqa: A123,B456 +69 69 | # noqa: A123,,B456 -RUF037.py:56:3: RUF037 [*] Unformatted special comment +RUF037.py:67:3: RUF037 [*] Unformatted special comment | -54 | # flake8: noqa: A123 B456 -55 | # noqa: A123,B456 -56 | # ruff: noqa: A123,B456 +65 | # flake8: noqa: A123 B456 +66 | # noqa: A123,B456 +67 | # ruff: noqa: A123,B456 | ^^^^ RUF037 -57 | # flake8: noqa: A123,B456 -58 | # noqa: A123,,B456 +68 | # flake8: noqa: A123,B456 +69 | # noqa: A123,,B456 | = help: Format comment ℹ Safe fix -53 53 | # ruff: noqa: A123 B456 -54 54 | # flake8: noqa: A123 B456 -55 55 | # noqa: A123,B456 -56 |-# ruff: noqa: A123,B456 - 56 |+# ruff: noqa: A123, B456 -57 57 | # flake8: noqa: A123,B456 -58 58 | # noqa: A123,,B456 -59 59 | # noqa: A123 , , B456 +64 64 | # ruff: noqa: A123 B456 +65 65 | # flake8: noqa: A123 B456 +66 66 | # noqa: A123,B456 +67 |-# ruff: noqa: A123,B456 + 67 |+# ruff: noqa: A123, B456 +68 68 | # flake8: noqa: A123,B456 +69 69 | # noqa: A123,,B456 +70 70 | # noqa: A123 , , B456 -RUF037.py:57:3: RUF037 [*] Unformatted special comment +RUF037.py:68:3: RUF037 [*] Unformatted special comment | -55 | # noqa: A123,B456 -56 | # ruff: noqa: A123,B456 -57 | # flake8: noqa: A123,B456 +66 | # noqa: A123,B456 +67 | # ruff: noqa: A123,B456 +68 | # flake8: noqa: A123,B456 | ^^^^^^ RUF037 -58 | # noqa: A123,,B456 -59 | # noqa: A123 , , B456 +69 | # noqa: A123,,B456 +70 | # noqa: A123 , , B456 | = help: Format comment ℹ Safe fix -54 54 | # flake8: noqa: A123 B456 -55 55 | # noqa: A123,B456 -56 56 | # ruff: noqa: A123,B456 -57 |-# flake8: noqa: A123,B456 - 57 |+# flake8: noqa: A123, B456 -58 58 | # noqa: A123,,B456 -59 59 | # noqa: A123 , , B456 -60 60 | # noqa: A123 B456 +65 65 | # flake8: noqa: A123 B456 +66 66 | # noqa: A123,B456 +67 67 | # ruff: noqa: A123,B456 +68 |-# flake8: noqa: A123,B456 + 68 |+# flake8: noqa: A123, B456 +69 69 | # noqa: A123,,B456 +70 70 | # noqa: A123 , , B456 +71 71 | # noqa: A123 B456 -RUF037.py:58:3: RUF037 [*] Unformatted special comment +RUF037.py:69:3: RUF037 [*] Unformatted special comment | -56 | # ruff: noqa: A123,B456 -57 | # flake8: noqa: A123,B456 -58 | # noqa: A123,,B456 +67 | # ruff: noqa: A123,B456 +68 | # flake8: noqa: A123,B456 +69 | # noqa: A123,,B456 | ^^^^ RUF037 -59 | # noqa: A123 , , B456 -60 | # noqa: A123 B456 +70 | # noqa: A123 , , B456 +71 | # noqa: A123 B456 | = help: Format comment ℹ Safe fix -55 55 | # noqa: A123,B456 -56 56 | # ruff: noqa: A123,B456 -57 57 | # flake8: noqa: A123,B456 -58 |-# noqa: A123,,B456 - 58 |+# noqa: A123, B456 -59 59 | # noqa: A123 , , B456 -60 60 | # noqa: A123 B456 -61 61 | # noqa: A123 B456 +66 66 | # noqa: A123,B456 +67 67 | # ruff: noqa: A123,B456 +68 68 | # flake8: noqa: A123,B456 +69 |-# noqa: A123,,B456 + 69 |+# noqa: A123, B456 +70 70 | # noqa: A123 , , B456 +71 71 | # noqa: A123 B456 +72 72 | # noqa: A123 B456 -RUF037.py:59:3: RUF037 [*] Unformatted special comment +RUF037.py:70:3: RUF037 [*] Unformatted special comment | -57 | # flake8: noqa: A123,B456 -58 | # noqa: A123,,B456 -59 | # noqa: A123 , , B456 +68 | # flake8: noqa: A123,B456 +69 | # noqa: A123,,B456 +70 | # noqa: A123 , , B456 | ^^^^ RUF037 -60 | # noqa: A123 B456 -61 | # noqa: A123 B456 +71 | # noqa: A123 B456 +72 | # noqa: A123 B456 | = help: Format comment ℹ Safe fix -56 56 | # ruff: noqa: A123,B456 -57 57 | # flake8: noqa: A123,B456 -58 58 | # noqa: A123,,B456 -59 |-# noqa: A123 , , B456 - 59 |+# noqa: A123, B456 -60 60 | # noqa: A123 B456 -61 61 | # noqa: A123 B456 -62 62 | # noqa: A123 B456 +67 67 | # ruff: noqa: A123,B456 +68 68 | # flake8: noqa: A123,B456 +69 69 | # noqa: A123,,B456 +70 |-# noqa: A123 , , B456 + 70 |+# noqa: A123, B456 +71 71 | # noqa: A123 B456 +72 72 | # noqa: A123 B456 +73 73 | # noqa: A123 B456 -RUF037.py:60:3: RUF037 [*] Unformatted special comment +RUF037.py:71:3: RUF037 [*] Unformatted special comment | -58 | # noqa: A123,,B456 -59 | # noqa: A123 , , B456 -60 | # noqa: A123 B456 +69 | # noqa: A123,,B456 +70 | # noqa: A123 , , B456 +71 | # noqa: A123 B456 | ^^^^ RUF037 -61 | # noqa: A123 B456 -62 | # noqa: A123 B456 +72 | # noqa: A123 B456 +73 | # noqa: A123 B456 | = help: Format comment ℹ Safe fix -57 57 | # flake8: noqa: A123,B456 -58 58 | # noqa: A123,,B456 -59 59 | # noqa: A123 , , B456 -60 |-# noqa: A123 B456 - 60 |+# noqa: A123, B456 -61 61 | # noqa: A123 B456 -62 62 | # noqa: A123 B456 -63 63 | # noqa: A123 ,B456 +68 68 | # flake8: noqa: A123,B456 +69 69 | # noqa: A123,,B456 +70 70 | # noqa: A123 , , B456 +71 |-# noqa: A123 B456 + 71 |+# noqa: A123, B456 +72 72 | # noqa: A123 B456 +73 73 | # noqa: A123 B456 +74 74 | # noqa: A123 ,B456 -RUF037.py:61:3: RUF037 [*] Unformatted special comment +RUF037.py:72:3: RUF037 [*] Unformatted special comment | -59 | # noqa: A123 , , B456 -60 | # noqa: A123 B456 -61 | # noqa: A123 B456 +70 | # noqa: A123 , , B456 +71 | # noqa: A123 B456 +72 | # noqa: A123 B456 | ^^^^ RUF037 -62 | # noqa: A123 B456 -63 | # noqa: A123 ,B456 +73 | # noqa: A123 B456 +74 | # noqa: A123 ,B456 | = help: Format comment ℹ Safe fix -58 58 | # noqa: A123,,B456 -59 59 | # noqa: A123 , , B456 -60 60 | # noqa: A123 B456 -61 |-# noqa: A123 B456 - 61 |+# noqa: A123, B456 -62 62 | # noqa: A123 B456 -63 63 | # noqa: A123 ,B456 -64 64 | # ruff: noqa: A123 B456 +69 69 | # noqa: A123,,B456 +70 70 | # noqa: A123 , , B456 +71 71 | # noqa: A123 B456 +72 |-# noqa: A123 B456 + 72 |+# noqa: A123, B456 +73 73 | # noqa: A123 B456 +74 74 | # noqa: A123 ,B456 +75 75 | # ruff: noqa: A123 B456 -RUF037.py:62:3: RUF037 [*] Unformatted special comment +RUF037.py:73:3: RUF037 [*] Unformatted special comment | -60 | # noqa: A123 B456 -61 | # noqa: A123 B456 -62 | # noqa: A123 B456 +71 | # noqa: A123 B456 +72 | # noqa: A123 B456 +73 | # noqa: A123 B456 | ^^^^ RUF037 -63 | # noqa: A123 ,B456 -64 | # ruff: noqa: A123 B456 +74 | # noqa: A123 ,B456 +75 | # ruff: noqa: A123 B456 | = help: Format comment ℹ Safe fix -59 59 | # noqa: A123 , , B456 -60 60 | # noqa: A123 B456 -61 61 | # noqa: A123 B456 -62 |-# noqa: A123 B456 - 62 |+# noqa: A123, B456 -63 63 | # noqa: A123 ,B456 -64 64 | # ruff: noqa: A123 B456 -65 65 | # flake8: noqa: A123 B456 +70 70 | # noqa: A123 , , B456 +71 71 | # noqa: A123 B456 +72 72 | # noqa: A123 B456 +73 |-# noqa: A123 B456 + 73 |+# noqa: A123, B456 +74 74 | # noqa: A123 ,B456 +75 75 | # ruff: noqa: A123 B456 +76 76 | # flake8: noqa: A123 B456 -RUF037.py:63:3: RUF037 [*] Unformatted special comment +RUF037.py:74:3: RUF037 [*] Unformatted special comment | -61 | # noqa: A123 B456 -62 | # noqa: A123 B456 -63 | # noqa: A123 ,B456 +72 | # noqa: A123 B456 +73 | # noqa: A123 B456 +74 | # noqa: A123 ,B456 | ^^^^ RUF037 -64 | # ruff: noqa: A123 B456 -65 | # flake8: noqa: A123 B456 +75 | # ruff: noqa: A123 B456 +76 | # flake8: noqa: A123 B456 | = help: Format comment ℹ Safe fix -60 60 | # noqa: A123 B456 -61 61 | # noqa: A123 B456 -62 62 | # noqa: A123 B456 -63 |-# noqa: A123 ,B456 - 63 |+# noqa: A123, B456 -64 64 | # ruff: noqa: A123 B456 -65 65 | # flake8: noqa: A123 B456 -66 66 | +71 71 | # noqa: A123 B456 +72 72 | # noqa: A123 B456 +73 73 | # noqa: A123 B456 +74 |-# noqa: A123 ,B456 + 74 |+# noqa: A123, B456 +75 75 | # ruff: noqa: A123 B456 +76 76 | # flake8: noqa: A123 B456 +77 77 | -RUF037.py:64:3: RUF037 [*] Unformatted special comment +RUF037.py:75:3: RUF037 [*] Unformatted special comment | -62 | # noqa: A123 B456 -63 | # noqa: A123 ,B456 -64 | # ruff: noqa: A123 B456 +73 | # noqa: A123 B456 +74 | # noqa: A123 ,B456 +75 | # ruff: noqa: A123 B456 | ^^^^ RUF037 -65 | # flake8: noqa: A123 B456 +76 | # flake8: noqa: A123 B456 | = help: Format comment ℹ Safe fix -61 61 | # noqa: A123 B456 -62 62 | # noqa: A123 B456 -63 63 | # noqa: A123 ,B456 -64 |-# ruff: noqa: A123 B456 - 64 |+# ruff: noqa: A123, B456 -65 65 | # flake8: noqa: A123 B456 -66 66 | -67 67 | +72 72 | # noqa: A123 B456 +73 73 | # noqa: A123 B456 +74 74 | # noqa: A123 ,B456 +75 |-# ruff: noqa: A123 B456 + 75 |+# ruff: noqa: A123, B456 +76 76 | # flake8: noqa: A123 B456 +77 77 | +78 78 | -RUF037.py:65:3: RUF037 [*] Unformatted special comment +RUF037.py:76:3: RUF037 [*] Unformatted special comment | -63 | # noqa: A123 ,B456 -64 | # ruff: noqa: A123 B456 -65 | # flake8: noqa: A123 B456 +74 | # noqa: A123 ,B456 +75 | # ruff: noqa: A123 B456 +76 | # flake8: noqa: A123 B456 | ^^^^^^ RUF037 | = help: Format comment ℹ Safe fix -62 62 | # noqa: A123 B456 -63 63 | # noqa: A123 ,B456 -64 64 | # ruff: noqa: A123 B456 -65 |-# flake8: noqa: A123 B456 - 65 |+# flake8: noqa: A123, B456 -66 66 | -67 67 | -68 68 | # type: ignore # noqa: A123, B456 +73 73 | # noqa: A123 B456 +74 74 | # noqa: A123 ,B456 +75 75 | # ruff: noqa: A123 B456 +76 |-# flake8: noqa: A123 B456 + 76 |+# flake8: noqa: A123, B456 +77 77 | +78 78 | +79 79 | # type: ignore # noqa: A123, B456 -RUF037.py:70:13: RUF037 [*] Unformatted special comment +RUF037.py:81:13: RUF037 [*] Unformatted special comment | -68 | # type: ignore # noqa: A123, B456 -69 | -70 | #isort:skip#noqa:A123 +79 | # type: ignore # noqa: A123, B456 +80 | +81 | #isort:skip#noqa:A123 | ^^^^ RUF037 -71 | -72 | # fmt:off# noqa: A123 +82 | +83 | # fmt:off# noqa: A123 | = help: Format comment ℹ Safe fix -67 67 | -68 68 | # type: ignore # noqa: A123, B456 -69 69 | -70 |-#isort:skip#noqa:A123 - 70 |+#isort:skip# noqa: A123 -71 71 | -72 72 | # fmt:off# noqa: A123 -73 73 | +78 78 | +79 79 | # type: ignore # noqa: A123, B456 +80 80 | +81 |-#isort:skip#noqa:A123 + 81 |+#isort:skip# noqa: A123 +82 82 | +83 83 | # fmt:off# noqa: A123 +84 84 | # noqa:A123, B456 - Lorem ipsum dolor sit amet -RUF037.py:72:3: RUF037 [*] Unformatted special comment +RUF037.py:83:3: RUF037 [*] Unformatted special comment | -70 | #isort:skip#noqa:A123 -71 | -72 | # fmt:off# noqa: A123 +81 | #isort:skip#noqa:A123 +82 | +83 | # fmt:off# noqa: A123 | ^^^ RUF037 -73 | -74 | # noqa:A123 - Lorem ipsum dolor sit amet +84 | # noqa:A123, B456 - Lorem ipsum dolor sit amet | = help: Format comment ℹ Safe fix -69 69 | -70 70 | #isort:skip#noqa:A123 -71 71 | -72 |-# fmt:off# noqa: A123 - 72 |+# fmt: off# noqa: A123 -73 73 | -74 74 | # noqa:A123 - Lorem ipsum dolor sit amet +80 80 | +81 81 | #isort:skip#noqa:A123 +82 82 | +83 |-# fmt:off# noqa: A123 + 83 |+# fmt: off# noqa: A123 +84 84 | # noqa:A123, B456 - Lorem ipsum dolor sit amet -RUF037.py:72:14: RUF037 [*] Unformatted special comment +RUF037.py:83:14: RUF037 [*] Unformatted special comment | -70 | #isort:skip#noqa:A123 -71 | -72 | # fmt:off# noqa: A123 +81 | #isort:skip#noqa:A123 +82 | +83 | # fmt:off# noqa: A123 | ^^^^ RUF037 -73 | -74 | # noqa:A123 - Lorem ipsum dolor sit amet +84 | # noqa:A123, B456 - Lorem ipsum dolor sit amet | = help: Format comment ℹ Safe fix -69 69 | -70 70 | #isort:skip#noqa:A123 -71 71 | -72 |-# fmt:off# noqa: A123 - 72 |+# fmt:off# noqa: A123 -73 73 | -74 74 | # noqa:A123 - Lorem ipsum dolor sit amet +80 80 | +81 81 | #isort:skip#noqa:A123 +82 82 | +83 |-# fmt:off# noqa: A123 + 83 |+# fmt:off# noqa: A123 +84 84 | # noqa:A123, B456 - Lorem ipsum dolor sit amet -RUF037.py:74:3: RUF037 [*] Unformatted special comment +RUF037.py:84:3: RUF037 [*] Unformatted special comment | -72 | # fmt:off# noqa: A123 -73 | -74 | # noqa:A123 - Lorem ipsum dolor sit amet +83 | # fmt:off# noqa: A123 +84 | # noqa:A123, B456 - Lorem ipsum dolor sit amet | ^^^^ RUF037 | = help: Format comment ℹ Safe fix -71 71 | -72 72 | # fmt:off# noqa: A123 -73 73 | -74 |-# noqa:A123 - Lorem ipsum dolor sit amet - 74 |+# noqa: A123 - Lorem ipsum dolor sit amet +81 81 | #isort:skip#noqa:A123 +82 82 | +83 83 | # fmt:off# noqa: A123 +84 |-# noqa:A123, B456 - Lorem ipsum dolor sit amet + 84 |+# noqa: A123, B456 - Lorem ipsum dolor sit amet From 2fbd4a21da2e4120586f92ff3c3bf065dec0a411 Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Wed, 13 Nov 2024 19:30:17 +0000 Subject: [PATCH 29/29] Fix tests --- .../resources/test/fixtures/ruff/RUF037.py | 5 +- .../ruff/rules/unformatted_special_comment.rs | 5 +- ...uff__tests__preview__RUF037_RUF037.py.snap | 998 +++++++++--------- 3 files changed, 482 insertions(+), 526 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF037.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF037.py index 8bcb883a68fdb8..0a8132b5aaffb0 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF037.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF037.py @@ -12,9 +12,8 @@ # Type: ignore # yapf: Disable # Yapf: disable -#yapf: enable -# yapf : enable -# yapf:disable +#yapf : enable +# yapf : disable # noqa # noqa: A123 diff --git a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs index 170fe61d3f2644..ce38196fb12b2f 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unformatted_special_comment.rs @@ -415,9 +415,8 @@ mod tests { #[test] fn incorrect_whitespace() { - no_unformatted("#yapf: enable"); - no_unformatted("# yapf : enable"); - no_unformatted("# yapf:disable"); + no_unformatted("#yapf : enable"); + no_unformatted("# yapf : disable"); } #[test] diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037.py.snap index 0af64a9276e1c0..75f0a48537029b 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF037_RUF037.py.snap @@ -2,781 +2,739 @@ source: crates/ruff_linter/src/rules/ruff/mod.rs snapshot_kind: text --- -RUF037.py:15:2: RUF037 [*] Unformatted special comment +RUF037.py:42:3: RUF037 [*] Unformatted special comment | -13 | # yapf: Disable -14 | # Yapf: disable -15 | #yapf: enable - | ^^^^ RUF037 -16 | # yapf : enable -17 | # yapf:disable - | - = help: Format comment - -ℹ Safe fix -12 12 | # Type: ignore -13 13 | # yapf: Disable -14 14 | # Yapf: disable -15 |-#yapf: enable - 15 |+# yapf: enable -16 16 | # yapf : enable -17 17 | # yapf:disable -18 18 | - -RUF037.py:17:3: RUF037 [*] Unformatted special comment - | -15 | #yapf: enable -16 | # yapf : enable -17 | # yapf:disable +40 | # yapf: enable +41 | # yapf: disable +42 | # noqa:A123 | ^^^^ RUF037 -18 | -19 | # noqa +43 | #noqa: A123 +44 | # type:ignore | = help: Format comment ℹ Safe fix -14 14 | # Yapf: disable -15 15 | #yapf: enable -16 16 | # yapf : enable -17 |-# yapf:disable - 17 |+# yapf: disable -18 18 | -19 19 | # noqa -20 20 | # noqa: A123 +39 39 | # type: list[str] +40 40 | # yapf: enable +41 41 | # yapf: disable +42 |-# noqa:A123 + 42 |+# noqa: A123 +43 43 | #noqa: A123 +44 44 | # type:ignore +45 45 | #type: int -RUF037.py:43:3: RUF037 [*] Unformatted special comment +RUF037.py:43:2: RUF037 [*] Unformatted special comment | -41 | # yapf: enable -42 | # yapf: disable -43 | # noqa:A123 - | ^^^^ RUF037 -44 | #noqa: A123 -45 | # type:ignore - | - = help: Format comment - -ℹ Safe fix -40 40 | # type: list[str] -41 41 | # yapf: enable -42 42 | # yapf: disable -43 |-# noqa:A123 - 43 |+# noqa: A123 -44 44 | #noqa: A123 -45 45 | # type:ignore -46 46 | #type: int - -RUF037.py:44:2: RUF037 [*] Unformatted special comment - | -42 | # yapf: disable -43 | # noqa:A123 -44 | #noqa: A123 +41 | # yapf: disable +42 | # noqa:A123 +43 | #noqa: A123 | ^^^^ RUF037 -45 | # type:ignore -46 | #type: int +44 | # type:ignore +45 | #type: int | = help: Format comment ℹ Safe fix -41 41 | # yapf: enable -42 42 | # yapf: disable -43 43 | # noqa:A123 -44 |-#noqa: A123 - 44 |+# noqa: A123 -45 45 | # type:ignore -46 46 | #type: int -47 47 | # fmt:off +40 40 | # yapf: enable +41 41 | # yapf: disable +42 42 | # noqa:A123 +43 |-#noqa: A123 + 43 |+# noqa: A123 +44 44 | # type:ignore +45 45 | #type: int +46 46 | # fmt:off -RUF037.py:45:6: RUF037 [*] Unformatted special comment +RUF037.py:44:6: RUF037 [*] Unformatted special comment | -43 | # noqa:A123 -44 | #noqa: A123 -45 | # type:ignore +42 | # noqa:A123 +43 | #noqa: A123 +44 | # type:ignore | ^^^^ RUF037 -46 | #type: int -47 | # fmt:off +45 | #type: int +46 | # fmt:off | = help: Format comment ℹ Safe fix -42 42 | # yapf: disable -43 43 | # noqa:A123 -44 44 | #noqa: A123 -45 |-# type:ignore - 45 |+# type: ignore -46 46 | #type: int -47 47 | # fmt:off -48 48 | #fmt: on +41 41 | # yapf: disable +42 42 | # noqa:A123 +43 43 | #noqa: A123 +44 |-# type:ignore + 44 |+# type: ignore +45 45 | #type: int +46 46 | # fmt:off +47 47 | #fmt: on -RUF037.py:46:2: RUF037 [*] Unformatted special comment +RUF037.py:45:2: RUF037 [*] Unformatted special comment | -44 | #noqa: A123 -45 | # type:ignore -46 | #type: int +43 | #noqa: A123 +44 | # type:ignore +45 | #type: int | ^^^^ RUF037 -47 | # fmt:off -48 | #fmt: on +46 | # fmt:off +47 | #fmt: on | = help: Format comment ℹ Safe fix -43 43 | # noqa:A123 -44 44 | #noqa: A123 -45 45 | # type:ignore -46 |-#type: int - 46 |+# type: int -47 47 | # fmt:off -48 48 | #fmt: on -49 49 | # fmt: skip +42 42 | # noqa:A123 +43 43 | #noqa: A123 +44 44 | # type:ignore +45 |-#type: int + 45 |+# type: int +46 46 | # fmt:off +47 47 | #fmt: on +48 48 | # fmt: skip -RUF037.py:47:3: RUF037 [*] Unformatted special comment +RUF037.py:46:3: RUF037 [*] Unformatted special comment | -45 | # type:ignore -46 | #type: int -47 | # fmt:off +44 | # type:ignore +45 | #type: int +46 | # fmt:off | ^^^ RUF037 -48 | #fmt: on -49 | # fmt: skip +47 | #fmt: on +48 | # fmt: skip | = help: Format comment ℹ Safe fix -44 44 | #noqa: A123 -45 45 | # type:ignore -46 46 | #type: int -47 |-# fmt:off - 47 |+# fmt: off -48 48 | #fmt: on -49 49 | # fmt: skip -50 50 | # isort:skip +43 43 | #noqa: A123 +44 44 | # type:ignore +45 45 | #type: int +46 |-# fmt:off + 46 |+# fmt: off +47 47 | #fmt: on +48 48 | # fmt: skip +49 49 | # isort:skip -RUF037.py:48:2: RUF037 [*] Unformatted special comment +RUF037.py:47:2: RUF037 [*] Unformatted special comment | -46 | #type: int -47 | # fmt:off -48 | #fmt: on +45 | #type: int +46 | # fmt:off +47 | #fmt: on | ^^^ RUF037 -49 | # fmt: skip -50 | # isort:skip +48 | # fmt: skip +49 | # isort:skip | = help: Format comment ℹ Safe fix -45 45 | # type:ignore -46 46 | #type: int -47 47 | # fmt:off -48 |-#fmt: on - 48 |+# fmt: on -49 49 | # fmt: skip -50 50 | # isort:skip -51 51 | # isort:skip_file +44 44 | # type:ignore +45 45 | #type: int +46 46 | # fmt:off +47 |-#fmt: on + 47 |+# fmt: on +48 48 | # fmt: skip +49 49 | # isort:skip +50 50 | # isort:skip_file -RUF037.py:49:5: RUF037 [*] Unformatted special comment +RUF037.py:48:5: RUF037 [*] Unformatted special comment | -47 | # fmt:off -48 | #fmt: on -49 | # fmt: skip +46 | # fmt:off +47 | #fmt: on +48 | # fmt: skip | ^^^ RUF037 -50 | # isort:skip -51 | # isort:skip_file +49 | # isort:skip +50 | # isort:skip_file | = help: Format comment ℹ Safe fix -46 46 | #type: int -47 47 | # fmt:off -48 48 | #fmt: on -49 |-# fmt: skip - 49 |+# fmt: skip -50 50 | # isort:skip -51 51 | # isort:skip_file -52 52 | # ruff: isort:skip +45 45 | #type: int +46 46 | # fmt:off +47 47 | #fmt: on +48 |-# fmt: skip + 48 |+# fmt: skip +49 49 | # isort:skip +50 50 | # isort:skip_file +51 51 | # ruff: isort:skip -RUF037.py:50:3: RUF037 [*] Unformatted special comment +RUF037.py:49:3: RUF037 [*] Unformatted special comment | -48 | #fmt: on -49 | # fmt: skip -50 | # isort:skip +47 | #fmt: on +48 | # fmt: skip +49 | # isort:skip | ^^^^^ RUF037 -51 | # isort:skip_file -52 | # ruff: isort:skip +50 | # isort:skip_file +51 | # ruff: isort:skip | = help: Format comment ℹ Safe fix -47 47 | # fmt:off -48 48 | #fmt: on -49 49 | # fmt: skip -50 |-# isort:skip - 50 |+# isort: skip -51 51 | # isort:skip_file -52 52 | # ruff: isort:skip -53 53 | # ruff: isort:skip_file +46 46 | # fmt:off +47 47 | #fmt: on +48 48 | # fmt: skip +49 |-# isort:skip + 49 |+# isort: skip +50 50 | # isort:skip_file +51 51 | # ruff: isort:skip +52 52 | # ruff: isort:skip_file -RUF037.py:51:3: RUF037 [*] Unformatted special comment +RUF037.py:50:3: RUF037 [*] Unformatted special comment | -49 | # fmt: skip -50 | # isort:skip -51 | # isort:skip_file +48 | # fmt: skip +49 | # isort:skip +50 | # isort:skip_file | ^^^^^ RUF037 -52 | # ruff: isort:skip -53 | # ruff: isort:skip_file +51 | # ruff: isort:skip +52 | # ruff: isort:skip_file | = help: Format comment ℹ Safe fix -48 48 | #fmt: on -49 49 | # fmt: skip -50 50 | # isort:skip -51 |-# isort:skip_file - 51 |+# isort: skip_file -52 52 | # ruff: isort:skip -53 53 | # ruff: isort:skip_file -54 54 | # type: ignore +47 47 | #fmt: on +48 48 | # fmt: skip +49 49 | # isort:skip +50 |-# isort:skip_file + 50 |+# isort: skip_file +51 51 | # ruff: isort:skip +52 52 | # ruff: isort:skip_file +53 53 | # type: ignore -RUF037.py:52:3: RUF037 [*] Unformatted special comment +RUF037.py:51:3: RUF037 [*] Unformatted special comment | -50 | # isort:skip -51 | # isort:skip_file -52 | # ruff: isort:skip +49 | # isort:skip +50 | # isort:skip_file +51 | # ruff: isort:skip | ^^^^ RUF037 -53 | # ruff: isort:skip_file -54 | # type: ignore +52 | # ruff: isort:skip_file +53 | # type: ignore | = help: Format comment ℹ Safe fix -49 49 | # fmt: skip -50 50 | # isort:skip -51 51 | # isort:skip_file -52 |-# ruff: isort:skip - 52 |+# ruff: isort: skip -53 53 | # ruff: isort:skip_file -54 54 | # type: ignore -55 55 | # type: int +48 48 | # fmt: skip +49 49 | # isort:skip +50 50 | # isort:skip_file +51 |-# ruff: isort:skip + 51 |+# ruff: isort: skip +52 52 | # ruff: isort:skip_file +53 53 | # type: ignore +54 54 | # type: int -RUF037.py:53:3: RUF037 [*] Unformatted special comment +RUF037.py:52:3: RUF037 [*] Unformatted special comment | -51 | # isort:skip_file -52 | # ruff: isort:skip -53 | # ruff: isort:skip_file +50 | # isort:skip_file +51 | # ruff: isort:skip +52 | # ruff: isort:skip_file | ^^^^ RUF037 -54 | # type: ignore -55 | # type: int +53 | # type: ignore +54 | # type: int | = help: Format comment ℹ Safe fix -50 50 | # isort:skip -51 51 | # isort:skip_file -52 52 | # ruff: isort:skip -53 |-# ruff: isort:skip_file - 53 |+# ruff: isort: skip_file -54 54 | # type: ignore -55 55 | # type: int -56 56 | # yapf: enable +49 49 | # isort:skip +50 50 | # isort:skip_file +51 51 | # ruff: isort:skip +52 |-# ruff: isort:skip_file + 52 |+# ruff: isort: skip_file +53 53 | # type: ignore +54 54 | # type: int +55 55 | # yapf: enable -RUF037.py:54:6: RUF037 [*] Unformatted special comment +RUF037.py:53:6: RUF037 [*] Unformatted special comment | -52 | # ruff: isort:skip -53 | # ruff: isort:skip_file -54 | # type: ignore +51 | # ruff: isort:skip +52 | # ruff: isort:skip_file +53 | # type: ignore | ^^^^ RUF037 -55 | # type: int -56 | # yapf: enable +54 | # type: int +55 | # yapf: enable | = help: Format comment ℹ Safe fix -51 51 | # isort:skip_file -52 52 | # ruff: isort:skip -53 53 | # ruff: isort:skip_file -54 |-# type: ignore - 54 |+# type: ignore -55 55 | # type: int -56 56 | # yapf: enable -57 57 | # yapf: disable +50 50 | # isort:skip_file +51 51 | # ruff: isort:skip +52 52 | # ruff: isort:skip_file +53 |-# type: ignore + 53 |+# type: ignore +54 54 | # type: int +55 55 | # yapf: enable +56 56 | # yapf: disable -RUF037.py:55:7: RUF037 [*] Unformatted special comment +RUF037.py:54:7: RUF037 [*] Unformatted special comment | -53 | # ruff: isort:skip_file -54 | # type: ignore -55 | # type: int +52 | # ruff: isort:skip_file +53 | # type: ignore +54 | # type: int | ^^^^ RUF037 -56 | # yapf: enable -57 | # yapf: disable +55 | # yapf: enable +56 | # yapf: disable | = help: Format comment ℹ Safe fix -52 52 | # ruff: isort:skip -53 53 | # ruff: isort:skip_file -54 54 | # type: ignore -55 |-# type: int - 55 |+# type: int -56 56 | # yapf: enable -57 57 | # yapf: disable -58 58 | +51 51 | # ruff: isort:skip +52 52 | # ruff: isort:skip_file +53 53 | # type: ignore +54 |-# type: int + 54 |+# type: int +55 55 | # yapf: enable +56 56 | # yapf: disable +57 57 | -RUF037.py:56:6: RUF037 [*] Unformatted special comment +RUF037.py:55:6: RUF037 [*] Unformatted special comment | -54 | # type: ignore -55 | # type: int -56 | # yapf: enable +53 | # type: ignore +54 | # type: int +55 | # yapf: enable | ^^^^ RUF037 -57 | # yapf: disable +56 | # yapf: disable | = help: Format comment ℹ Safe fix -53 53 | # ruff: isort:skip_file -54 54 | # type: ignore -55 55 | # type: int -56 |-# yapf: enable - 56 |+# yapf: enable -57 57 | # yapf: disable -58 58 | -59 59 | # NoQA: A123, B456 +52 52 | # ruff: isort:skip_file +53 53 | # type: ignore +54 54 | # type: int +55 |-# yapf: enable + 55 |+# yapf: enable +56 56 | # yapf: disable +57 57 | +58 58 | # NoQA: A123, B456 -RUF037.py:57:4: RUF037 [*] Unformatted special comment +RUF037.py:56:4: RUF037 [*] Unformatted special comment | -55 | # type: int -56 | # yapf: enable -57 | # yapf: disable +54 | # type: int +55 | # yapf: enable +56 | # yapf: disable | ^^^^ RUF037 -58 | -59 | # NoQA: A123, B456 +57 | +58 | # NoQA: A123, B456 | = help: Format comment ℹ Safe fix -54 54 | # type: ignore -55 55 | # type: int -56 56 | # yapf: enable -57 |-# yapf: disable - 57 |+# yapf: disable -58 58 | -59 59 | # NoQA: A123, B456 -60 60 | # ruff: NoQA: A123, B456 +53 53 | # type: ignore +54 54 | # type: int +55 55 | # yapf: enable +56 |-# yapf: disable + 56 |+# yapf: disable +57 57 | +58 58 | # NoQA: A123, B456 +59 59 | # ruff: NoQA: A123, B456 -RUF037.py:59:3: RUF037 [*] Unformatted special comment +RUF037.py:58:3: RUF037 [*] Unformatted special comment | -57 | # yapf: disable -58 | -59 | # NoQA: A123, B456 +56 | # yapf: disable +57 | +58 | # NoQA: A123, B456 | ^^^^ RUF037 -60 | # ruff: NoQA: A123, B456 -61 | # flake8: NoQA: A123, B456 +59 | # ruff: NoQA: A123, B456 +60 | # flake8: NoQA: A123, B456 | = help: Format comment ℹ Safe fix -56 56 | # yapf: enable -57 57 | # yapf: disable -58 58 | -59 |-# NoQA: A123, B456 - 59 |+# noqa: A123, B456 -60 60 | # ruff: NoQA: A123, B456 -61 61 | # flake8: NoQA: A123, B456 -62 62 | +55 55 | # yapf: enable +56 56 | # yapf: disable +57 57 | +58 |-# NoQA: A123, B456 + 58 |+# noqa: A123, B456 +59 59 | # ruff: NoQA: A123, B456 +60 60 | # flake8: NoQA: A123, B456 +61 61 | -RUF037.py:60:3: RUF037 [*] Unformatted special comment +RUF037.py:59:3: RUF037 [*] Unformatted special comment | -59 | # NoQA: A123, B456 -60 | # ruff: NoQA: A123, B456 +58 | # NoQA: A123, B456 +59 | # ruff: NoQA: A123, B456 | ^^^^ RUF037 -61 | # flake8: NoQA: A123, B456 +60 | # flake8: NoQA: A123, B456 | = help: Format comment ℹ Safe fix -57 57 | # yapf: disable -58 58 | -59 59 | # NoQA: A123, B456 -60 |-# ruff: NoQA: A123, B456 - 60 |+# ruff: noqa: A123, B456 -61 61 | # flake8: NoQA: A123, B456 -62 62 | -63 63 | # noqa: A123 B456 +56 56 | # yapf: disable +57 57 | +58 58 | # NoQA: A123, B456 +59 |-# ruff: NoQA: A123, B456 + 59 |+# ruff: noqa: A123, B456 +60 60 | # flake8: NoQA: A123, B456 +61 61 | +62 62 | # noqa: A123 B456 -RUF037.py:61:3: RUF037 [*] Unformatted special comment +RUF037.py:60:3: RUF037 [*] Unformatted special comment | -59 | # NoQA: A123, B456 -60 | # ruff: NoQA: A123, B456 -61 | # flake8: NoQA: A123, B456 +58 | # NoQA: A123, B456 +59 | # ruff: NoQA: A123, B456 +60 | # flake8: NoQA: A123, B456 | ^^^^^^ RUF037 -62 | -63 | # noqa: A123 B456 +61 | +62 | # noqa: A123 B456 + | + = help: Format comment + +ℹ Safe fix +57 57 | +58 58 | # NoQA: A123, B456 +59 59 | # ruff: NoQA: A123, B456 +60 |-# flake8: NoQA: A123, B456 + 60 |+# flake8: noqa: A123, B456 +61 61 | +62 62 | # noqa: A123 B456 +63 63 | # ruff: noqa: A123 B456 + +RUF037.py:62:3: RUF037 [*] Unformatted special comment + | +60 | # flake8: NoQA: A123, B456 +61 | +62 | # noqa: A123 B456 + | ^^^^ RUF037 +63 | # ruff: noqa: A123 B456 +64 | # flake8: noqa: A123 B456 | = help: Format comment ℹ Safe fix -58 58 | -59 59 | # NoQA: A123, B456 -60 60 | # ruff: NoQA: A123, B456 -61 |-# flake8: NoQA: A123, B456 - 61 |+# flake8: noqa: A123, B456 -62 62 | -63 63 | # noqa: A123 B456 -64 64 | # ruff: noqa: A123 B456 +59 59 | # ruff: NoQA: A123, B456 +60 60 | # flake8: NoQA: A123, B456 +61 61 | +62 |-# noqa: A123 B456 + 62 |+# noqa: A123, B456 +63 63 | # ruff: noqa: A123 B456 +64 64 | # flake8: noqa: A123 B456 +65 65 | # noqa: A123,B456 RUF037.py:63:3: RUF037 [*] Unformatted special comment | -61 | # flake8: NoQA: A123, B456 -62 | -63 | # noqa: A123 B456 +62 | # noqa: A123 B456 +63 | # ruff: noqa: A123 B456 | ^^^^ RUF037 -64 | # ruff: noqa: A123 B456 -65 | # flake8: noqa: A123 B456 +64 | # flake8: noqa: A123 B456 +65 | # noqa: A123,B456 | = help: Format comment ℹ Safe fix -60 60 | # ruff: NoQA: A123, B456 -61 61 | # flake8: NoQA: A123, B456 -62 62 | -63 |-# noqa: A123 B456 - 63 |+# noqa: A123, B456 -64 64 | # ruff: noqa: A123 B456 -65 65 | # flake8: noqa: A123 B456 -66 66 | # noqa: A123,B456 +60 60 | # flake8: NoQA: A123, B456 +61 61 | +62 62 | # noqa: A123 B456 +63 |-# ruff: noqa: A123 B456 + 63 |+# ruff: noqa: A123, B456 +64 64 | # flake8: noqa: A123 B456 +65 65 | # noqa: A123,B456 +66 66 | # ruff: noqa: A123,B456 RUF037.py:64:3: RUF037 [*] Unformatted special comment | -63 | # noqa: A123 B456 -64 | # ruff: noqa: A123 B456 - | ^^^^ RUF037 -65 | # flake8: noqa: A123 B456 -66 | # noqa: A123,B456 +62 | # noqa: A123 B456 +63 | # ruff: noqa: A123 B456 +64 | # flake8: noqa: A123 B456 + | ^^^^^^ RUF037 +65 | # noqa: A123,B456 +66 | # ruff: noqa: A123,B456 | = help: Format comment ℹ Safe fix -61 61 | # flake8: NoQA: A123, B456 -62 62 | -63 63 | # noqa: A123 B456 -64 |-# ruff: noqa: A123 B456 - 64 |+# ruff: noqa: A123, B456 -65 65 | # flake8: noqa: A123 B456 -66 66 | # noqa: A123,B456 -67 67 | # ruff: noqa: A123,B456 +61 61 | +62 62 | # noqa: A123 B456 +63 63 | # ruff: noqa: A123 B456 +64 |-# flake8: noqa: A123 B456 + 64 |+# flake8: noqa: A123, B456 +65 65 | # noqa: A123,B456 +66 66 | # ruff: noqa: A123,B456 +67 67 | # flake8: noqa: A123,B456 RUF037.py:65:3: RUF037 [*] Unformatted special comment | -63 | # noqa: A123 B456 -64 | # ruff: noqa: A123 B456 -65 | # flake8: noqa: A123 B456 - | ^^^^^^ RUF037 -66 | # noqa: A123,B456 -67 | # ruff: noqa: A123,B456 +63 | # ruff: noqa: A123 B456 +64 | # flake8: noqa: A123 B456 +65 | # noqa: A123,B456 + | ^^^^ RUF037 +66 | # ruff: noqa: A123,B456 +67 | # flake8: noqa: A123,B456 | = help: Format comment ℹ Safe fix -62 62 | -63 63 | # noqa: A123 B456 -64 64 | # ruff: noqa: A123 B456 -65 |-# flake8: noqa: A123 B456 - 65 |+# flake8: noqa: A123, B456 -66 66 | # noqa: A123,B456 -67 67 | # ruff: noqa: A123,B456 -68 68 | # flake8: noqa: A123,B456 +62 62 | # noqa: A123 B456 +63 63 | # ruff: noqa: A123 B456 +64 64 | # flake8: noqa: A123 B456 +65 |-# noqa: A123,B456 + 65 |+# noqa: A123, B456 +66 66 | # ruff: noqa: A123,B456 +67 67 | # flake8: noqa: A123,B456 +68 68 | # noqa: A123,,B456 RUF037.py:66:3: RUF037 [*] Unformatted special comment | -64 | # ruff: noqa: A123 B456 -65 | # flake8: noqa: A123 B456 -66 | # noqa: A123,B456 +64 | # flake8: noqa: A123 B456 +65 | # noqa: A123,B456 +66 | # ruff: noqa: A123,B456 | ^^^^ RUF037 -67 | # ruff: noqa: A123,B456 -68 | # flake8: noqa: A123,B456 +67 | # flake8: noqa: A123,B456 +68 | # noqa: A123,,B456 | = help: Format comment ℹ Safe fix -63 63 | # noqa: A123 B456 -64 64 | # ruff: noqa: A123 B456 -65 65 | # flake8: noqa: A123 B456 -66 |-# noqa: A123,B456 - 66 |+# noqa: A123, B456 -67 67 | # ruff: noqa: A123,B456 -68 68 | # flake8: noqa: A123,B456 -69 69 | # noqa: A123,,B456 +63 63 | # ruff: noqa: A123 B456 +64 64 | # flake8: noqa: A123 B456 +65 65 | # noqa: A123,B456 +66 |-# ruff: noqa: A123,B456 + 66 |+# ruff: noqa: A123, B456 +67 67 | # flake8: noqa: A123,B456 +68 68 | # noqa: A123,,B456 +69 69 | # noqa: A123 , , B456 RUF037.py:67:3: RUF037 [*] Unformatted special comment | -65 | # flake8: noqa: A123 B456 -66 | # noqa: A123,B456 -67 | # ruff: noqa: A123,B456 - | ^^^^ RUF037 -68 | # flake8: noqa: A123,B456 -69 | # noqa: A123,,B456 +65 | # noqa: A123,B456 +66 | # ruff: noqa: A123,B456 +67 | # flake8: noqa: A123,B456 + | ^^^^^^ RUF037 +68 | # noqa: A123,,B456 +69 | # noqa: A123 , , B456 | = help: Format comment ℹ Safe fix -64 64 | # ruff: noqa: A123 B456 -65 65 | # flake8: noqa: A123 B456 -66 66 | # noqa: A123,B456 -67 |-# ruff: noqa: A123,B456 - 67 |+# ruff: noqa: A123, B456 -68 68 | # flake8: noqa: A123,B456 -69 69 | # noqa: A123,,B456 -70 70 | # noqa: A123 , , B456 +64 64 | # flake8: noqa: A123 B456 +65 65 | # noqa: A123,B456 +66 66 | # ruff: noqa: A123,B456 +67 |-# flake8: noqa: A123,B456 + 67 |+# flake8: noqa: A123, B456 +68 68 | # noqa: A123,,B456 +69 69 | # noqa: A123 , , B456 +70 70 | # noqa: A123 B456 RUF037.py:68:3: RUF037 [*] Unformatted special comment | -66 | # noqa: A123,B456 -67 | # ruff: noqa: A123,B456 -68 | # flake8: noqa: A123,B456 - | ^^^^^^ RUF037 -69 | # noqa: A123,,B456 -70 | # noqa: A123 , , B456 +66 | # ruff: noqa: A123,B456 +67 | # flake8: noqa: A123,B456 +68 | # noqa: A123,,B456 + | ^^^^ RUF037 +69 | # noqa: A123 , , B456 +70 | # noqa: A123 B456 | = help: Format comment ℹ Safe fix -65 65 | # flake8: noqa: A123 B456 -66 66 | # noqa: A123,B456 -67 67 | # ruff: noqa: A123,B456 -68 |-# flake8: noqa: A123,B456 - 68 |+# flake8: noqa: A123, B456 -69 69 | # noqa: A123,,B456 -70 70 | # noqa: A123 , , B456 -71 71 | # noqa: A123 B456 +65 65 | # noqa: A123,B456 +66 66 | # ruff: noqa: A123,B456 +67 67 | # flake8: noqa: A123,B456 +68 |-# noqa: A123,,B456 + 68 |+# noqa: A123, B456 +69 69 | # noqa: A123 , , B456 +70 70 | # noqa: A123 B456 +71 71 | # noqa: A123 B456 RUF037.py:69:3: RUF037 [*] Unformatted special comment | -67 | # ruff: noqa: A123,B456 -68 | # flake8: noqa: A123,B456 -69 | # noqa: A123,,B456 +67 | # flake8: noqa: A123,B456 +68 | # noqa: A123,,B456 +69 | # noqa: A123 , , B456 | ^^^^ RUF037 -70 | # noqa: A123 , , B456 -71 | # noqa: A123 B456 +70 | # noqa: A123 B456 +71 | # noqa: A123 B456 | = help: Format comment ℹ Safe fix -66 66 | # noqa: A123,B456 -67 67 | # ruff: noqa: A123,B456 -68 68 | # flake8: noqa: A123,B456 -69 |-# noqa: A123,,B456 +66 66 | # ruff: noqa: A123,B456 +67 67 | # flake8: noqa: A123,B456 +68 68 | # noqa: A123,,B456 +69 |-# noqa: A123 , , B456 69 |+# noqa: A123, B456 -70 70 | # noqa: A123 , , B456 -71 71 | # noqa: A123 B456 -72 72 | # noqa: A123 B456 +70 70 | # noqa: A123 B456 +71 71 | # noqa: A123 B456 +72 72 | # noqa: A123 B456 RUF037.py:70:3: RUF037 [*] Unformatted special comment | -68 | # flake8: noqa: A123,B456 -69 | # noqa: A123,,B456 -70 | # noqa: A123 , , B456 +68 | # noqa: A123,,B456 +69 | # noqa: A123 , , B456 +70 | # noqa: A123 B456 | ^^^^ RUF037 -71 | # noqa: A123 B456 -72 | # noqa: A123 B456 +71 | # noqa: A123 B456 +72 | # noqa: A123 B456 | = help: Format comment ℹ Safe fix -67 67 | # ruff: noqa: A123,B456 -68 68 | # flake8: noqa: A123,B456 -69 69 | # noqa: A123,,B456 -70 |-# noqa: A123 , , B456 +67 67 | # flake8: noqa: A123,B456 +68 68 | # noqa: A123,,B456 +69 69 | # noqa: A123 , , B456 +70 |-# noqa: A123 B456 70 |+# noqa: A123, B456 -71 71 | # noqa: A123 B456 -72 72 | # noqa: A123 B456 -73 73 | # noqa: A123 B456 +71 71 | # noqa: A123 B456 +72 72 | # noqa: A123 B456 +73 73 | # noqa: A123 ,B456 RUF037.py:71:3: RUF037 [*] Unformatted special comment | -69 | # noqa: A123,,B456 -70 | # noqa: A123 , , B456 -71 | # noqa: A123 B456 +69 | # noqa: A123 , , B456 +70 | # noqa: A123 B456 +71 | # noqa: A123 B456 | ^^^^ RUF037 -72 | # noqa: A123 B456 -73 | # noqa: A123 B456 +72 | # noqa: A123 B456 +73 | # noqa: A123 ,B456 | = help: Format comment ℹ Safe fix -68 68 | # flake8: noqa: A123,B456 -69 69 | # noqa: A123,,B456 -70 70 | # noqa: A123 , , B456 -71 |-# noqa: A123 B456 +68 68 | # noqa: A123,,B456 +69 69 | # noqa: A123 , , B456 +70 70 | # noqa: A123 B456 +71 |-# noqa: A123 B456 71 |+# noqa: A123, B456 -72 72 | # noqa: A123 B456 -73 73 | # noqa: A123 B456 -74 74 | # noqa: A123 ,B456 +72 72 | # noqa: A123 B456 +73 73 | # noqa: A123 ,B456 +74 74 | # ruff: noqa: A123 B456 RUF037.py:72:3: RUF037 [*] Unformatted special comment | -70 | # noqa: A123 , , B456 -71 | # noqa: A123 B456 -72 | # noqa: A123 B456 +70 | # noqa: A123 B456 +71 | # noqa: A123 B456 +72 | # noqa: A123 B456 | ^^^^ RUF037 -73 | # noqa: A123 B456 -74 | # noqa: A123 ,B456 +73 | # noqa: A123 ,B456 +74 | # ruff: noqa: A123 B456 | = help: Format comment ℹ Safe fix -69 69 | # noqa: A123,,B456 -70 70 | # noqa: A123 , , B456 -71 71 | # noqa: A123 B456 -72 |-# noqa: A123 B456 +69 69 | # noqa: A123 , , B456 +70 70 | # noqa: A123 B456 +71 71 | # noqa: A123 B456 +72 |-# noqa: A123 B456 72 |+# noqa: A123, B456 -73 73 | # noqa: A123 B456 -74 74 | # noqa: A123 ,B456 -75 75 | # ruff: noqa: A123 B456 +73 73 | # noqa: A123 ,B456 +74 74 | # ruff: noqa: A123 B456 +75 75 | # flake8: noqa: A123 B456 RUF037.py:73:3: RUF037 [*] Unformatted special comment | -71 | # noqa: A123 B456 -72 | # noqa: A123 B456 -73 | # noqa: A123 B456 +71 | # noqa: A123 B456 +72 | # noqa: A123 B456 +73 | # noqa: A123 ,B456 | ^^^^ RUF037 -74 | # noqa: A123 ,B456 -75 | # ruff: noqa: A123 B456 +74 | # ruff: noqa: A123 B456 +75 | # flake8: noqa: A123 B456 | = help: Format comment ℹ Safe fix -70 70 | # noqa: A123 , , B456 -71 71 | # noqa: A123 B456 -72 72 | # noqa: A123 B456 -73 |-# noqa: A123 B456 +70 70 | # noqa: A123 B456 +71 71 | # noqa: A123 B456 +72 72 | # noqa: A123 B456 +73 |-# noqa: A123 ,B456 73 |+# noqa: A123, B456 -74 74 | # noqa: A123 ,B456 -75 75 | # ruff: noqa: A123 B456 -76 76 | # flake8: noqa: A123 B456 +74 74 | # ruff: noqa: A123 B456 +75 75 | # flake8: noqa: A123 B456 +76 76 | RUF037.py:74:3: RUF037 [*] Unformatted special comment | -72 | # noqa: A123 B456 -73 | # noqa: A123 B456 -74 | # noqa: A123 ,B456 +72 | # noqa: A123 B456 +73 | # noqa: A123 ,B456 +74 | # ruff: noqa: A123 B456 | ^^^^ RUF037 -75 | # ruff: noqa: A123 B456 -76 | # flake8: noqa: A123 B456 +75 | # flake8: noqa: A123 B456 | = help: Format comment ℹ Safe fix -71 71 | # noqa: A123 B456 -72 72 | # noqa: A123 B456 -73 73 | # noqa: A123 B456 -74 |-# noqa: A123 ,B456 - 74 |+# noqa: A123, B456 -75 75 | # ruff: noqa: A123 B456 -76 76 | # flake8: noqa: A123 B456 +71 71 | # noqa: A123 B456 +72 72 | # noqa: A123 B456 +73 73 | # noqa: A123 ,B456 +74 |-# ruff: noqa: A123 B456 + 74 |+# ruff: noqa: A123, B456 +75 75 | # flake8: noqa: A123 B456 +76 76 | 77 77 | RUF037.py:75:3: RUF037 [*] Unformatted special comment | -73 | # noqa: A123 B456 -74 | # noqa: A123 ,B456 -75 | # ruff: noqa: A123 B456 - | ^^^^ RUF037 -76 | # flake8: noqa: A123 B456 - | - = help: Format comment - -ℹ Safe fix -72 72 | # noqa: A123 B456 -73 73 | # noqa: A123 B456 -74 74 | # noqa: A123 ,B456 -75 |-# ruff: noqa: A123 B456 - 75 |+# ruff: noqa: A123, B456 -76 76 | # flake8: noqa: A123 B456 -77 77 | -78 78 | - -RUF037.py:76:3: RUF037 [*] Unformatted special comment - | -74 | # noqa: A123 ,B456 -75 | # ruff: noqa: A123 B456 -76 | # flake8: noqa: A123 B456 +73 | # noqa: A123 ,B456 +74 | # ruff: noqa: A123 B456 +75 | # flake8: noqa: A123 B456 | ^^^^^^ RUF037 | = help: Format comment ℹ Safe fix -73 73 | # noqa: A123 B456 -74 74 | # noqa: A123 ,B456 -75 75 | # ruff: noqa: A123 B456 -76 |-# flake8: noqa: A123 B456 - 76 |+# flake8: noqa: A123, B456 +72 72 | # noqa: A123 B456 +73 73 | # noqa: A123 ,B456 +74 74 | # ruff: noqa: A123 B456 +75 |-# flake8: noqa: A123 B456 + 75 |+# flake8: noqa: A123, B456 +76 76 | 77 77 | -78 78 | -79 79 | # type: ignore # noqa: A123, B456 +78 78 | # type: ignore # noqa: A123, B456 -RUF037.py:81:13: RUF037 [*] Unformatted special comment +RUF037.py:80:13: RUF037 [*] Unformatted special comment | -79 | # type: ignore # noqa: A123, B456 -80 | -81 | #isort:skip#noqa:A123 +78 | # type: ignore # noqa: A123, B456 +79 | +80 | #isort:skip#noqa:A123 | ^^^^ RUF037 -82 | -83 | # fmt:off# noqa: A123 +81 | +82 | # fmt:off# noqa: A123 | = help: Format comment ℹ Safe fix -78 78 | -79 79 | # type: ignore # noqa: A123, B456 -80 80 | -81 |-#isort:skip#noqa:A123 - 81 |+#isort:skip# noqa: A123 -82 82 | -83 83 | # fmt:off# noqa: A123 -84 84 | # noqa:A123, B456 - Lorem ipsum dolor sit amet - -RUF037.py:83:3: RUF037 [*] Unformatted special comment - | -81 | #isort:skip#noqa:A123 -82 | -83 | # fmt:off# noqa: A123 +77 77 | +78 78 | # type: ignore # noqa: A123, B456 +79 79 | +80 |-#isort:skip#noqa:A123 + 80 |+#isort:skip# noqa: A123 +81 81 | +82 82 | # fmt:off# noqa: A123 +83 83 | # noqa:A123, B456 - Lorem ipsum dolor sit amet + +RUF037.py:82:3: RUF037 [*] Unformatted special comment + | +80 | #isort:skip#noqa:A123 +81 | +82 | # fmt:off# noqa: A123 | ^^^ RUF037 -84 | # noqa:A123, B456 - Lorem ipsum dolor sit amet +83 | # noqa:A123, B456 - Lorem ipsum dolor sit amet | = help: Format comment ℹ Safe fix -80 80 | -81 81 | #isort:skip#noqa:A123 -82 82 | -83 |-# fmt:off# noqa: A123 - 83 |+# fmt: off# noqa: A123 -84 84 | # noqa:A123, B456 - Lorem ipsum dolor sit amet +79 79 | +80 80 | #isort:skip#noqa:A123 +81 81 | +82 |-# fmt:off# noqa: A123 + 82 |+# fmt: off# noqa: A123 +83 83 | # noqa:A123, B456 - Lorem ipsum dolor sit amet -RUF037.py:83:14: RUF037 [*] Unformatted special comment +RUF037.py:82:14: RUF037 [*] Unformatted special comment | -81 | #isort:skip#noqa:A123 -82 | -83 | # fmt:off# noqa: A123 +80 | #isort:skip#noqa:A123 +81 | +82 | # fmt:off# noqa: A123 | ^^^^ RUF037 -84 | # noqa:A123, B456 - Lorem ipsum dolor sit amet +83 | # noqa:A123, B456 - Lorem ipsum dolor sit amet | = help: Format comment ℹ Safe fix -80 80 | -81 81 | #isort:skip#noqa:A123 -82 82 | -83 |-# fmt:off# noqa: A123 - 83 |+# fmt:off# noqa: A123 -84 84 | # noqa:A123, B456 - Lorem ipsum dolor sit amet +79 79 | +80 80 | #isort:skip#noqa:A123 +81 81 | +82 |-# fmt:off# noqa: A123 + 82 |+# fmt:off# noqa: A123 +83 83 | # noqa:A123, B456 - Lorem ipsum dolor sit amet -RUF037.py:84:3: RUF037 [*] Unformatted special comment +RUF037.py:83:3: RUF037 [*] Unformatted special comment | -83 | # fmt:off# noqa: A123 -84 | # noqa:A123, B456 - Lorem ipsum dolor sit amet +82 | # fmt:off# noqa: A123 +83 | # noqa:A123, B456 - Lorem ipsum dolor sit amet | ^^^^ RUF037 | = help: Format comment ℹ Safe fix -81 81 | #isort:skip#noqa:A123 -82 82 | -83 83 | # fmt:off# noqa: A123 -84 |-# noqa:A123, B456 - Lorem ipsum dolor sit amet - 84 |+# noqa: A123, B456 - Lorem ipsum dolor sit amet +80 80 | #isort:skip#noqa:A123 +81 81 | +82 82 | # fmt:off# noqa: A123 +83 |-# noqa:A123, B456 - Lorem ipsum dolor sit amet + 83 |+# noqa: A123, B456 - Lorem ipsum dolor sit amet