mirror of
https://github.com/github/codeql.git
synced 2026-04-29 18:55:14 +02:00
JS: add whitelist to js/useless-defensive-code
This commit is contained in:
@@ -15,5 +15,18 @@ import javascript
|
||||
import semmle.javascript.DefensiveProgramming
|
||||
|
||||
from DefensiveExpression e, boolean cv
|
||||
where e.getTheTestResult() = cv
|
||||
where e.getTheTestResult() = cv and
|
||||
// whitelist
|
||||
not (
|
||||
// module environment detection
|
||||
exists (VarAccess access, string name |
|
||||
name = "exports" or name = "module" |
|
||||
e.asExpr().(Internal::TypeofUndefinedTest).getOperand() = access and
|
||||
access.getName() = name and
|
||||
not exists (access.getVariable().getADeclaration())
|
||||
)
|
||||
or
|
||||
// too benign in practice
|
||||
e instanceof Internal::DefensiveInit
|
||||
)
|
||||
select e, "This guard always evaluates to " + cv + "."
|
||||
|
||||
@@ -390,7 +390,7 @@ module Internal {
|
||||
/**
|
||||
* A test for `undefined` using a `typeof` expression.
|
||||
*/
|
||||
private class TypeofUndefinedTest extends UndefinedNullTest {
|
||||
class TypeofUndefinedTest extends UndefinedNullTest {
|
||||
|
||||
TypeofTest test;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user