Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 87e0027

Browse files
committed
JS: address comments
1 parent 56707fc commit 87e0027

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

javascript/ql/src/Statements/UselessConditional.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,11 @@ predicate whitelist(Expr e) {
120120
*/
121121
predicate isConditional(ASTNode cond, Expr e) {
122122
e = cond.(IfStmt).getCondition() or
123-
e = cond.(WhileStmt).getExpr() or
124-
e = cond.(ForStmt).getTest() or
123+
e = cond.(LoopStmt).getTest() or
125124
e = cond.(ConditionalExpr).getCondition() or
126125
e = cond.(LogicalBinaryExpr).getLeftOperand() or
127126
// Include `z` in `if (x && z)`.
128-
isConditional(_, cond) and e = cond.(LogicalBinaryExpr).getRightOperand()
127+
isConditional(_, cond) and e = cond.(Expr).getUnderlyingValue().(LogicalBinaryExpr).getRightOperand()
129128
}
130129

131130
from ASTNode cond, DataFlow::AnalyzedNode op, boolean cv, ASTNode sel, string msg

javascript/ql/test/query-tests/Statements/UselessConditional/UselessConditional.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
| UselessConditional.js:94:16:94:16 | x | This use of variable 'x' always evaluates to false. |
2020
| UselessConditional.js:100:13:100:24 | true && true | This expression always evaluates to true. |
2121
| UselessConditional.js:101:18:101:18 | x | This use of variable 'x' always evaluates to false. |
22+
| UselessConditional.js:102:19:102:19 | x | This use of variable 'x' always evaluates to false. |
23+
| UselessConditional.js:103:23:103:23 | x | This use of variable 'x' always evaluates to false. |
2224
| UselessConditionalGood.js:58:12:58:13 | x2 | This use of variable 'x2' always evaluates to false. |
2325
| UselessConditionalGood.js:69:12:69:13 | xy | This use of variable 'xy' always evaluates to false. |
2426
| UselessConditionalGood.js:85:12:85:13 | xy | This use of variable 'xy' always evaluates to false. |

javascript/ql/test/query-tests/Statements/UselessConditional/UselessConditional.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ async function awaitFlow(){
9999
}
100100
if (true && true) {} // NOT OK
101101
if (y && x) {} // NOT OK
102+
if (y && (x)) {} // NOT OK
103+
do { } while (x); // NOT OK
102104
}
103105
});
104106

0 commit comments

Comments
 (0)