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

Skip to content

Commit 5dcc5b3

Browse files
authored
Merge pull request #2581 from erik-krogh/FlowUselessExpr
Approved by max-schaefer
2 parents 9b9d712 + c22d3d0 commit 5dcc5b3

4 files changed

Lines changed: 8 additions & 3 deletions

File tree

change-notes/1.24/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
| Clear-text logging of sensitive information (`js/clear-text-logging`) | More results | More results involving `process.env` and indirect calls to logging methods are recognized. |
2424
| Incomplete string escaping or encoding (`js/incomplete-sanitization`) | Fewer false positive results | This query now recognizes additional cases where a single replacement is likely to be intentional. |
2525
| Unbound event handler receiver (`js/unbound-event-handler-receiver`) | Fewer false positive results | This query now recognizes additional ways event handler receivers can be bound. |
26+
| Expression has no effect (`js/useless-expression`) | Fewer false positive results | The query now recognizes block-level flow type annotations. |
2627

2728
## Changes to libraries
2829

javascript/ql/src/Expressions/ExprHasNoEffect.qll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ predicate inVoidContext(Expr e) {
4040
exists(LogicalBinaryExpr logical | e = logical.getRightOperand() and inVoidContext(logical))
4141
}
4242

43-
4443
/**
4544
* Holds if `e` is of the form `x;` or `e.p;` and has a JSDoc comment containing a tag.
4645
* In that case, it is probably meant as a declaration and shouldn't be flagged by this query.
@@ -155,5 +154,7 @@ predicate hasNoEffect(Expr e) {
155154
not exists(FunctionExpr fe, ExprStmt es | fe = e |
156155
fe = es.getExpr() and
157156
not exists(fe.getName())
158-
)
159-
}
157+
) and
158+
// exclude block-level flow type annotations. For example: `(name: empty)`.
159+
not e.(ParExpr).getExpression().getLastToken().getNextToken().getValue() = ":"
160+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options: --experimental

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,6 @@ function g() {
7272

7373
Object.defineProperty(o, "nonTrivialGetter2", unknownGetterDef());
7474
o.nonTrivialGetter2; // OK
75+
76+
(o: empty); // OK.
7577
};

0 commit comments

Comments
 (0)