valid-v-else
Angular templatesHTMLVue / SvelteVue / Sveltecorrectnessno fixdefault: warnhtml/eslint-plugin-vue-recommended
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”<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>Configuration
Section titled “Configuration”angular: lint: rules: valid-v-else: warn # off, warn (default), errorhtml: lint: rules: valid-v-else: warn # off, warn (default), errorsvelte: lint: rules: valid-v-else: warn # off, warn (default), errorvue: lint: rules: valid-v-else: warn # off, warn (default), errorEnabled 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.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| eslint-plugin-vue | valid-v-else |
full |