Skip to content

Commit ec0276b

Browse files
authored
Disable autofix in vue/attribute-hyphenation for attributes with underscore (#2045)
1 parent ced6fc3 commit ec0276b

File tree

2 files changed

+98
-2
lines changed

2 files changed

+98
-2
lines changed

lib/rules/attribute-hyphenation.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,16 @@ module.exports = {
9494
data: {
9595
text
9696
},
97-
fix: (fixer) =>
98-
fixer.replaceText(node.key, text.replace(name, caseConverter(name)))
97+
fix: (fixer) => {
98+
if (text.includes('_')) {
99+
return null
100+
}
101+
102+
return fixer.replaceText(
103+
node.key,
104+
text.replace(name, caseConverter(name))
105+
)
106+
}
99107
})
100108
}
101109

tests/lib/rules/attribute-hyphenation.js

+88
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ ruleTester.run('attribute-hyphenation', rule, {
5858
filename: 'test.vue',
5959
code: '<template><div><slot myProp></slot></div></template>',
6060
options: ['never']
61+
},
62+
{
63+
filename: 'test.vue',
64+
code: '<template><div><custom :attr_ff="prop"></custom></div></template>',
65+
options: ['always']
66+
},
67+
{
68+
filename: 'test.vue',
69+
code: '<template><div><custom :attr_ff="prop"></custom></div></template>',
70+
options: ['never']
6171
}
6272
],
6373

@@ -280,6 +290,84 @@ ruleTester.run('attribute-hyphenation', rule, {
280290
line: 1
281291
}
282292
]
293+
},
294+
{
295+
filename: 'test.vue',
296+
code: '<template><div><custom :attr_Gg="prop"></custom></div></template>',
297+
output: null,
298+
options: ['always'],
299+
errors: [
300+
{
301+
message: "Attribute ':attr_Gg' must be hyphenated.",
302+
type: 'VDirectiveKey',
303+
line: 1
304+
}
305+
]
306+
},
307+
{
308+
filename: 'test.vue',
309+
code: '<template><div><custom :Attr_Hh="prop"></custom></div></template>',
310+
output: null,
311+
options: ['always'],
312+
errors: [
313+
{
314+
message: "Attribute ':Attr_Hh' must be hyphenated.",
315+
type: 'VDirectiveKey',
316+
line: 1
317+
}
318+
]
319+
},
320+
{
321+
filename: 'test.vue',
322+
code: '<template><div><custom :_attr_Jj="prop"></custom></div></template>',
323+
output: null,
324+
options: ['always'],
325+
errors: [
326+
{
327+
message: "Attribute ':_attr_Jj' must be hyphenated.",
328+
type: 'VDirectiveKey',
329+
line: 1
330+
}
331+
]
332+
},
333+
{
334+
filename: 'test.vue',
335+
code: '<template><div><custom :_attrKk="prop"></custom></div></template>',
336+
output: null,
337+
options: ['always'],
338+
errors: [
339+
{
340+
message: "Attribute ':_attrKk' must be hyphenated.",
341+
type: 'VDirectiveKey',
342+
line: 1
343+
}
344+
]
345+
},
346+
{
347+
filename: 'test.vue',
348+
code: '<template><div><custom :_AttrLl="prop"></custom></div></template>',
349+
output: null,
350+
options: ['always'],
351+
errors: [
352+
{
353+
message: "Attribute ':_AttrLl' must be hyphenated.",
354+
type: 'VDirectiveKey',
355+
line: 1
356+
}
357+
]
358+
},
359+
{
360+
filename: 'test.vue',
361+
code: '<template><div><custom :my-custom_prop="prop"></custom></div></template>',
362+
output: null,
363+
options: ['never'],
364+
errors: [
365+
{
366+
message: "Attribute ':my-custom_prop' can't be hyphenated.",
367+
type: 'VDirectiveKey',
368+
line: 1
369+
}
370+
]
283371
}
284372
]
285373
})

0 commit comments

Comments
 (0)