vue/no-negated-v-if-condition
Disallow a negated v-if condition when the chain has a v-else
Default severity: warning
Presets: nuxt, opinionated
Automatic fix: None; review the suggested change
Applies to: Vue SFC templates and blocks, with script context where the rule requires it
Options: No rule-specific options. Severity and preset selection are configurable.
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({
lint: {
vize: {
"preset": "incremental",
"rules": {
"vue/no-negated-v-if-condition": "warn"
}
},
},
});
vp run lint
Bad
The paired v-if and v-else branches begin with a negated condition.
<template>
<div v-if="!ok">A</div>
<div v-else>B</div>
</template>
Good
A positive ok condition comes first; when inverting a condition, place the original opposite branch first. A lone negated v-if and !== comparisons remain allowed.
<template>
<div v-if="ok">B</div>
<div v-else>A</div>
<div v-if="!ok">A</div>
<div v-if="a !== b">A</div>
<div v-else>B</div>
</template>
Good avoids this rule's finding under the configuration above; other rules may still report diagnostics.