forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignmentToConst.ql
More file actions
26 lines (24 loc) · 857 Bytes
/
AssignmentToConst.ql
File metadata and controls
26 lines (24 loc) · 857 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
/**
* @name Assignment to constant
* @description Assigning to a variable that is declared 'const' has either no effect or leads to a
* runtime error, depending on the platform.
* @kind problem
* @problem.severity error
* @id js/assignment-to-constant
* @tags quality
* reliability
* correctness
* @precision very-high
*/
import javascript
import semmle.javascript.RestrictedLocations
from DeclStmt cds, VariableDeclarator decl, VarDef def, Variable v
where
(cds instanceof ConstDeclStmt or cds instanceof UsingDeclStmt) and
decl = cds.getADecl() and
def.getAVariable() = v and
decl.getBindingPattern().getAVariable() = v and
def != decl and
def.(ExprOrStmt).getTopLevel() = decl.getTopLevel()
select def.(FirstLineOf), "Assignment to variable " + v.getName() + ", which is $@ constant.", cds,
"declared"