diff --git a/lib/rules/attribute-hyphenation.js b/lib/rules/attribute-hyphenation.js
index d2ae0ccac..24bacffc2 100644
--- a/lib/rules/attribute-hyphenation.js
+++ b/lib/rules/attribute-hyphenation.js
@@ -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))
+ )
+ }
})
}
diff --git a/tests/lib/rules/attribute-hyphenation.js b/tests/lib/rules/attribute-hyphenation.js
index 002254dd0..146c25658 100644
--- a/tests/lib/rules/attribute-hyphenation.js
+++ b/tests/lib/rules/attribute-hyphenation.js
@@ -58,6 +58,16 @@ ruleTester.run('attribute-hyphenation', rule, {
filename: 'test.vue',
code: '
',
options: ['never']
+ },
+ {
+ filename: 'test.vue',
+ code: '
',
+ options: ['always']
+ },
+ {
+ filename: 'test.vue',
+ code: '
',
+ options: ['never']
}
],
@@ -280,6 +290,84 @@ ruleTester.run('attribute-hyphenation', rule, {
line: 1
}
]
+ },
+ {
+ filename: 'test.vue',
+ code: '
',
+ output: null,
+ options: ['always'],
+ errors: [
+ {
+ message: "Attribute ':attr_Gg' must be hyphenated.",
+ type: 'VDirectiveKey',
+ line: 1
+ }
+ ]
+ },
+ {
+ filename: 'test.vue',
+ code: '
',
+ output: null,
+ options: ['always'],
+ errors: [
+ {
+ message: "Attribute ':Attr_Hh' must be hyphenated.",
+ type: 'VDirectiveKey',
+ line: 1
+ }
+ ]
+ },
+ {
+ filename: 'test.vue',
+ code: '
',
+ output: null,
+ options: ['always'],
+ errors: [
+ {
+ message: "Attribute ':_attr_Jj' must be hyphenated.",
+ type: 'VDirectiveKey',
+ line: 1
+ }
+ ]
+ },
+ {
+ filename: 'test.vue',
+ code: '
',
+ output: null,
+ options: ['always'],
+ errors: [
+ {
+ message: "Attribute ':_attrKk' must be hyphenated.",
+ type: 'VDirectiveKey',
+ line: 1
+ }
+ ]
+ },
+ {
+ filename: 'test.vue',
+ code: '
',
+ output: null,
+ options: ['always'],
+ errors: [
+ {
+ message: "Attribute ':_AttrLl' must be hyphenated.",
+ type: 'VDirectiveKey',
+ line: 1
+ }
+ ]
+ },
+ {
+ filename: 'test.vue',
+ code: '
',
+ output: null,
+ options: ['never'],
+ errors: [
+ {
+ message: "Attribute ':my-custom_prop' can't be hyphenated.",
+ type: 'VDirectiveKey',
+ line: 1
+ }
+ ]
}
]
})