Files
codeql/python/ql/src/Expressions/Formatting/UnusedNamedArgumentIn3101Format.ql
Taus Brock-Nannestad f07a7bf8cf Python: Autoformat everything using qlformat.
Will need subsequent PRs fixing up test failures (due to deprecated
methods moving around), but other than that everything should be
straight-forward.
2020-07-07 15:43:52 +02:00

32 lines
1.0 KiB
Plaintext

/**
* @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 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