Skip to content

Commit 6178486

Browse files
committed
Add ignore for data- property
1 parent a4be85d commit 6178486

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

lib/rules/html-attributes-casing.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,24 @@ function create (context) {
3838
'VStartTag' (obj) {
3939
if (!utils.isSvgElementName(obj.id.name) && !utils.isMathMLElementName(obj.id.name)) {
4040
obj.attributes.forEach((node) => {
41-
if (node.directive && node.key.name === 'bind') {
42-
const text = sourceCode.getText(node.key)
43-
const oldValue = node.key.argument
41+
if (!node.directive) {
42+
const oldValue = node.key.name
43+
if (oldValue.indexOf('data-') !== -1) {
44+
return
45+
}
4446
const value = casing.getConverter(caseType)(oldValue)
4547
if (value !== oldValue) {
46-
reportIssue(node, text, text.replace(oldValue, value))
48+
reportIssue(node, oldValue, value)
4749
}
48-
} else if (!node.directive) {
49-
const oldValue = node.key.name
50+
} else if (node.key.name === 'bind') {
51+
const oldValue = node.key.argument
52+
if (oldValue.indexOf('data-') !== -1) {
53+
return
54+
}
55+
const text = sourceCode.getText(node.key)
5056
const value = casing.getConverter(caseType)(oldValue)
5157
if (value !== oldValue) {
52-
reportIssue(node, oldValue, value)
58+
reportIssue(node, text, text.replace(oldValue, value))
5359
}
5460
}
5561
})

tests/lib/rules/html-attributes-casing.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ ruleTester.run('html-attributes-casing', rule, {
6262
filename: 'test.vue',
6363
code: '<template><div><svg foo-bar="prop"></svg></div></template>',
6464
options: ['PascalCase']
65+
},
66+
{
67+
filename: 'test.vue',
68+
code: '<template><div><component data-foo-bar="prop"></component></div></template>',
69+
options: ['PascalCase']
70+
},
71+
{
72+
filename: 'test.vue',
73+
code: '<template><div><component :data-foo-bar="prop"></component></div></template>',
74+
options: ['PascalCase']
6575
}
6676
],
6777

0 commit comments

Comments
 (0)