mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:24 +00:00
Do not skip analysis if *args
present for F523
(#3923)
This commit is contained in:
parent
237a64d922
commit
311ba29d0f
3 changed files with 36 additions and 6 deletions
|
@ -11,3 +11,9 @@
|
||||||
"{}".format(1, 2, 3) # F523
|
"{}".format(1, 2, 3) # F523
|
||||||
"{:{}}".format(1, 2) # No issues
|
"{:{}}".format(1, 2) # No issues
|
||||||
"{:{}}".format(1, 2, 3) # F523
|
"{:{}}".format(1, 2, 3) # F523
|
||||||
|
|
||||||
|
# With *args
|
||||||
|
"{0}{1}".format(*args) # No issues
|
||||||
|
"{0}{1}".format(1, *args) # No issues
|
||||||
|
"{0}{1}".format(1, 2, *args) # No issues
|
||||||
|
"{0}{1}".format(1, 2, 3, *args) # F523
|
||||||
|
|
|
@ -493,12 +493,15 @@ pub(crate) fn string_dot_format_extra_positional_arguments(
|
||||||
args: &[Expr],
|
args: &[Expr],
|
||||||
location: Range,
|
location: Range,
|
||||||
) {
|
) {
|
||||||
if has_star_args(args) {
|
let missing: Vec<usize> = args
|
||||||
return;
|
.iter()
|
||||||
}
|
.enumerate()
|
||||||
|
.filter(|(i, arg)| {
|
||||||
let missing: Vec<usize> = (0..args.len())
|
!(matches!(arg.node, ExprKind::Starred { .. })
|
||||||
.filter(|i| !(summary.autos.contains(i) || summary.indices.contains(i)))
|
|| summary.autos.contains(i)
|
||||||
|
|| summary.indices.contains(i))
|
||||||
|
})
|
||||||
|
.map(|(i, _)| i)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if missing.is_empty() {
|
if missing.is_empty() {
|
||||||
|
|
|
@ -170,4 +170,25 @@ expression: diagnostics
|
||||||
row: 13
|
row: 13
|
||||||
column: 23
|
column: 23
|
||||||
parent: ~
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
name: StringDotFormatExtraPositionalArguments
|
||||||
|
body: "`.format` call has unused arguments at position(s): 2"
|
||||||
|
suggestion: "Remove extra positional arguments at position(s): 2"
|
||||||
|
fixable: true
|
||||||
|
location:
|
||||||
|
row: 19
|
||||||
|
column: 0
|
||||||
|
end_location:
|
||||||
|
row: 19
|
||||||
|
column: 31
|
||||||
|
fix:
|
||||||
|
edits:
|
||||||
|
- content: "\"{0}{1}\".format(1, 2, *args)"
|
||||||
|
location:
|
||||||
|
row: 19
|
||||||
|
column: 0
|
||||||
|
end_location:
|
||||||
|
row: 19
|
||||||
|
column: 31
|
||||||
|
parent: ~
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue