-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathUnusedNamedArgumentIn3101Format.ql
More file actions
32 lines (30 loc) · 1.06 KB
/
UnusedNamedArgumentIn3101Format.ql
File metadata and controls
32 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* @name Unused named argument in formatting call
* @description Including surplus keyword arguments in a formatting call makes code more difficult to read and may indicate an error.
* @kind problem
* @tags quality
* maintainability
* useless-code
* @problem.severity warning
* @sub-severity high
* @precision very-high
* @id py/str-format/surplus-named-argument
*/
import python
import AdvancedFormatting
from AdvancedFormattingCall call, AdvancedFormatString fmt, string name, string fmt_repr
where
call.getAFormat() = fmt and
name = call.getAKeyword().getArg() and
forall(AdvancedFormatString format | format = call.getAFormat() |
not format.getFieldName(_, _) = name
) and
not exists(call.getKwargs()) and
(
strictcount(call.getAFormat()) = 1 and fmt_repr = "format \"" + fmt.getText() + "\""
or
strictcount(call.getAFormat()) != 1 and fmt_repr = "any format used."
)
select call,
"Surplus named argument for string format. An argument named '" + name +
"' is provided, but it is not required by $@.", fmt, fmt_repr