Skip to content

Commit 66f64c9

Browse files
committed
attribute-hyphenation: Work correctly when ignore has != 1 item
Currently, the "ignore" options array only works correctly with exactly 1 item. Adjust it to work with 0 and with >1 items.
1 parent 2b6a475 commit 66f64c9

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/rules/attribute-hyphenation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ module.exports = {
4949
const option = context.options[0]
5050
const optionsPayload = context.options[1]
5151
const useHyphenated = option !== 'never'
52-
const ignoredAttributes = ['data-', 'aria-', 'slot-scope']
52+
let ignoredAttributes = ['data-', 'aria-', 'slot-scope']
5353

5454
if (optionsPayload && optionsPayload.ignore) {
55-
ignoredAttributes.push(optionsPayload.ignore)
55+
ignoredAttributes = ignoredAttributes.concat(optionsPayload.ignore)
5656
}
5757

5858
const caseConverter = casing.getConverter(useHyphenated ? 'kebab-case' : 'camelCase')

tests/lib/rules/attribute-hyphenation.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ ruleTester.run('attribute-hyphenation', rule, {
4545
},
4646
{
4747
filename: 'test.vue',
48-
code: '<template><custom data-id="foo" aria-test="bar" slot-scope="{ data }" custom-hypen="foo"><a onClick="" my-prop="prop"></a></custom></template>',
49-
options: ['never', { 'ignore': ['custom-hypen'] }]
48+
code: '<template><custom data-id="foo" aria-test="bar" slot-scope="{ data }" custom-hypen="foo" second-custom="bar"><a onClick="" my-prop="prop"></a></custom></template>',
49+
options: ['never', { 'ignore': ['custom-hypen', 'second-custom'] }]
5050
}
5151
],
5252

@@ -117,6 +117,28 @@ ruleTester.run('attribute-hyphenation', rule, {
117117
line: 1
118118
}]
119119
},
120+
{
121+
filename: 'test.vue',
122+
code: '<template><div><custom v-bind:MyProp="prop"></custom></div></template>',
123+
output: '<template><div><custom v-bind:my-prop="prop"></custom></div></template>',
124+
options: ['always', { 'ignore': [] }],
125+
errors: [{
126+
message: "Attribute 'v-bind:MyProp' must be hyphenated.",
127+
type: 'VDirectiveKey',
128+
line: 1
129+
}]
130+
},
131+
{
132+
filename: 'test.vue',
133+
code: '<template><custom data-id="foo" aria-test="bar" slot-scope="{ data }" custom-hypen="foo" third-custom="bar"><a onClick="" my-prop="prop"></a></custom></template>',
134+
output: '<template><custom data-id="foo" aria-test="bar" slot-scope="{ data }" custom-hypen="foo" thirdCustom="bar"><a onClick="" my-prop="prop"></a></custom></template>',
135+
options: ['never', { 'ignore': ['custom-hypen', 'second-custom'] }],
136+
errors: [{
137+
message: "Attribute 'third-custom' cann't be hyphenated.",
138+
type: 'VDirectiveKey',
139+
line: 1
140+
}]
141+
},
120142
{
121143
// This is the same code as the `'ignore': ['custom-hypen']`
122144
// valid test; to verify that setting ignore actually makes the

0 commit comments

Comments
 (0)