mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
JavaScript: Teach Unused{Variable,Parameter} to ignore variables with leading underscore.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
*/
|
||||
|
||||
import javascript
|
||||
import UnusedParameter // local library
|
||||
import UnusedParameter
|
||||
|
||||
from Parameter p
|
||||
where isAnAccidentallyUnusedParameter(p)
|
||||
|
||||
@@ -46,7 +46,9 @@ predicate isUnused(Function f, Parameter p, Variable pv, int i) {
|
||||
// functions without a body cannot use their parameters
|
||||
f.hasBody() and
|
||||
// field parameters are used to initialize a field
|
||||
not p instanceof FieldParameter
|
||||
not p instanceof FieldParameter and
|
||||
// common convention: parameters with leading underscore are intentionally unused
|
||||
pv.getName().charAt(0) != "_"
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,7 +22,9 @@ class UnusedLocal extends LocalVariable {
|
||||
not exists(FunctionExpr fe | this = fe.getVariable()) and
|
||||
not exists(ClassExpr ce | this = ce.getVariable()) and
|
||||
not exists(ExportDeclaration ed | ed.exportsAs(this, _)) and
|
||||
not exists(LocalVarTypeAccess type | type.getVariable() = this)
|
||||
not exists(LocalVarTypeAccess type | type.getVariable() = this) and
|
||||
// common convention: variables with leading underscore are intentionally unused
|
||||
getName().charAt(0) != "_"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user