Files
codeql/javascript/ql/src/Expressions/DuplicateSwitchCase.ql
2019-01-07 10:15:45 +00:00

34 lines
854 B
Plaintext

/**
* @name Duplicate switch case
* @description If two cases in a switch statement have the same label, the second case
* will never be executed.
* @kind problem
* @problem.severity warning
* @id js/duplicate-switch-case
* @tags maintainability
* correctness
* external/cwe/cwe-561
* @precision very-high
*/
import Clones
/**
* A clone detector for finding structurally identical case labels.
*/
class DuplicateSwitchCase extends StructurallyCompared {
DuplicateSwitchCase() { exists(Case c | this = c.getExpr()) }
override Expr candidate() {
exists(SwitchStmt s, int i, int j |
this = s.getCase(i).getExpr() and
result = s.getCase(j).getExpr() and
i < j
)
}
}
from DuplicateSwitchCase e, Expr f
where e.same(f)
select f, "This case label is a duplicate of $@.", e, e.toString()