-
-
Notifications
You must be signed in to change notification settings - Fork 700
feat: add vue/no-duplicate-class-names rule
#2934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
e02efe9
feat: add `no-duplicate-class-names` rule
Yizack f162493
docs: add rule details
Yizack 0fd19ef
docs: add changeset
Yizack 2071c01
feat: report conditional expression
Yizack 99139ad
refactor: no need for a 2nd loop
Yizack ba9bd9b
feat: support `TemplateLiteral` + improve report
Yizack 535b73a
chore: simplify node param
Yizack 1b04b2a
feat: support `BinaryExpression` + preserve spaces
Yizack f0c52c0
refactor: rename functions and improve code
Yizack 7b641c0
fix: report cross attribute duplicates
Yizack a375602
test: add more invalid test cases
Yizack 93e9271
Merge remote-tracking branch 'upstream/master'
Yizack 47b5065
test: rename cross-attribute tests + add literal test
Yizack c7dcaca
fix: find duplicates within unconditional expression nodes + add comm…
Yizack b30dbed
Merge remote-tracking branch 'upstream/master'
Yizack d97f4d9
fix: mixed cross node case
Yizack a46ec4d
docs: add on more bad and use isActive
Yizack 8e78e75
fix: improve error message
Yizack a569c82
refactor: refactor variable name
Yizack 142bd0b
docs: pick a more common example for the last "good" example
Yizack 9fec4c9
test: add `line`, `column`, `endLine` and `endColumn`
Yizack 2709da8
Merge remote-tracking branch 'upstream/master'
Yizack fde5af0
test: adjust error message message
Yizack 7cdcd5d
fix: handle `LogicalExpression`
Yizack 4bb29a1
test: fix duplicate-class-logical-expression-in-conditional
Yizack d98ca00
test: test actual logical expression duplicate in array
Yizack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'eslint-plugin-vue': minor | ||
| --- | ||
|
|
||
| Added new [`vue/no-duplicate-class-names`](https://eslint.vuejs.org/rules/no-duplicate-class-names.html) rule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| --- | ||
| pageClass: rule-details | ||
| sidebarDepth: 0 | ||
| title: vue/no-duplicate-class-names | ||
| description: disallow duplication of class names in class attributes | ||
| --- | ||
|
|
||
| # vue/no-duplicate-class-names | ||
|
|
||
| > disallow duplication of class names in class attributes | ||
|
|
||
| - :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> _**This rule has not been released yet.**_ </badge> | ||
| - :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fix-problems) can automatically fix some of the problems reported by this rule. | ||
|
|
||
| ## :book: Rule Details | ||
|
|
||
| This rule prevents the same class name from appearing multiple times within the same class attribute or directive. | ||
|
|
||
| <eslint-code-block fix :rules="{'vue/no-duplicate-class-names': ['error']}"> | ||
|
|
||
| ```vue | ||
| <template> | ||
| <!-- ✓ GOOD --> | ||
| <div class="foo bar"></div> | ||
| <div :class="'foo bar'"></div> | ||
| <div :class="{ 'foo bar': isActive }"></div> | ||
| <div :class="['foo', 'bar']"></div> | ||
| <div :class="isActive ? 'foo' : 'bar'"></div> | ||
| <div :class="'foo ' + 'bar'"></div> | ||
|
|
||
| <!-- ✗ BAD --> | ||
| <div class="foo foo"></div> | ||
| <div class="foo bar foo baz bar"></div> | ||
| <div :class="'foo foo'"></div> | ||
| <div :class="`foo foo`"></div> | ||
| <div :class="{ 'foo foo': isActive }"></div> | ||
| <div :class="['foo foo']"></div> | ||
| <div :class="['foo foo', { 'bar bar baz': isActive }]"></div> | ||
| <div :class="isActive ? 'foo foo' : 'bar'"></div> | ||
| <div :class="'foo foo ' + 'bar'"></div> | ||
| <div class="foo" :class="'foo'"></div> | ||
| <div :class="['foo', 'foo']"></div> | ||
| <div :class="'foo ' + 'foo'"></div> | ||
| <div :class="['foo', { 'foo': isActive }]"></div> | ||
| </template> | ||
| ``` | ||
|
|
||
| </eslint-code-block> | ||
|
|
||
| ## :wrench: Options | ||
|
|
||
| Nothing. | ||
|
|
||
| ## :mag: Implementation | ||
|
|
||
| - [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-duplicate-class-names.js) | ||
| - [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-duplicate-class-names.js) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.