mirror of
https://github.com/github/codeql.git
synced 2026-01-07 19:50:22 +01:00
Will need subsequent PRs fixing up test failures (due to deprecated methods moving around), but other than that everything should be straight-forward.
36 lines
1.1 KiB
Plaintext
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."
|