Skip to content

valid-v-else-if

Reports a v-else-if that has no expression, has an argument or a modifier, shares an element with v-if or v-else, 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-if that does not continue a chain is a compile error, or it is ignored and the element is always rendered.

To fix, write v-else-if="condition" right after the v-if or v-else-if element.

Reported
...
<!-- a comment may sit between -->
<p v-else-if="b">b</p>
<p v-else>c</p>
<p v-else-if="d">after else</p>
<p v-if="a">a</p>
text
<p v-else-if="x">b</p>
...
<p v-if="a" v-else-if="b">both</p>
</template>
angular:
lint:
rules:
valid-v-else-if: warn # off, warn (default), error
html:
lint:
rules:
valid-v-else-if: warn # off, warn (default), error
svelte:
lint:
rules:
valid-v-else-if: warn # off, warn (default), error
vue:
lint:
rules:
valid-v-else-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-else-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-else-if full