Movatterモバイル変換


[0]ホーム

URL:


Branches ofv-if directive should not have the same implementation

  • VUE_IDENTICAL_BRANCHES_IN_TEMPLATE
  • Code Quality
  • Medium
  • cwe, vue

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

Noncompliant Code Example

View with compliant examples side by side
<template>  <div v-if="cond">    Hi there!  </div>  <div v-else>    Hi there!  </div></template>

Compliant Code Example

View with noncompliant examples side by side
<template>  <div v-if="cond">    Hi there!  </div>  <div v-else>    Goodbye!  </div></template>

Version

This rule was introduced in DeepScan 1.40.0.

See

Was this documentation helpful?

Last updated on April 29, 2025

[8]ページ先頭

©2009-2025 Movatter.jp