no-use-v-if-with-v-for
Angular templatesHTMLVue / SvelteVue / Sveltesuspiciousno fixdefault: warnhtml/eslint-plugin-vue-recommended
What it does
Section titled “What it does”Reports an element that has v-if and v-for together.
Why it matters
Section titled “Why it matters”In Vue 3 v-if is evaluated first, so a condition on the loop variable fails with an error, and in Vue 2 the order was the other way round, which makes the code unsafe to port.
To fix, filter the list in a computed value, or move the v-if to a wrapping <template>.
Example
Section titled “Example”<ul><li v-for="x in xs" v-if="x.on" :key="x.id">a</li><li v-if="a">b</li><template v-for="x in xs" :key="x.id"><li v-if="x.on">c</li></template></ul>Configuration
Section titled “Configuration”angular: lint: rules: no-use-v-if-with-v-for: warn # off, warn (default), errorhtml: lint: rules: no-use-v-if-with-v-for: warn # off, warn (default), errorsvelte: lint: rules: no-use-v-if-with-v-for: warn # off, warn (default), errorvue: lint: rules: no-use-v-if-with-v-for: warn # off, warn (default), errorEnabled by the presets: html/eslint-plugin-vue-recommended.
Suppress one line with sudsy-disable-next-line no-use-v-if-with-v-for 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 | no-use-v-if-with-v-for |
full |