Skip to content

Commit

Permalink
mark f522 as sometimes fixable (#4893)
Browse files Browse the repository at this point in the history
  • Loading branch information
addisoncrump authored Jun 6, 2023
1 parent 3f032cf commit 1ed5d7e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
3 changes: 3 additions & 0 deletions crates/ruff/resources/test/fixtures/pyflakes/F522.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
8 changes: 5 additions & 3 deletions crates/ruff/src/rules/pyflakes/rules/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,18 +386,20 @@ pub struct StringDotFormatExtraNamedArguments {
missing: Vec<String>,
}

impl AlwaysAutofixableViolation for StringDotFormatExtraNamedArguments {
impl Violation for StringDotFormatExtraNamedArguments {
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;

#[derive_message_formats]
fn message(&self) -> String {
let StringDotFormatExtraNamedArguments { missing } = self;
let message = missing.join(", ");
format!("`.format` call has unused named argument(s): {message}")
}

fn autofix_title(&self) -> String {
fn autofix_title(&self) -> Option<String> {
let StringDotFormatExtraNamedArguments { missing } = self;
let message = missing.join(", ");
format!("Remove extra named arguments: {message}")
Some(format!("Remove extra named arguments: {message}"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ 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
|
4 | "{bar}{}".format(1, bar=2, spam=3) # F522
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

Expand All @@ -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


0 comments on commit 1ed5d7e

Please sign in to comment.