Skip to content

Commit 358e618

Browse files
author
Esben Sparre Andreasen
committed
JS: downgrade other alerts to js/useless-defensive-code
1 parent e29c57a commit 358e618

6 files changed

Lines changed: 8 additions & 1 deletion

File tree

javascript/ql/src/Expressions/HeterogeneousComparison.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import javascript
1717
private import semmle.javascript.dataflow.InferredTypes
18+
private import semmle.javascript.DefensiveProgramming
1819

1920
/**
2021
* Holds if `left` and `right` are the left and right operands, respectively, of `nd`, which is
@@ -198,6 +199,7 @@ from ASTNode cmp,
198199
int leftTypeCount, int rightTypeCount ,
199200
string leftTypeDescription, string rightTypeDescription
200201
where isHeterogeneousComparison(cmp, left, right, leftTypes, rightTypes) and
202+
not exists (cmp.(Expr).flow().(DefensiveExpression).getTheTestResult()) and
201203
not whitelist(left.asExpr()) and
202204
not whitelist(right.asExpr()) and
203205
leftExprDescription = capitalize(getDescription(left.asExpr(), "this expression")) and

javascript/ql/src/Statements/UselessConditional.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ predicate isConstantBooleanReturnValue(Expr e) {
8787
predicate whitelist(Expr e) {
8888
isConstant(e) or
8989
isConstant(e.(LogNotExpr).getOperand()) or
90-
e.flow() instanceof Internal::DefensiveInit or
90+
exists (e.flow().(DefensiveExpression).getTheTestResult()) or
9191
isInitialParameterUse(e) or
9292
isConstantBooleanReturnValue(e)
9393
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| tst.js:162:9:162:16 | typeof x | This expression is of type string, but it is compared to $@ of type undefined. | tst.js:162:22:162:30 | undefined | 'undefined' |
2+
| tst.js:163:9:163:21 | typeof window | This expression is of type string, but it is compared to $@ of type undefined. | tst.js:163:27:163:35 | undefined | 'undefined' |
3+
| tst.js:165:9:165:16 | typeof x | This expression is of type string, but it is compared to $@ of type undefined. | tst.js:165:22:165:22 | u | variable 'u' |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Expressions/HeterogeneousComparison.ql

javascript/ql/test/query-tests/Expressions/UselessDefensiveProgramming/UselessConditional.expected

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Statements/UselessConditional.ql

0 commit comments

Comments
 (0)