vue/valid-v-if
Enforce valid v-if directives.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
error |
essential, happy-path, nuxt, ecosystem, opinionated |
No | None |
Applies to: Vue SFC templates and blocks, with script context where the rule requires it.
Bad
The conditions omit an expression or combine v-if with an else directive on the same node.
<template>
<div v-if></div>
<div v-if=""></div>
<div v-if="ready" v-else></div>
</template>
Good
Each v-if has a nonempty condition such as ready or count > 0, without an incompatible else directive.
<template>
<div v-if="ready"></div>
<div v-if="count > 0"></div>
</template>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/valid-v-if": "error"
}
},
});
Then run vp run lint.