forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReturnAssignsLocal.ql
More file actions
22 lines (20 loc) · 840 Bytes
/
ReturnAssignsLocal.ql
File metadata and controls
22 lines (20 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
* @name Return statement assigns local variable
* @description An assignment to a local variable in a return statement is useless, since the variable will
* immediately go out of scope and its value is lost.
* @kind problem
* @problem.severity warning
* @id js/useless-assignment-in-return
* @tags maintainability
* readability
* external/cwe/cwe-563
* @precision very-high
*/
import javascript
import semmle.javascript.RestrictedLocations
from ReturnStmt r, AssignExpr assgn, Variable v
where assgn = r.getExpr().stripParens() and
v = ((Function)r.getContainer()).getScope().getAVariable() and
not v.isCaptured() and
assgn.getLhs() = v.getAnAccess()
select (FirstLineOf)r, "The assignment to " + v.getName() + " is useless, since it is a local variable and will go out of scope."