Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable autofix in vue/attribute-hyphenation for attributes with underscore #2045

Merged
merged 7 commits into from Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 (useHyphenated && text.includes('_')) {
FloEdelmann marked this conversation as resolved.
Show resolved Hide resolved
return null
}

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

Expand Down
70 changes: 70 additions & 0 deletions tests/lib/rules/attribute-hyphenation.js
Expand Up @@ -58,6 +58,11 @@ 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']
}
],

Expand Down Expand Up @@ -280,6 +285,71 @@ 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
}
]
}
]
})