From 57d90e46ac390b3e1f01bc8afb9c0e1dd0262c38 Mon Sep 17 00:00:00 2001 From: Addison Crump Date: Tue, 6 Jun 2023 15:14:23 +0200 Subject: [PATCH] mark f522 as sometimes fixable (#4893) --- .../resources/test/fixtures/pyflakes/F522.py | 3 +++ crates/ruff/src/rules/pyflakes/rules/strings.rs | 8 +++++--- ...f__rules__pyflakes__tests__F522_F522.py.snap | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/crates/ruff/resources/test/fixtures/pyflakes/F522.py b/crates/ruff/resources/test/fixtures/pyflakes/F522.py index f84a28d53ec200..18e3d072f26a16 100644 --- a/crates/ruff/resources/test/fixtures/pyflakes/F522.py +++ b/crates/ruff/resources/test/fixtures/pyflakes/F522.py @@ -2,3 +2,6 @@ "{bar}{}".format(1, bar=2, spam=3) # F522 "{bar:{spam}}".format(bar=2, spam=3) # No issues "{bar:{spam}}".format(bar=2, spam=3, eggs=4, ham=5) # F522 +# Not fixable +('' + .format(x=2)) \ No newline at end of file diff --git a/crates/ruff/src/rules/pyflakes/rules/strings.rs b/crates/ruff/src/rules/pyflakes/rules/strings.rs index 5afec5c441662d..11edb1bc454611 100644 --- a/crates/ruff/src/rules/pyflakes/rules/strings.rs +++ b/crates/ruff/src/rules/pyflakes/rules/strings.rs @@ -386,7 +386,9 @@ pub struct StringDotFormatExtraNamedArguments { missing: Vec, } -impl AlwaysAutofixableViolation for StringDotFormatExtraNamedArguments { +impl Violation for StringDotFormatExtraNamedArguments { + const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + #[derive_message_formats] fn message(&self) -> String { let StringDotFormatExtraNamedArguments { missing } = self; @@ -394,10 +396,10 @@ impl AlwaysAutofixableViolation for StringDotFormatExtraNamedArguments { format!("`.format` call has unused named argument(s): {message}") } - fn autofix_title(&self) -> String { + fn autofix_title(&self) -> Option { let StringDotFormatExtraNamedArguments { missing } = self; let message = missing.join(", "); - format!("Remove extra named arguments: {message}") + Some(format!("Remove extra named arguments: {message}")) } } diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F522_F522.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F522_F522.py.snap index ca5ac6ec6e5373..b1ae9be9748a22 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F522_F522.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F522_F522.py.snap @@ -33,6 +33,7 @@ F522.py:2:1: F522 [*] `.format` call has unused named argument(s): spam 2 |+"{bar}{}".format(1, bar=2, ) # F522 3 3 | "{bar:{spam}}".format(bar=2, spam=3) # No issues 4 4 | "{bar:{spam}}".format(bar=2, spam=3, eggs=4, ham=5) # F522 +5 5 | # Not fixable F522.py:4:1: F522 [*] `.format` call has unused named argument(s): eggs, ham | @@ -40,6 +41,8 @@ F522.py:4:1: F522 [*] `.format` call has unused named argument(s): eggs, ham 5 | "{bar:{spam}}".format(bar=2, spam=3) # No issues 6 | "{bar:{spam}}".format(bar=2, spam=3, eggs=4, ham=5) # F522 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F522 +7 | # Not fixable +8 | ('' | = help: Remove extra named arguments: eggs, ham @@ -49,5 +52,19 @@ F522.py:4:1: F522 [*] `.format` call has unused named argument(s): eggs, ham 3 3 | "{bar:{spam}}".format(bar=2, spam=3) # No issues 4 |-"{bar:{spam}}".format(bar=2, spam=3, eggs=4, ham=5) # F522 4 |+"{bar:{spam}}".format(bar=2, spam=3, ) # F522 +5 5 | # Not fixable +6 6 | ('' +7 7 | .format(x=2)) + +F522.py:6:2: F522 `.format` call has unused named argument(s): x + | +6 | "{bar:{spam}}".format(bar=2, spam=3, eggs=4, ham=5) # F522 +7 | # Not fixable +8 | ('' + | __^ +9 | | .format(x=2)) + | |_____________^ F522 + | + = help: Remove extra named arguments: x