Skip to content

Commit 7617a91

Browse files
authored
Fix false negatives in TemplateLiteral for vue/prop-name-casing rule. (#1208)
1 parent b33c708 commit 7617a91

File tree

2 files changed

+28
-38
lines changed

2 files changed

+28
-38
lines changed

lib/rules/prop-name-casing.js

+2-14
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,8 @@ function create(context) {
2424

2525
return utils.executeOnVue(context, (obj) => {
2626
for (const item of utils.getComponentProps(obj)) {
27-
if (item.propName == null) {
28-
continue
29-
}
30-
const propName =
31-
item.key.type === 'Literal'
32-
? item.key.value
33-
: item.key.type === 'TemplateLiteral'
34-
? null
35-
: item.propName
36-
// TODO We should use propName.
37-
// const propName = item.propName
38-
39-
if (typeof propName !== 'string') {
40-
// (boolean | null | number | RegExp) Literal
27+
const propName = item.propName
28+
if (propName == null) {
4129
continue
4230
}
4331
if (!checker(propName)) {

tests/lib/rules/prop-name-casing.js

+26-24
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,6 @@ ruleTester.run('prop-name-casing', rule, {
131131
`,
132132
parserOptions
133133
},
134-
{
135-
// TemplateLiteral computed property does not warn
136-
filename: 'test.vue',
137-
code: `
138-
export default {
139-
props: {
140-
[\`greeting-text\`]: String
141-
}
142-
}
143-
`,
144-
parserOptions
145-
},
146134
{
147135
// TemplateLiteral computed property does not warn
148136
filename: 'test.vue',
@@ -275,18 +263,6 @@ ruleTester.run('prop-name-casing', rule, {
275263
`,
276264
parserOptions
277265
},
278-
{
279-
// RegExp Literal computed property name
280-
filename: 'test.vue',
281-
code: `
282-
export default {
283-
props: {
284-
[/greeting-text/]: String
285-
}
286-
}
287-
`,
288-
parserOptions
289-
},
290266
{
291267
// Japanese characters
292268
filename: 'test.vue',
@@ -578,6 +554,32 @@ ruleTester.run('prop-name-casing', rule, {
578554
options: ['snake_case'],
579555
parserOptions,
580556
errors: ['Prop "_itemName" is not in snake_case.']
557+
},
558+
{
559+
// TemplateLiteral computed property
560+
filename: 'test.vue',
561+
code: `
562+
export default {
563+
props: {
564+
[\`greeting-text\`]: String
565+
}
566+
}
567+
`,
568+
parserOptions,
569+
errors: ['Prop "greeting-text" is not in camelCase.']
570+
},
571+
{
572+
// RegExp Literal computed property name
573+
filename: 'test.vue',
574+
code: `
575+
export default {
576+
props: {
577+
[/greeting-text/]: String
578+
}
579+
}
580+
`,
581+
parserOptions,
582+
errors: ['Prop "/greeting-text/" is not in camelCase.']
581583
}
582584
]
583585
})

0 commit comments

Comments
 (0)