-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathRedeclaredVariable.ql
More file actions
29 lines (27 loc) · 970 Bytes
/
RedeclaredVariable.ql
File metadata and controls
29 lines (27 loc) · 970 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
28
29
/**
* @name Redeclared variable
* @description Declaring the same variable twice is confusing and may even suggest a latent bug.
* @kind problem
* @problem.severity recommendation
* @id js/variable-redeclaration
* @tags quality
* reliability
* correctness
* readability
* @precision medium
*/
import javascript
private import Declarations.Declarations
from Variable v, TopLevel tl, VarDecl decl, VarDecl redecl
where
decl = firstRefInTopLevel(v, Decl(), tl) and
redecl = refInTopLevel(v, Decl(), tl) and
redecl != decl and
not tl.isExterns() and
// Ignore redeclared ambient declarations, such as overloaded functions.
not decl.isAmbient() and
not redecl.isAmbient() and
// Redeclaring a namespace extends the previous definition.
not decl = any(NamespaceDeclaration ns).getIdentifier() and
not redecl = any(NamespaceDeclaration ns).getIdentifier()
select redecl, "This variable has already $@.", decl, "been declared"