Skip to content

no-negated-v-if-condition: fix suggestion do not swap component names and attributes #2939

@andreww2012

Description

@andreww2012

Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have read the FAQ and my problem is not listed.

Tell us about your environment

  • ESLint version: 9.37.0
  • eslint-plugin-vue version: 10.5.0
  • Vue version: N/A
  • Node version: 20.19.2
  • Operating System: N/A

Please show your full configuration:

import eslintPluginVue from 'eslint-plugin-vue';
import { defineConfig } from 'eslint/config';
import vueEslintParser from 'vue-eslint-parser';

export default defineConfig([
  {
    files: ['*.vue'],
    plugins: {
      vue: eslintPluginVue,
    },
    languageOptions: {
      parser: vueEslintParser,
    },
    rules: {
      'vue/no-negated-v-if-condition': 2,
    },
  },
]);

What did you do?

Fix suggestions of no-negated-v-if-condition do not swap component names and their attributes:

<div v-if="!condition" div-attr="foo" div-attr-2>div contents</div>
<span v-else span-attr="baz" span-attr2>span contents</span>

What did you expect to happen?

Should be fixed to

<span v-if="condition" span-attr="baz" span-attr2>span contents</span>
<div v-else div-attr="foo" div-attr-2>div contents</div>

What actually happened?

It gets fixed to

<div v-if="condition" div-attr="foo" div-attr-2>span contents</div>
<span v-else span-attr="baz" span-attr2>div contents</span>

Repository to reproduce this issue

https://github.com/andreww2012/eslint-plugin-vue-no-negated-v-if-condition-bad-suggestion

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions