Skip to content

Commit

Permalink
Disable autofix in vue/attribute-hyphenation for attributes with un…
Browse files Browse the repository at this point in the history
…derscore (#2045)
  • Loading branch information
kurageso committed Nov 23, 2022
1 parent ced6fc3 commit ec0276b
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/rules/attribute-hyphenation.js
Expand Up @@ -94,8 +94,16 @@ module.exports = {
data: {
text
},
fix: (fixer) =>
fixer.replaceText(node.key, text.replace(name, caseConverter(name)))
fix: (fixer) => {
if (text.includes('_')) {
return null
}

return fixer.replaceText(
node.key,
text.replace(name, caseConverter(name))
)
}
})
}

Expand Down
88 changes: 88 additions & 0 deletions tests/lib/rules/attribute-hyphenation.js
Expand Up @@ -58,6 +58,16 @@ ruleTester.run('attribute-hyphenation', rule, {
filename: 'test.vue',
code: '<template><div><slot myProp></slot></div></template>',
options: ['never']
},
{
filename: 'test.vue',
code: '<template><div><custom :attr_ff="prop"></custom></div></template>',
options: ['always']
},
{
filename: 'test.vue',
code: '<template><div><custom :attr_ff="prop"></custom></div></template>',
options: ['never']
}
],

Expand Down Expand Up @@ -280,6 +290,84 @@ ruleTester.run('attribute-hyphenation', rule, {
line: 1
}
]
},
{
filename: 'test.vue',
code: '<template><div><custom :attr_Gg="prop"></custom></div></template>',
output: null,
options: ['always'],
errors: [
{
message: "Attribute ':attr_Gg' must be hyphenated.",
type: 'VDirectiveKey',
line: 1
}
]
},
{
filename: 'test.vue',
code: '<template><div><custom :Attr_Hh="prop"></custom></div></template>',
output: null,
options: ['always'],
errors: [
{
message: "Attribute ':Attr_Hh' must be hyphenated.",
type: 'VDirectiveKey',
line: 1
}
]
},
{
filename: 'test.vue',
code: '<template><div><custom :_attr_Jj="prop"></custom></div></template>',
output: null,
options: ['always'],
errors: [
{
message: "Attribute ':_attr_Jj' must be hyphenated.",
type: 'VDirectiveKey',
line: 1
}
]
},
{
filename: 'test.vue',
code: '<template><div><custom :_attrKk="prop"></custom></div></template>',
output: null,
options: ['always'],
errors: [
{
message: "Attribute ':_attrKk' must be hyphenated.",
type: 'VDirectiveKey',
line: 1
}
]
},
{
filename: 'test.vue',
code: '<template><div><custom :_AttrLl="prop"></custom></div></template>',
output: null,
options: ['always'],
errors: [
{
message: "Attribute ':_AttrLl' must be hyphenated.",
type: 'VDirectiveKey',
line: 1
}
]
},
{
filename: 'test.vue',
code: '<template><div><custom :my-custom_prop="prop"></custom></div></template>',
output: null,
options: ['never'],
errors: [
{
message: "Attribute ':my-custom_prop' can't be hyphenated.",
type: 'VDirectiveKey',
line: 1
}
]
}
]
})

0 comments on commit ec0276b

Please sign in to comment.