Skip to content

Commit 8027916

Browse files
LukeShumichalsnik
authored andcommitted
Fix attribute-hyphenation ignore lists (#513)
* tests: attribute-hyphenation: Fix the ignore-list test The test introduced in f9e1eee didn't actually test what it meant to test for. It attempts to verify that the ignore list is obeyed; but its subject is an element that is ignored in its entirety! The code under test was never triggered! Fix this by changing <div> for <custom> in the test case, and also add the same test-case without the `ignore` config, in order to verify that it actually has something to ignore. * 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. * attribute-hyphenation: Fix spelling mistakes - hypen -> hyphen - cann't -> can't * Update test suite for attribute-hyphenation
1 parent bd5c31e commit 8027916

File tree

2 files changed

+91
-8
lines changed

2 files changed

+91
-8
lines changed

lib/rules/attribute-hyphenation.js

Lines changed: 3 additions & 3 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')
@@ -63,7 +63,7 @@ module.exports = {
6363
context.report({
6464
node: node.key,
6565
loc: node.loc,
66-
message: useHyphenated ? "Attribute '{{text}}' must be hyphenated." : "Attribute '{{text}}' cann't be hyphenated.",
66+
message: useHyphenated ? "Attribute '{{text}}' must be hyphenated." : "Attribute '{{text}}' can't be hyphenated.",
6767
data: {
6868
text
6969
},

tests/lib/rules/attribute-hyphenation.js

Lines changed: 88 additions & 5 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><div data-id="foo" aria-test="bar" slot-scope="{ data }" custom-hypen="foo"><a onClick="" my-prop="prop"></a></div></template>',
49-
options: ['never', { 'ignore': ['custom-hypen'] }]
48+
code: '<template><custom data-id="foo" aria-test="bar" slot-scope="{ data }" custom-hyphen="foo" second-custom="bar"><a onClick="" my-prop="prop"></a></custom></template>',
49+
options: ['never', { 'ignore': ['custom-hyphen', 'second-custom'] }]
5050
}
5151
],
5252

@@ -57,7 +57,7 @@ ruleTester.run('attribute-hyphenation', rule, {
5757
output: '<template><div><custom myProp="foo"></custom></div></template>',
5858
options: ['never'],
5959
errors: [{
60-
message: "Attribute 'my-prop' cann't be hyphenated.",
60+
message: "Attribute 'my-prop' can't be hyphenated.",
6161
type: 'VIdentifier',
6262
line: 1
6363
}]
@@ -79,7 +79,7 @@ ruleTester.run('attribute-hyphenation', rule, {
7979
output: '<template><div><custom :myProp="prop"></custom></div></template>',
8080
options: ['never'],
8181
errors: [{
82-
message: "Attribute ':my-prop' cann't be hyphenated.",
82+
message: "Attribute ':my-prop' can't be hyphenated.",
8383
type: 'VDirectiveKey',
8484
line: 1
8585
}]
@@ -101,7 +101,7 @@ ruleTester.run('attribute-hyphenation', rule, {
101101
output: '<template><div><custom v-bind:myProp="prop"></custom></div></template>',
102102
options: ['never'],
103103
errors: [{
104-
message: "Attribute 'v-bind:my-prop' cann't be hyphenated.",
104+
message: "Attribute 'v-bind:my-prop' can't be hyphenated.",
105105
type: 'VDirectiveKey',
106106
line: 1
107107
}]
@@ -116,6 +116,89 @@ ruleTester.run('attribute-hyphenation', rule, {
116116
type: 'VDirectiveKey',
117117
line: 1
118118
}]
119+
},
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><div><custom v-bind:my-prop="prop" :second-prop="test"></custom></div></template>',
134+
output: '<template><div><custom v-bind:my-prop="prop" :secondProp="test"></custom></div></template>',
135+
options: ['never', { ignore: ['my-prop'] }],
136+
errors: [{
137+
message: "Attribute ':second-prop' can't be hyphenated.",
138+
type: 'VDirectiveKey',
139+
line: 1
140+
}]
141+
},
142+
{
143+
filename: 'test.vue',
144+
code: '<template><div><custom v-bind:myProp="prop" :secondProp="test"></custom></div></template>',
145+
output: '<template><div><custom v-bind:my-prop="prop" :secondProp="test"></custom></div></template>',
146+
options: ['always', { ignore: ['secondProp'] }],
147+
errors: [{
148+
message: "Attribute 'v-bind:myProp' must be hyphenated.",
149+
type: 'VDirectiveKey',
150+
line: 1
151+
}]
152+
},
153+
{
154+
filename: 'test.vue',
155+
code: `
156+
<template>
157+
<custom data-id="foo" aria-test="bar" slot-scope="{ data }" custom-hyphen="foo" second-custom="baz" third-custom="bar">
158+
<a onClick="" my-prop="prop"></a>
159+
</custom>
160+
</template>
161+
`,
162+
output: `
163+
<template>
164+
<custom data-id="foo" aria-test="bar" slot-scope="{ data }" custom-hyphen="foo" second-custom="baz" thirdCustom="bar">
165+
<a onClick="" my-prop="prop"></a>
166+
</custom>
167+
</template>
168+
`,
169+
options: ['never', { 'ignore': ['custom-hyphen', 'second-custom'] }],
170+
errors: [{
171+
message: "Attribute 'third-custom' can't be hyphenated.",
172+
type: 'VIdentifier',
173+
line: 3
174+
}]
175+
},
176+
{
177+
filename: 'test.vue',
178+
code: `
179+
<template>
180+
<custom data-id="foo" aria-test="bar" slot-scope="{ data }" custom-hyphen="foo" second-custom="baz" thirdCustom="bar">
181+
<a onClick="" my-prop="prop"></a>
182+
</custom>
183+
</template>
184+
`,
185+
output: `
186+
<template>
187+
<custom data-id="foo" aria-test="bar" slot-scope="{ data }" customHyphen="foo" secondCustom="baz" thirdCustom="bar">
188+
<a onClick="" my-prop="prop"></a>
189+
</custom>
190+
</template>
191+
`,
192+
options: ['never'],
193+
errors: [{
194+
message: "Attribute 'custom-hyphen' can't be hyphenated.",
195+
type: 'VIdentifier',
196+
line: 3
197+
}, {
198+
message: "Attribute 'second-custom' can't be hyphenated.",
199+
type: 'VIdentifier',
200+
line: 3
201+
}]
119202
}
120203
]
121204
})

0 commit comments

Comments
 (0)