Files
codeql/python/ql/src/Expressions/Formatting/WrongNameInArgumentsFor3101Format.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

26 lines
867 B
Plaintext

/**
* @name Missing named arguments in formatting call
* @description A string formatting operation, such as '"{name}".format(key=b)',
* where the names of format items in the format string differs from the names of the values to be formatted will raise a KeyError.
* @kind problem
* @problem.severity error
* @tags reliability
* correctness
* @sub-severity low
* @precision high
* @id py/str-format/missing-named-argument
*/
import python
import AdvancedFormatting
from AdvancedFormattingCall call, AdvancedFormatString fmt, string name
where
call.getAFormat() = fmt and
not name = call.getAKeyword().getArg() and
fmt.getFieldName(_, _) = name and
not exists(call.getKwargs())
select call,
"Missing named argument for string format. Format $@ requires '" + name + "', but it is omitted.",
fmt, "\"" + fmt.getText() + "\""