Skip to content

valid-v-else

Reports a v-else that has an expression, an argument or a modifier, shares an element with v-if or v-else-if, or is not on the element right after one with v-if or v-else-if. Only comments and blank space may sit between the elements of a chain.

A v-else that does not continue a chain is a compile error, and an expression on it is ignored, so the author believes there is a second condition.

To fix, write a bare v-else right after the v-if or v-else-if element.

Reported
<template>
<p v-else>no if before</p>
<p v-if="a">a</p>
<!-- a comment may sit between -->
<p v-else-if="b">b</p>
...
<p v-if="a">a</p>
text
...
<p v-else="y">value</p>
...
</template>
angular:
lint:
rules:
valid-v-else: warn # off, warn (default), error
html:
lint:
rules:
valid-v-else: warn # off, warn (default), error
svelte:
lint:
rules:
valid-v-else: warn # off, warn (default), error
vue:
lint:
rules:
valid-v-else: warn # off, warn (default), error

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

Suppress one line with sudsy-disable-next-line valid-v-else 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-else full