Skip to content

Commit 1786dde

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 1786dde

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Diff for: lib/rules/attribute-hyphenation.js

+2-2
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')

Diff for: tests/lib/rules/attribute-hyphenation.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ruleTester.run('attribute-hyphenation', rule, {
4646
{
4747
filename: 'test.vue',
4848
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'] }]
49+
options: ['never', { 'ignore': ['custom-hypen', 'second-custom'] }]
5050
}
5151
],
5252

@@ -117,6 +117,17 @@ 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+
},
120131
{
121132
// This is the same code as the `'ignore': ['custom-hypen']`
122133
// valid test; to verify that setting ignore actually makes the

0 commit comments

Comments
 (0)