noVueDuplicateVElseIf (JavaScript)
Summary
Section titled “Summary”- Rule available since:
v2.6.9 - Diagnostic Category:
lint/nursery/noVueDuplicateVElseIf - This rule doesn’t have a fix.
- The default severity of this rule is error.
- This rule belongs to the following domains:
- Sources:
- Same as
vue/no-dupe-v-else-if
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noVueDuplicateVElseIf": "error" } } }}Description
Section titled “Description”Disallow duplicate conditions in v-if / v-else-if chains.
Vue renders only the first element of a v-if / v-else-if chain whose condition is
true. When a v-else-if repeats a condition from earlier in the same chain, its element
can never be rendered: whenever its condition is true, the earlier one is true too. This
is almost always a copy-paste mistake.
The rule also understands || and &&, so it reports conditions that earlier
conditions already cover, even when they aren’t written the same way. For example,
v-else-if="a" can never be reached after v-if="a || b", and v-else-if="a && b"
can never be reached after v-if="a".
The rule assumes that evaluating a condition twice gives the same result both times.
A condition that calls a function returning a different value on every call, such as
Math.random() > 0.5, can be reported even though its element can be rendered.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<template> <div v-if="isSomething(x)" /> <div v-else-if="isSomething(x)" /></template>code-block.vue:3:19 lint/nursery/noVueDuplicateVElseIf ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This condition is a duplicate of, or is covered by, earlier conditions in the v-if / v-else-if chain.
1 │ <template>
2 │ <div v-if="isSomething(x)" />
> 3 │ <div v-else-if="isSomething(x)" />
│ ^^^^^^^^^^^^^^
4 │ </template>
5 │
ℹ Whenever this condition is true, an earlier condition of the chain is true too, so this element is never rendered.
ℹ Remove this element, or change its condition to the one you meant.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
<template> <div v-if="n === 1" /> <div v-else-if="n === 2" /> <div v-else-if="n === 1" /></template>code-block.vue:4:19 lint/nursery/noVueDuplicateVElseIf ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This condition is a duplicate of, or is covered by, earlier conditions in the v-if / v-else-if chain.
2 │ <div v-if="n === 1" />
3 │ <div v-else-if="n === 2" />
> 4 │ <div v-else-if="n === 1" />
│ ^^^^^^^
5 │ </template>
6 │
ℹ Whenever this condition is true, an earlier condition of the chain is true too, so this element is never rendered.
ℹ Remove this element, or change its condition to the one you meant.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
<template> <div v-if="a || b" /> <div v-else-if="a" /></template>code-block.vue:3:19 lint/nursery/noVueDuplicateVElseIf ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This condition is a duplicate of, or is covered by, earlier conditions in the v-if / v-else-if chain.
1 │ <template>
2 │ <div v-if="a || b" />
> 3 │ <div v-else-if="a" />
│ ^
4 │ </template>
5 │
ℹ Whenever this condition is true, an earlier condition of the chain is true too, so this element is never rendered.
ℹ Remove this element, or change its condition to the one you meant.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
<template> <div v-if="a" /> <div v-else-if="a && b" /></template>code-block.vue:3:19 lint/nursery/noVueDuplicateVElseIf ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This condition is a duplicate of, or is covered by, earlier conditions in the v-if / v-else-if chain.
1 │ <template>
2 │ <div v-if="a" />
> 3 │ <div v-else-if="a && b" />
│ ^
4 │ </template>
5 │
ℹ Whenever this condition is true, an earlier condition of the chain is true too, so this element is never rendered.
ℹ Remove this element, or change its condition to the one you meant.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
<template> <div v-if="isSomething(x)" /> <div v-else-if="isSomethingElse(x)" />
<div v-if="n === 1" /> <div v-else-if="n === 2" /> <div v-else-if="n === 3" />
<div v-if="a && b" /> <div v-else-if="a" /></template>See Also
Section titled “See Also”- For the same check on
ifstatements in JavaScript, seenoDuplicateElseIf.
Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.