Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mark f522 as sometimes fixable #4893

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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