Skip to content

no-duplicate-class-names: reports on the same class names applied under non-intersecting conditions #2974

@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.31.1
  • eslint-plugin-vue version: 10.6.1
  • Vue version:
  • Node version:
  • Operating System:

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-duplicate-class-names': 2,
    },
  },
]);

What did you do?

Sometimes it's desirable to include the same class name multiple times, while also avoiding the situation when the class appears more than once in runtime.

Here's an example from the real component when this happens and no-duplicate-class-names reports on the second bg-secondary class appearance:

<template>
  <div
    :class="[
      (type === 'primary' || type === 'secondary') && {
        'bg-white': background === 'primary',
        'bg-secondary': background === 'secondary',
      },
      type === 'tertiary' && 'bg-secondary px-3 py-2',
    ]"
  ></div>
</template>

What did you expect to happen?

I think no-duplicate-class-names checks should be improved. Yet I understand that precise checking of whether class appearance conditions are intersecting might be difficult.

What actually happened?

bg-secondary class was reported as duplicate by the rule in question.

Repository to reproduce this issue

https://ota-meshi.github.io/eslint-plugin-vue-demo/#eJxlUEEOgjAQ/MpkD6KJDYneCPgR8VDbjTZCaUpRCfJ3QaNIPO3uzM5kMh2pSjMllAYuXSED73ILpNpcxwkkqpB1neW0f9/AMrSOkWUZIudNKX0b4fHAhNasKqtHfIXFAt1HCETHk7idTeAowVGqy8lXjdVzr/X8fTL7l0zcV9R/tylPYB/MK+aQZuYJdxdbuFZsPg6HnMZll8ZDA0MVafzTC63JNwXXlHR0bTi2ldCNK4waaPHqSVhZjvym758owGsD

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions