Skip to content

valid-v-if

Reports a v-if that has no expression, has an argument or a modifier, or is on the same element as v-else or v-else-if.

A v-if without an expression fails to compile or always hides the element, and an argument or a modifier is ignored.

To fix, write v-if="condition" and put v-else on the next element.

Reported
...
text
...
<p v-if="a" v-else-if="b">both</p>
</template>
angular:
lint:
rules:
valid-v-if: warn # off, warn (default), error
html:
lint:
rules:
valid-v-if: warn # off, warn (default), error
svelte:
lint:
rules:
valid-v-if: warn # off, warn (default), error
vue:
lint:
rules:
valid-v-if: warn # off, warn (default), error

Enabled by the presets: html/eslint-plugin-vue-recommended.

Suppress one line with sudsy-disable-next-line valid-v-if in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
eslint-plugin-vue valid-v-if full