-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathUnreachableStatement.ql
More file actions
29 lines (27 loc) · 1.08 KB
/
UnreachableStatement.ql
File metadata and controls
29 lines (27 loc) · 1.08 KB
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
28
29
/**
* @name Unreachable statement
* @description Unreachable statements are often indicative of missing code or latent bugs and should be avoided.
* @kind problem
* @problem.severity warning
* @id js/unreachable-statement
* @tags maintainability
* correctness
* external/cwe/cwe-561
* @precision very-high
*/
import javascript
import semmle.javascript.RestrictedLocations
from Stmt s
where // `s` is unreachable in the CFG
s.getFirstControlFlowNode().isUnreachable() and
// the CFG does not model all possible exceptional control flow, so be conservative about catch clauses
not s instanceof CatchClause and
// function declarations are special and always reachable
not s instanceof FunctionDeclStmt and
// allow a spurious 'break' statement at the end of a switch-case
not exists(Case c, int i | i = c.getNumBodyStmt() | (BreakStmt)s = c.getBodyStmt(i-1)) and
// ignore ambient statements
not s.isAmbient() and
// ignore empty statements
not s instanceof EmptyStmt
select (FirstLineOf)s, "This statement is unreachable."