mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
JS: ignore useless-expr in first stmt in try block
This commit is contained in:
@@ -156,5 +156,7 @@ predicate hasNoEffect(Expr e) {
|
||||
not exists(fe.getName())
|
||||
) and
|
||||
// exclude block-level flow type annotations. For example: `(name: empty)`.
|
||||
not e.(ParExpr).getExpression().getLastToken().getNextToken().getValue() = ":"
|
||||
not e.(ParExpr).getExpression().getLastToken().getNextToken().getValue() = ":" and
|
||||
// exclude the first statement of a try block
|
||||
not e = any(TryStmt stmt).getBody().getStmt(0).(ExprStmt).getExpr()
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
| try.js:22:9:22:26 | x.ordinaryProperty | This expression has no effect. |
|
||||
| tst2.js:3:4:3:4 | 0 | This expression has no effect. |
|
||||
| tst.js:3:1:3:2 | 23 | This expression has no effect. |
|
||||
| tst.js:5:1:5:2 | 23 | This expression has no effect. |
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
function try1(x) {
|
||||
try {
|
||||
x.ordinaryProperty; // OK - try/catch indicates intent to throw exception
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function try2(x) {
|
||||
try {
|
||||
x.ordinaryProperty; // OK - try/catch indicates intent to throw exception
|
||||
return x;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function try3(x) {
|
||||
try {
|
||||
x.ordinaryProperty()
|
||||
x.ordinaryProperty // NOT OK
|
||||
return x;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user