Branches of v-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 having v-if or v-else-if directive is identical to the v-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

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?