type/require-await
Disallow async functions that contain no await expression.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
nuxt, opinionated |
No | None |
Applies to: Type information in Vue SFC scripts and templates, for the constructs shown below.
This rule reads type information from your TypeScript project (tsconfig.json), so the configuration sets typeAware: true. typeAware does not turn on opt-in rules by itself.
Bad
noAwait is async but its body never awaits a value.
<script setup lang="ts">
async function noAwait(): Promise<number> {
return 1;
}
</script>
Good
withAwait awaits Promise.resolve(1) before returning it.
<script setup lang="ts">
async function withAwait(): Promise<number> {
return await Promise.resolve(1);
}
</script>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"type/require-await": "warn"
},
"typeAware": true
},
});
Then run vp run lint.