forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNestedLoopsSameVariable.ql
More file actions
27 lines (24 loc) · 927 Bytes
/
NestedLoopsSameVariable.ql
File metadata and controls
27 lines (24 loc) · 927 Bytes
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
/**
* @name Nested loops with same variable
* @description Nested loops in which the iteration variable is the same for each loop are difficult
* to understand.
* @kind problem
* @problem.severity warning
* @id js/nested-loops-with-same-variable
* @tags maintainability
* correctness
* @precision medium
*/
import javascript
/**
* Gets an iteration variable that loop `for` tests and updates.
*/
Variable getAnIterationVariable(ForStmt for) {
result.getAnAccess().getParentExpr*() = for.getTest() and
exists (UpdateExpr upd | upd.getParentExpr*() = for.getUpdate() | upd.getOperand() = result.getAnAccess())
}
from ForStmt outer, ForStmt inner
where inner.nestedIn(outer) and
getAnIterationVariable(outer) = getAnIterationVariable(inner)
select inner.getTest(), "This for statement uses the same loop variable as an enclosing $@.",
outer, "for statement"