Skip to content

Commit 2624809

Browse files
committed
feat: add test cases
1 parent 914f52d commit 2624809

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

lib/rules/attribute-hyphenation.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ module.exports = {
143143
}
144144

145145
/** @param {string} name */
146-
function isIgnoredTags(name) {
146+
function isIgnoredTagName(name) {
147147
return ignoreTags.some((re) => re.test(name))
148148
}
149149

@@ -152,7 +152,7 @@ module.exports = {
152152
const element = node.parent.parent
153153
if (
154154
(!utils.isCustomComponent(element) && element.name !== 'slot') ||
155-
isIgnoredTags(element.rawName)
155+
isIgnoredTagName(element.rawName)
156156
)
157157
return
158158

lib/rules/v-on-event-hyphenation.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ module.exports = {
112112
}
113113

114114
/** @param {string} name */
115-
function isIgnoreTags(name) {
115+
function isIgnoredTagName(name) {
116116
return ignoreTags.some((re) => re.test(name))
117117
}
118118

@@ -121,7 +121,7 @@ module.exports = {
121121
const element = node.parent.parent
122122
if (
123123
!utils.isCustomComponent(element) ||
124-
isIgnoreTags(element.rawName)
124+
isIgnoredTagName(element.rawName)
125125
) {
126126
return
127127
}

tests/lib/rules/attribute-hyphenation.js

+33
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ ruleTester.run('attribute-hyphenation', rule, {
9595
</template>
9696
`,
9797
options: ['never', { ignoreTags: ['VueComponent', '/^custom-/'] }]
98+
},
99+
{
100+
filename: 'test.vue',
101+
code: `
102+
<template>
103+
<VueComponent myProp="prop"></VueComponent>
104+
<custom-component myProp="prop"></custom-component>
105+
</template>
106+
`,
107+
options: ['always', { ignoreTags: ['VueComponent', '/^custom-/'] }]
98108
}
99109
],
100110

@@ -483,6 +493,29 @@ ruleTester.run('attribute-hyphenation', rule, {
483493
column: 17
484494
}
485495
]
496+
},
497+
{
498+
code: `
499+
<template>
500+
<custom myProp/>
501+
<CustomComponent myProp/>
502+
</template>
503+
`,
504+
output: `
505+
<template>
506+
<custom my-prop/>
507+
<CustomComponent myProp/>
508+
</template>
509+
`,
510+
options: ['always', { ignoreTags: ['CustomComponent'] }],
511+
errors: [
512+
{
513+
message: "Attribute 'myProp' must be hyphenated.",
514+
type: 'VIdentifier',
515+
line: 3,
516+
column: 17
517+
}
518+
]
486519
}
487520
]
488521
})

tests/lib/rules/v-on-event-hyphenation.js

+31
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ tester.run('v-on-event-hyphenation', rule, {
6161
</template>
6262
`,
6363
options: ['never', { ignoreTags: ['/^Vue/', 'custom-component'] }]
64+
},
65+
{
66+
code: `
67+
<template>
68+
<VueComponent v-on:customEvent="events"/>
69+
<custom-component v-on:customEvent="events"/>
70+
</template>
71+
`,
72+
options: ['always', { ignoreTags: ['/^Vue/', 'custom-component'] }]
6473
}
6574
],
6675
invalid: [
@@ -218,6 +227,28 @@ tester.run('v-on-event-hyphenation', rule, {
218227
column: 23
219228
}
220229
]
230+
},
231+
{
232+
code: `
233+
<template>
234+
<VueComponent v-on:customEvent="events"/>
235+
<CustomComponent v-on:customEvent="events"/>
236+
</template>
237+
`,
238+
output: `
239+
<template>
240+
<VueComponent v-on:custom-event="events"/>
241+
<CustomComponent v-on:customEvent="events"/>
242+
</template>
243+
`,
244+
options: ['always', { autofix: true, ignoreTags: ['CustomComponent'] }],
245+
errors: [
246+
{
247+
message: "v-on event 'v-on:customEvent' must be hyphenated.",
248+
line: 3,
249+
column: 23
250+
}
251+
]
221252
}
222253
]
223254
})

0 commit comments

Comments
 (0)