Skip to content

Commit 8bd817c

Browse files
committed
Exclude expressions that are part of a conditional expression
1 parent b7f7092 commit 8bd817c

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

javascript/ql/lib/Expressions/ExprHasNoEffect.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ predicate hasNoEffect(Expr e) {
178178
e.getParent() = parent and
179179
e.getLastToken().getNextToken().getValue() = ":"
180180
) and
181+
// exclude expressions that are part of a conditional expression
182+
not exists(ConditionalExpr cond | e.getParent() = cond) and
181183
// exclude the first statement of a try block
182184
not e = any(TryStmt stmt).getBody().getStmt(0).(ExprStmt).getExpr() and
183185
// 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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,4 @@
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:77:24:77:24 | o | This expression has no effect. |
15-
| tst.js:83:43:83:46 | null | This expression has no effect. |
16-
| tst.js:84:42:84:45 | null | This expression has no effect. |
1714
| 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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ function g() {
7474

7575
(o: empty);
7676

77-
testSomeCondition() ? o : // $ Alert
77+
testSomeCondition() ? o :
7878
doSomethingDangerous();
7979

8080
consume(testSomeCondition() ? o :
8181
doSomethingDangerous());
8282

83-
("release" === isRelease() ? warning() : null); // $ Alert
84-
"release" === isRelease() ? warning() : null; // $ Alert
83+
("release" === isRelease() ? warning() : null);
84+
"release" === isRelease() ? warning() : null;
8585
};

0 commit comments

Comments
 (0)