Mark F523 as "sometimes" fixable (#4868)

This commit is contained in:
Charlie Marsh 2023-06-05 12:55:28 -04:00 committed by GitHub
parent dc223fd3ca
commit f952bef1ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 4 deletions

View File

@ -26,3 +26,7 @@
# With modified indexes # With modified indexes
"{1}{2}".format(1, 2, 3) # F523, # F524 "{1}{2}".format(1, 2, 3) # F523, # F524
"{1}{3}".format(1, 2, 3, 4) # F523, # F524 "{1}{3}".format(1, 2, 3, 4) # F523, # F524
# Not fixable
(''
.format(2))

View File

@ -4,7 +4,7 @@ use ruff_text_size::TextRange;
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use rustpython_parser::ast::{self, Constant, Expr, Identifier, Keyword}; use rustpython_parser::ast::{self, Constant, Expr, Identifier, Keyword};
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Violation}; use ruff_diagnostics::{AlwaysAutofixableViolation, AutofixKind, Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation}; use ruff_macros::{derive_message_formats, violation};
use crate::checkers::ast::Checker; use crate::checkers::ast::Checker;
@ -425,7 +425,9 @@ pub struct StringDotFormatExtraPositionalArguments {
missing: Vec<String>, missing: Vec<String>,
} }
impl AlwaysAutofixableViolation for StringDotFormatExtraPositionalArguments { impl Violation for StringDotFormatExtraPositionalArguments {
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
let StringDotFormatExtraPositionalArguments { missing } = self; let StringDotFormatExtraPositionalArguments { missing } = self;
@ -433,10 +435,12 @@ impl AlwaysAutofixableViolation for StringDotFormatExtraPositionalArguments {
format!("`.format` call has unused arguments at position(s): {message}") format!("`.format` call has unused arguments at position(s): {message}")
} }
fn autofix_title(&self) -> String { fn autofix_title(&self) -> Option<String> {
let StringDotFormatExtraPositionalArguments { missing } = self; let StringDotFormatExtraPositionalArguments { missing } = self;
let message = missing.join(", "); let message = missing.join(", ");
format!("Remove extra positional arguments at position(s): {message}") Some(format!(
"Remove extra positional arguments at position(s): {message}"
))
} }
} }

View File

@ -261,6 +261,8 @@ F523.py:27:1: F523 [*] `.format` call has unused arguments at position(s): 0
27 |-"{1}{2}".format(1, 2, 3) # F523, # F524 27 |-"{1}{2}".format(1, 2, 3) # F523, # F524
27 |+"{0}{1}".format(2, 3) # F523, # F524 27 |+"{0}{1}".format(2, 3) # F523, # F524
28 28 | "{1}{3}".format(1, 2, 3, 4) # F523, # F524 28 28 | "{1}{3}".format(1, 2, 3, 4) # F523, # F524
29 29 |
30 30 | # Not fixable
F523.py:28:1: F523 [*] `.format` call has unused arguments at position(s): 0, 2 F523.py:28:1: F523 [*] `.format` call has unused arguments at position(s): 0, 2
| |
@ -268,6 +270,8 @@ F523.py:28:1: F523 [*] `.format` call has unused arguments at position(s): 0, 2
29 | "{1}{2}".format(1, 2, 3) # F523, # F524 29 | "{1}{2}".format(1, 2, 3) # F523, # F524
30 | "{1}{3}".format(1, 2, 3, 4) # F523, # F524 30 | "{1}{3}".format(1, 2, 3, 4) # F523, # F524
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ F523 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ F523
31 |
32 | # Not fixable
| |
= help: Remove extra positional arguments at position(s): 0, 2 = help: Remove extra positional arguments at position(s): 0, 2
@ -277,5 +281,18 @@ F523.py:28:1: F523 [*] `.format` call has unused arguments at position(s): 0, 2
27 27 | "{1}{2}".format(1, 2, 3) # F523, # F524 27 27 | "{1}{2}".format(1, 2, 3) # F523, # F524
28 |-"{1}{3}".format(1, 2, 3, 4) # F523, # F524 28 |-"{1}{3}".format(1, 2, 3, 4) # F523, # F524
28 |+"{0}{1}".format(2, 4) # F523, # F524 28 |+"{0}{1}".format(2, 4) # F523, # F524
29 29 |
30 30 | # Not fixable
31 31 | (''
F523.py:31:2: F523 `.format` call has unused arguments at position(s): 0
|
31 | # Not fixable
32 | (''
| __^
33 | | .format(2))
| |__________^ F523
|
= help: Remove extra positional arguments at position(s): 0