-
-
Notifications
You must be signed in to change notification settings - Fork 696
Description
Hello I was looking for a rule to make sure I don't add duplicated class names in my code but I couldn't find any so I created a custom rule for my project but would be nice to have support for it in this plugin.
Please describe what the rule should do:
This rule can be used to void duplication of class names inside class attributes.
What category should the rule belong to?
- Enforces code style (layout)
- Warns about a potential error (problem)
- Suggests an alternate way of doing something (suggestion)
- Other (please specify:)
Provide 2-3 code examples that this rule should warn about:
<template>
<!-- ✓ GOOD -->
<div class="foo"></div>
<!-- ✗ BAD -->
<div class="foo foo"></div>
</template>
<template>
<!-- ✓ GOOD -->
<div :class="{ 'foo': true }"></div>
<!-- ✗ BAD -->
<div :class="{ 'foo foo': true }"></div>
</template>
<template>
<!-- ✓ GOOD -->
<div :class="['foo']"></div>
<!-- ✗ BAD -->
<div :class="['foo foo']"></div>
</template>
I'd say this rule should check duplicates within each class attribute separately so it should not report cases where a class appears once in class=""
and once in :class=""
<template>
<!-- ✓ GOOD -->
<div class="foo" :class="'foo'"></div>
</template>
And also should not report duplicates withing each object key/array items or mixed inside :class=""
<template>
<!-- ✓ GOOD -->
<div :class="{ 'foo': true, 'foo bar': true }"></div>
</template>
<template>
<!-- ✓ GOOD -->
<div :class="['foo', 'foo bar']"></div>
</template>
<template>
<!-- ✓ GOOD -->
<div :class="['foo', { 'foo bar': true }]"></div>
</template>
I can help with the PR, tests and documentation as needed :)