Skip to content

Commit aac56e0

Browse files
committed
JavaScript: Fix false positive on Flow type annotations in ExprHasNoEffect
1 parent 46b5ded commit aac56e0

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

javascript/ql/lib/Expressions/ExprHasNoEffect.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ predicate hasNoEffect(Expr e) {
174174
not exists(fe.getName())
175175
) and
176176
// exclude block-level flow type annotations. For example: `(name: empty)`.
177-
not e.(ParExpr).getExpression().getLastToken().getNextToken().getValue() = ":" and
177+
not exists(ParExpr parent |
178+
e.getParent() = parent and
179+
e.getLastToken().getNextToken().getValue() = ":"
180+
) and
178181
// exclude the first statement of a try block
179182
not e = any(TryStmt stmt).getBody().getStmt(0).(ExprStmt).getExpr() and
180183
// exclude expressions that are alone in a file, and file doesn't contain a function.

javascript/ql/test/query-tests/Expressions/ExprHasNoEffect/ExprHasNoEffect.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@
1111
| tst.js:49:3:49:49 | new Syn ... o me?") | This expression has no effect. |
1212
| tst.js:50:3:50:36 | new Err ... age(e)) | This expression has no effect. |
1313
| tst.js:61:2:61:20 | o.trivialNonGetter1 | This expression has no effect. |
14-
| tst.js:75:3:75:3 | o | This expression has no effect. |
1514
| tst.js:77:24:77:24 | o | This expression has no effect. |
1615
| uselessfn.js:1:2:1:26 | functio ... d.");\\n} | This expression has no effect. |

javascript/ql/test/query-tests/Expressions/ExprHasNoEffect/tst.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function g() {
7272
Object.defineProperty(o, "nonTrivialGetter2", unknownGetterDef());
7373
o.nonTrivialGetter2;
7474

75-
(o: empty); // $SPURIOUS:Alert
75+
(o: empty);
7676

7777
testSomeCondition() ? o : // $ Alert
7878
doSomethingDangerous();

0 commit comments

Comments
 (0)