8000 cleaner code and do not overwrite default ignore list · MechJosh0/eslint-plugin-vue@3505bbf · GitHub
[go: up one dir, main page]

Skip to content

Commit 3505bbf

Browse files
committed
cleaner code and do not overwrite default ignore list
1 parent 639f503 commit 3505bbf

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

docs/rules/attribute-hyphenation.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Default casing is set to `always` with `['data-', 'aria-', 'slot-scope']` set to be ignored
99

1010
```
11-
'vue/attribute-hyphenation': [2, 'always'|'never', { 'ignore': ['data-', 'aria-', 'slot-scope'] }]
11+
'vue/attribute-hyphenation': [2, 'always'|'never', { 'ignore': ['custom-prop'] }]
1212
```
1313

1414
### `[2, "always"]` - Use hyphenated name. (It errors on upper case letters.)
@@ -39,16 +39,16 @@ Default casing is set to `always` with `['data-', 'aria-', 'slot-scope']` set to
3939
<MyComponent my-prop="prop"/>
4040
```
4141

42-
### `[2, "never", { 'ignore': ['data-', 'aria-', 'slot-scope', 'custom-prop'] }]` - Don't use hyphenated name but allow custom attributes
42+
### `[2, "never", { 'ignore': ['custom-prop'] }]` - Don't use hyphenated name but allow custom attributes
4343

4444
:+1: Examples of **correct** code`:
4545

4646
```html
47-
<MyComponent myProp="prop" custom-prop="foo"/>
47+
<MyComponent myProp="prop" custom-prop="foo" data-id="1"/>
4848
```
4949

5050
:-1: Examples of **incorrect** code`:
5151

5252
```html
53-
<MyComponent my-prop="prop" custom-prop="foo"/>
53+
<MyComponent my-prop="prop" custom-prop="foo" data-id="1"/>
5454
```

lib/rules/attribute-hyphenation.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const casing = require('../utils/casing')
1414
module.exports = {
1515
meta: {
1616
docs: {
17-
description: 'enforce attribute naming style in template',
17+
description: 'enforce attribute naming style on custom components in template',
1818
category: 'strongly-recommended',
1919
url: 'https://github.com/vuejs/eslint-plugin-vue/blob/v4.4.0/docs/rules/attribute-hyphenation.md'
2020
},
@@ -49,12 +49,10 @@ module.exports = {
4949
const option = context.options[0]
5050
const optionsPayload = context.options[1]
5151
const useHyphenated = option !== 'never'
52-
let ignoredAttributes = []
52+
const ignoredAttributes = ['data-', 'aria-', 'slot-scope']
5353

5454
if (optionsPayload && optionsPayload.ignore) {
55-
ignoredAttributes = optionsPayload.ignore
56-
} else {
57-
ignoredAttributes = ['data-', 'aria-', 'slot-scope']
55+
ignoredAttributes.push(optionsPayload.ignore)
5856
}
5957

6058
const caseConverter = casing.getConverter(useHyphenated ? 'kebab-case' : 'camelCase')
@@ -74,8 +72,8 @@ module.exports = {
7472
}
7573

7674
function isIgnoredAttribute (value) {
77-
const isIgnored = !ignoredAttributes.every(function (attr) {
78-
return value.indexOf(attr) === -1
75+
const isIgnored = ignoredAttributes.some(function (attr) {
76+
return value.indexOf(attr) !== -1
7977
})
8078

8179
if (isIgnored) {

0 commit comments

Comments
 (0)
0