Skip to content

Commit 8325289

Browse files
committed
update no-duplicate-attributes
1 parent 68bdf10 commit 8325289

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed

docs/rules/no-duplicate-attributes.md

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,53 @@ It's possibly mistakes.
1010
This rule reports duplicate attributes.
1111
`v-bind:foo` directives are handled as the attributes `foo`.
1212

13-
:-1: Examples of **incorrect** code for this rule:
14-
15-
```html
16-
<MyComponent
17-
:foo="def"
18-
foo="abc"
19-
/>
13+
<eslint-code-block :rules="{'vue/no-duplicate-attributes': ['error']}">
2014
```
21-
22-
:+1: Examples of **correct** code for this rule:
23-
24-
```html
25-
<MyComponent :foo="abc"/>
26-
```
27-
28-
```html
29-
<MyComponent foo="abc"/>
15+
<template>
16+
<!-- ✓ GOOD -->
17+
<MyComponent :foo="abc" />
18+
<MyComponent foo="abc" />
19+
<MyComponent class="abc" :class="def" />
20+
21+
<!-- ✗ BAD -->
22+
<MyComponent :foo="abc" foo="def" />
23+
<MyComponent foo="abc" :foo="def" />
24+
<MyComponent foo="abc" foo="def" />
25+
<MyComponent :foo.a="abc" :foo.b="def" />
26+
<MyComponent class="abc" class="def" />
27+
</template>
3028
```
29+
</eslint-code-block>
3130

3231
## :wrench: Options
3332

34-
`allowCoexistClass` - Enables [`v-bind:class`] directive can coexist with the plain `class` attribute.
35-
`allowCoexistStyle` - Enables [`v-bind:style`] directive can coexist with the plain `style` attribute.
36-
37-
```
38-
'vue/no-duplicate-attributes': [2, {
39-
allowCoexistClass: Boolean // default: true
40-
allowCoexistStyle: Boolean, // default: true
41-
}]
33+
```json
34+
{
35+
"vue/no-duplicate-attributes": ["error", {
36+
"allowCoexistClass": true,
37+
"allowCoexistStyle": true
38+
}]
39+
}
4240
```
4341

44-
## TODO: `<div foo foo></div>`
45-
46-
`parse5` remove duplicate attributes on the tokenization phase.
47-
Needs investigation to check.
48-
42+
- `allowCoexistClass` (`boolean`) ... Enables [`v-bind:class`] directive can coexist with the plain `class` attribute. Default is `true`.
43+
- `allowCoexistStyle` (`boolean`) ... Enables [`v-bind:style`] directive can coexist with the plain `style` attribute. Default is `true`.
4944

5045
[`v-bind:class`]: https://vuejs.org/v2/guide/class-and-style.html
5146
[`v-bind:style`]: https://vuejs.org/v2/guide/class-and-style.html
5247

48+
### `{ "allowCoexistClass": false, "allowCoexistStyle": false }`
49+
50+
<eslint-code-block :rules="{'vue/no-duplicate-attributes': ['error', {allowCoexistClass: false, allowCoexistStyle: false}]}">
51+
```
52+
<template>
53+
<!-- ✗ BAD -->
54+
<MyComponent class="abc" :class="def" />
55+
<MyComponent style="abc" :style="def" />
56+
</template>
57+
```
58+
</eslint-code-block>
59+
5360
## :mag: Implementation
5461

5562
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-duplicate-attributes.js)

0 commit comments

Comments
 (0)