Skip to content

noVueDuplicateVElseIf (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noVueDuplicateVElseIf": "error"
}
}
}
}

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.

<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>