Files
codeql/python/ql/src/Statements/C_StyleParentheses.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

36 lines
1.1 KiB
Plaintext

/**
* @name C-style condition
* @description Putting parentheses around a condition in an 'if' or 'while' statement is
* unnecessary and harder to read.
* @kind problem
* @tags maintainability
* @problem.severity recommendation
* @sub-severity low
* @deprecated
* @precision very-high
* @id py/c-style-parentheses
*/
import python
from Expr e, Location l, string kind, string what
where
e.isParenthesized() and
not e instanceof Tuple and
(
exists(If i | i.getTest() = e) and kind = "if" and what = "condition"
or
exists(While w | w.getTest() = e) and kind = "while" and what = "condition"
or
exists(Return r | r.getValue() = e) and kind = "return" and what = "value"
or
exists(Assert a | a.getTest() = e and not exists(a.getMsg())) and
kind = "assert" and
what = "test"
) and
// These require parentheses
(not e instanceof Yield and not e instanceof YieldFrom and not e instanceof GeneratorExp) and
l = e.getLocation() and
l.getStartLine() = l.getEndLine()
select e, "Parenthesized " + what + " in '" + kind + "' statement."