mirror of
https://github.com/github/codeql.git
synced 2026-05-01 19:55:15 +02:00
JS: Add query for missing await
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
| 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. |
|
||||
@@ -0,0 +1 @@
|
||||
Expressions/MissingAwait.ql
|
||||
@@ -0,0 +1,47 @@
|
||||
async function getThing() {
|
||||
return something();
|
||||
}
|
||||
|
||||
function useThing() {
|
||||
let thing = getThing();
|
||||
|
||||
if (thing === undefined) {} // NOT OK
|
||||
|
||||
if (thing == null) {} // NOT OK
|
||||
|
||||
return thing + "bar"; // NOT OK
|
||||
}
|
||||
|
||||
async function useThingCorrectly() {
|
||||
let thing = await getThing();
|
||||
|
||||
if (thing === undefined) {} // OK
|
||||
|
||||
if (thing == null) {} // OK
|
||||
|
||||
return thing + "bar"; // OK
|
||||
}
|
||||
|
||||
async function useThingCorrectly2() {
|
||||
let thing = getThing();
|
||||
|
||||
if (await thing === undefined) {} // OK
|
||||
|
||||
if (await thing == null) {} // OK
|
||||
|
||||
return thing + "bar"; // NOT OK
|
||||
}
|
||||
|
||||
function getThingSync() {
|
||||
return something();
|
||||
}
|
||||
|
||||
function useThingPossiblySync(b) {
|
||||
let thing = b ? getThing() : getThingSync();
|
||||
|
||||
if (thing === undefined) {} // OK
|
||||
|
||||
if (thing == null) {} // OK
|
||||
|
||||
return thing + "bar"; // NOT OK - but we don't flag it
|
||||
}
|
||||
Reference in New Issue
Block a user