--- source: crates/biome_js_analyze/tests/spec_tests.rs expression: invalid.js --- # Input ```jsx async function fetchData() { return fetch('/data'); } (async function fetchDataImmediate() { return fetch('/data'); })(); const obj = { async fetchData() { return fetch('/data'); }, }; class DataFetcher { async fetchData() { return fetch('/data'); } } async function outer() { async function innerFetchData() { return fetch('/data'); } } async function outer() { async function innerFetchData() { return fetch('/data'); } return fetch('/another-data'); } async function outer() { async function innerFetchData() { return await fetch('/data'); } return fetch('/another-data'); } async function complexFunction() { const obj = { async fetchData() { return fetch('/data'); }, }; class NestedDataFetcher { async fetchData() { return fetch('/data'); } } if (a === 'a') { return fetch('condition-data'); } } async function withoutForAwait () { let sum = 0; for (const n of [1, 2, 3]) { sum += n } return sum; }; ``` # Diagnostics ``` invalid.js:1:1 lint/suspicious/useAwait ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! This async function lacks an await expression. > 1 │ async function fetchData() { │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 2 │ return fetch('/data'); > 3 │ } │ ^ 4 │ 5 │ (async function fetchDataImmediate() { i Remove this async modifier, or add an await expression in the function. > 1 │ async function fetchData() { │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 2 │ return fetch('/data'); > 3 │ } │ ^ 4 │ 5 │ (async function fetchDataImmediate() { i Async functions without await expressions may not need to be declared async. ``` ``` invalid.js:5:2 lint/suspicious/useAwait ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! This async function lacks an await expression. 3 │ } 4 │ > 5 │ (async function fetchDataImmediate() { │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 6 │ return fetch('/data'); > 7 │ })(); │ ^ 8 │ 9 │ const obj = { i Remove this async modifier, or add an await expression in the function. 3 │ } 4 │ > 5 │ (async function fetchDataImmediate() { │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 6 │ return fetch('/data'); > 7 │ })(); │ ^ 8 │ 9 │ const obj = { i Async functions without await expressions may not need to be declared async. ``` ``` invalid.js:10:2 lint/suspicious/useAwait ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! This async function lacks an await expression. 9 │ const obj = { > 10 │ async fetchData() { │ ^^^^^^^^^^^^^^^^^^^ > 11 │ return fetch('/data'); > 12 │ }, │ ^ 13 │ }; 14 │ i Remove this async modifier, or add an await expression in the function. 9 │ const obj = { > 10 │ async fetchData() { │ ^^^^^^^^^^^^^^^^^^^ > 11 │ return fetch('/data'); > 12 │ }, │ ^ 13 │ }; 14 │ i Async functions without await expressions may not need to be declared async. ``` ``` invalid.js:16:2 lint/suspicious/useAwait ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! This async function lacks an await expression. 15 │ class DataFetcher { > 16 │ async fetchData() { │ ^^^^^^^^^^^^^^^^^^^ > 17 │ return fetch('/data'); > 18 │ } │ ^ 19 │ } 20 │ i Remove this async modifier, or add an await expression in the function. 15 │ class DataFetcher { > 16 │ async fetchData() { │ ^^^^^^^^^^^^^^^^^^^ > 17 │ return fetch('/data'); > 18 │ } │ ^ 19 │ } 20 │ i Async functions without await expressions may not need to be declared async. ``` ``` invalid.js:22:2 lint/suspicious/useAwait ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! This async function lacks an await expression. 21 │ async function outer() { > 22 │ async function innerFetchData() { │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 23 │ return fetch('/data'); > 24 │ } │ ^ 25 │ } 26 │ i Remove this async modifier, or add an await expression in the function. 21 │ async function outer() { > 22 │ async function innerFetchData() { │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 23 │ return fetch('/data'); > 24 │ } │ ^ 25 │ } 26 │ i Async functions without await expressions may not need to be declared async. ``` ``` invalid.js:21:1 lint/suspicious/useAwait ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! This async function lacks an await expression. 19 │ } 20 │ > 21 │ async function outer() { │ ^^^^^^^^^^^^^^^^^^^^^^^^ > 22 │ async function innerFetchData() { > 23 │ return fetch('/data'); > 24 │ } > 25 │ } │ ^ 26 │ 27 │ async function outer() { i Remove this async modifier, or add an await expression in the function. 19 │ } 20 │ > 21 │ async function outer() { │ ^^^^^^^^^^^^^^^^^^^^^^^^ > 22 │ async function innerFetchData() { > 23 │ return fetch('/data'); > 24 │ } > 25 │ } │ ^ 26 │ 27 │ async function outer() { i Async functions without await expressions may not need to be declared async. ``` ``` invalid.js:28:2 lint/suspicious/useAwait ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! This async function lacks an await expression. 27 │ async function outer() { > 28 │ async function innerFetchData() { │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 29 │ return fetch('/data'); > 30 │ } │ ^ 31 │ return fetch('/another-data'); 32 │ } i Remove this async modifier, or add an await expression in the function. 27 │ async function outer() { > 28 │ async function innerFetchData() { │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 29 │ return fetch('/data'); > 30 │ } │ ^ 31 │ return fetch('/another-data'); 32 │ } i Async functions without await expressions may not need to be declared async. ``` ``` invalid.js:27:1 lint/suspicious/useAwait ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! This async function lacks an await expression. 25 │ } 26 │ > 27 │ async function outer() { │ ^^^^^^^^^^^^^^^^^^^^^^^^ > 28 │ async function innerFetchData() { > 29 │ return fetch('/data'); > 30 │ } > 31 │ return fetch('/another-data'); > 32 │ } │ ^ 33 │ 34 │ async function outer() { i Remove this async modifier, or add an await expression in the function. 25 │ } 26 │ > 27 │ async function outer() { │ ^^^^^^^^^^^^^^^^^^^^^^^^ > 28 │ async function innerFetchData() { > 29 │ return fetch('/data'); > 30 │ } > 31 │ return fetch('/another-data'); > 32 │ } │ ^ 33 │ 34 │ async function outer() { i Async functions without await expressions may not need to be declared async. ``` ``` invalid.js:34:1 lint/suspicious/useAwait ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! This async function lacks an await expression. 32 │ } 33 │ > 34 │ async function outer() { │ ^^^^^^^^^^^^^^^^^^^^^^^^ > 35 │ async function innerFetchData() { > 36 │ return await fetch('/data'); > 37 │ } > 38 │ return fetch('/another-data'); > 39 │ } │ ^ 40 │ 41 │ async function complexFunction() { i Remove this async modifier, or add an await expression in the function. 32 │ } 33 │ > 34 │ async function outer() { │ ^^^^^^^^^^^^^^^^^^^^^^^^ > 35 │ async function innerFetchData() { > 36 │ return await fetch('/data'); > 37 │ } > 38 │ return fetch('/another-data'); > 39 │ } │ ^ 40 │ 41 │ async function complexFunction() { i Async functions without await expressions may not need to be declared async. ``` ``` invalid.js:43:3 lint/suspicious/useAwait ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! This async function lacks an await expression. 41 │ async function complexFunction() { 42 │ const obj = { > 43 │ async fetchData() { │ ^^^^^^^^^^^^^^^^^^^ > 44 │ return fetch('/data'); > 45 │ }, │ ^ 46 │ }; 47 │ i Remove this async modifier, or add an await expression in the function. 41 │ async function complexFunction() { 42 │ const obj = { > 43 │ async fetchData() { │ ^^^^^^^^^^^^^^^^^^^ > 44 │ return fetch('/data'); > 45 │ }, │ ^ 46 │ }; 47 │ i Async functions without await expressions may not need to be declared async. ``` ``` invalid.js:49:3 lint/suspicious/useAwait ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! This async function lacks an await expression. 48 │ class NestedDataFetcher { > 49 │ async fetchData() { │ ^^^^^^^^^^^^^^^^^^^ > 50 │ return fetch('/data'); > 51 │ } │ ^ 52 │ } 53 │ i Remove this async modifier, or add an await expression in the function. 48 │ class NestedDataFetcher { > 49 │ async fetchData() { │ ^^^^^^^^^^^^^^^^^^^ > 50 │ return fetch('/data'); > 51 │ } │ ^ 52 │ } 53 │ i Async functions without await expressions may not need to be declared async. ``` ``` invalid.js:41:1 lint/suspicious/useAwait ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! This async function lacks an await expression. 39 │ } 40 │ > 41 │ async function complexFunction() { │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 42 │ const obj = { ... > 56 │ } > 57 │ } │ ^ 58 │ 59 │ async function withoutForAwait () { i Remove this async modifier, or add an await expression in the function. 39 │ } 40 │ > 41 │ async function complexFunction() { │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 42 │ const obj = { ... > 56 │ } > 57 │ } │ ^ 58 │ 59 │ async function withoutForAwait () { i Async functions without await expressions may not need to be declared async. ``` ``` invalid.js:59:1 lint/suspicious/useAwait ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! This async function lacks an await expression. 57 │ } 58 │ > 59 │ async function withoutForAwait () { │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 60 │ let sum = 0; > 61 │ for (const n of [1, 2, 3]) { > 62 │ sum += n > 63 │ } > 64 │ return sum; > 65 │ }; │ ^ 66 │ i Remove this async modifier, or add an await expression in the function. 57 │ } 58 │ > 59 │ async function withoutForAwait () { │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 60 │ let sum = 0; > 61 │ for (const n of [1, 2, 3]) { > 62 │ sum += n > 63 │ } > 64 │ return sum; > 65 │ }; │ ^ 66 │ i Async functions without await expressions may not need to be declared async. ```