Branches ofv-if
directive should not have the same implementation
This rule applies when the content of an element havingv-if
orv-else-if
directive is identical to thev-else
branch.
This might imply the condition is unnecessary, but at worst this is a programmer's mistake. For example, a programmer copies code from a branch into another and forgets to modify it.
Therefore, a programmer needs to check the same content is really needed for both branches.
Noncompliant Code Example | Compliant Code Example | ||
---|---|---|---|
1 | <template> | 1 | <template> |
2 | <div v-if="cond"> | 2 | <div v-if="cond"> |
3 | Hi there! | 3 | Hi there! |
4 | </div> | 4 | </div> |
5 | <div v-else> | 5 | <div v-else> |
6 | Hi there! | 6 | Goodbye! |
7 | </div> | 7 | </div> |
8 | </template> | 8 | </template> |
<template> <div v-if="cond"> Hi there! </div> <div v-else> Hi there! </div></template>
<template> <div v-if="cond"> Hi there! </div> <div v-else> Goodbye! </div></template>
This rule was introduced in DeepScan 1.40.0.