mirror of
https://github.com/github/codeql.git
synced 2026-05-04 05:05:12 +02:00
JS: make use of getUnderlyingValue in js/useless-assignment-to-local
This commit is contained in:
@@ -38,9 +38,7 @@ predicate isDefaultInit(Expr e) {
|
||||
// initialising to an empty array or object literal, even if unnecessary,
|
||||
// can convey useful type information to the reader
|
||||
e.(ArrayExpr).getSize() = 0 or
|
||||
e.(ObjectExpr).getNumProperty() = 0 or
|
||||
// recursive case
|
||||
isDefaultInit(e.(AssignExpr).getRhs())
|
||||
e.(ObjectExpr).getNumProperty() = 0
|
||||
}
|
||||
|
||||
from VarDef dead, PurelyLocalVariable v // captured variables may be read by closures, so don't flag them
|
||||
@@ -60,7 +58,7 @@ where deadStoreOfLocal(dead, v) and
|
||||
// don't flag overwrites with `null` or `undefined`
|
||||
not SyntacticConstants::isNullOrUndefined(dead.getSource()) and
|
||||
// don't flag default inits that are later overwritten
|
||||
not (isDefaultInit(dead.getSource()) and dead.isOverwritten(v)) and
|
||||
not (isDefaultInit(dead.getSource().(Expr).getUnderlyingValue()) and dead.isOverwritten(v)) and
|
||||
// don't flag assignments in externs
|
||||
not dead.(ASTNode).inExternsFile() and
|
||||
// don't flag exported variables
|
||||
|
||||
@@ -7,4 +7,3 @@
|
||||
| tst.js:45:6:45:11 | x = 23 | This definition of x is useless, since its value is never read. |
|
||||
| tst.js:51:6:51:11 | x = 23 | This definition of x is useless, since its value is never read. |
|
||||
| tst.js:132:7:132:13 | {x} = o | This definition of x is useless, since its value is never read. |
|
||||
| tst.js:158:11:158:21 | a = (x, -1) | This definition of a is useless, since its value is never read. |
|
||||
|
||||
Reference in New Issue
Block a user