JS: Add more bad promise contexts

This commit is contained in:
Asger F
2020-01-03 14:12:55 +00:00
parent 45524d8b19
commit 30a8769dad
3 changed files with 33 additions and 2 deletions

View File

@@ -46,6 +46,14 @@ predicate isBadPromiseContext(Expr expr) {
expr = any(UnaryExpr e).getOperand() expr = any(UnaryExpr e).getOperand()
or or
expr = any(UpdateExpr e).getOperand() expr = any(UpdateExpr e).getOperand()
or
expr = any(ConditionalExpr e).getCondition()
or
expr = any(IfStmt stmt).getCondition()
or
expr = any(ForInStmt stmt).getIterationDomain()
or
expr = any(IndexExpr e).getIndex()
} }
string tryGetPromiseExplanation(Expr e) { string tryGetPromiseExplanation(Expr e) {

View File

@@ -1,2 +1,9 @@
| tst.js:8:9:8:13 | thing | Missing await. The value 'thing' is always a promise. | | tst.js:8:9:8:13 | thing | Missing await. The value 'thing' is always a promise. |
| tst.js:32:12:32:16 | thing | Missing await. The value 'thing' is always a promise. | | tst.js:10:9:10:13 | thing | Missing await. The value 'thing' is always a promise. |
| tst.js:12:15:12:19 | thing | Missing await. The value 'thing' is always a promise. |
| tst.js:14:19:14:23 | thing | Missing await. The value 'thing' is always a promise. |
| tst.js:19:19:19:23 | thing | Missing await. The value 'thing' is always a promise. |
| tst.js:20:9:20:13 | thing | Missing await. The value 'thing' is always a promise. |
| tst.js:22:15:22:19 | thing | Missing await. The value 'thing' is always a promise. |
| tst.js:25:13:25:17 | thing | Missing await. The value 'thing' is always a promise. |
| tst.js:48:12:48:16 | thing | Missing await. The value 'thing' is always a promise. |

View File

@@ -9,7 +9,23 @@ function useThing() {
if (thing == null) {} // NOT OK if (thing == null) {} // NOT OK
return thing + "bar"; // NOT OK something(thing ? 1 : 2); // NOT OK
for (let x in thing) { // NOT OK
something(x);
}
let obj = something();
something(obj[thing]); // NOT OK
obj[thing] = 5; // NOT OK
something(thing + "bar"); // NOT OK
if (something()) {
if (thing) { // NOT OK
something(3);
}
}
} }
async function useThingCorrectly() { async function useThingCorrectly() {