Skip to content

Commit 9210660

Browse files
authored
Merge pull request github#3401 from erik-krogh/jsonLike
Approved by esbena
2 parents 86c5b38 + eb7e0d6 commit 9210660

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

change-notes/1.25/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
| Misspelled variable name (`js/misspelled-variable-name`) | Message changed | The message for this query now correctly identifies the misspelled variable in additional cases. |
2121
| Uncontrolled data used in path expression (`js/path-injection`) | More results | This query now recognizes additional file system calls. |
2222
| Uncontrolled command line (`js/command-line-injection`) | More results | This query now recognizes additional command execution calls. |
23+
| Expression has no effect (`js/useless-expression`) | Less results | This query no longer flags an expression when that expression is the only content of the containing file. |
2324

2425
## Changes to libraries
2526

javascript/ql/src/Expressions/ExprHasNoEffect.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,11 @@ predicate hasNoEffect(Expr e) {
158158
// exclude block-level flow type annotations. For example: `(name: empty)`.
159159
not e.(ParExpr).getExpression().getLastToken().getNextToken().getValue() = ":" and
160160
// exclude the first statement of a try block
161-
not e = any(TryStmt stmt).getBody().getStmt(0).(ExprStmt).getExpr()
161+
not e = any(TryStmt stmt).getBody().getStmt(0).(ExprStmt).getExpr() and
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+
)
162168
}
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)