Skip to content

Commit

Permalink
Fix false negatives in TemplateLiteral for vue/prop-name-casing rul…
Browse files Browse the repository at this point in the history
…e. (#1208)
  • Loading branch information
ota-meshi committed Jun 12, 2020
1 parent b33c708 commit 7617a91
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 38 deletions.
16 changes: 2 additions & 14 deletions lib/rules/prop-name-casing.js
Expand Up @@ -24,20 +24,8 @@ function create(context) {

return utils.executeOnVue(context, (obj) => {
for (const item of utils.getComponentProps(obj)) {
if (item.propName == null) {
continue
}
const propName =
item.key.type === 'Literal'
? item.key.value
: item.key.type === 'TemplateLiteral'
? null
: item.propName
// TODO We should use propName.
// const propName = item.propName

if (typeof propName !== 'string') {
// (boolean | null | number | RegExp) Literal
const propName = item.propName
if (propName == null) {
continue
}
if (!checker(propName)) {
Expand Down
50 changes: 26 additions & 24 deletions tests/lib/rules/prop-name-casing.js
Expand Up @@ -131,18 +131,6 @@ ruleTester.run('prop-name-casing', rule, {
`,
parserOptions
},
{
// TemplateLiteral computed property does not warn
filename: 'test.vue',
code: `
export default {
props: {
[\`greeting-text\`]: String
}
}
`,
parserOptions
},
{
// TemplateLiteral computed property does not warn
filename: 'test.vue',
Expand Down Expand Up @@ -275,18 +263,6 @@ ruleTester.run('prop-name-casing', rule, {
`,
parserOptions
},
{
// RegExp Literal computed property name
filename: 'test.vue',
code: `
export default {
props: {
[/greeting-text/]: String
}
}
`,
parserOptions
},
{
// Japanese characters
filename: 'test.vue',
Expand Down Expand Up @@ -578,6 +554,32 @@ ruleTester.run('prop-name-casing', rule, {
options: ['snake_case'],
parserOptions,
errors: ['Prop "_itemName" is not in snake_case.']
},
{
// TemplateLiteral computed property
filename: 'test.vue',
code: `
export default {
props: {
[\`greeting-text\`]: String
}
}
`,
parserOptions,
errors: ['Prop "greeting-text" is not in camelCase.']
},
{
// RegExp Literal computed property name
filename: 'test.vue',
code: `
export default {
props: {
[/greeting-text/]: String
}
}
`,
parserOptions,
errors: ['Prop "/greeting-text/" is not in camelCase.']
}
]
})

0 comments on commit 7617a91

Please sign in to comment.