Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix false negatives for TemplateLiteral in vue/prop-name-casing rule. #1208

Merged
merged 1 commit into from Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.']
}
]
})