Skip to content

Commit eb7e0d6

Browse files
committed
still flag single-expression files that contain a function
1 parent ffdbe31 commit eb7e0d6

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

javascript/ql/src/Expressions/ExprHasNoEffect.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ predicate hasNoEffect(Expr e) {
159159
not e.(ParExpr).getExpression().getLastToken().getNextToken().getValue() = ":" and
160160
// exclude the first statement of a try block
161161
not e = any(TryStmt stmt).getBody().getStmt(0).(ExprStmt).getExpr() and
162-
// exclude expressions that are alone in a file
163-
not e.getParent().(ExprStmt).getParent().(TopLevel).getNumChild() = 1
162+
// exclude expressions that are alone in a file, and file doesn't contain a function.
163+
not exists(TopLevel top |
164+
top = e.getParent().(ExprStmt).getParent() and
165+
top.getNumChild() = 1 and
166+
not exists(Function fun | fun.getEnclosingContainer() = top)
167+
)
164168
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["foo", "bar", 123]

0 commit comments

Comments
 (0)