Skip to content

[Fix] 'vue/prop-name-casing` to not warn variable computed property #444

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

Merged
merged 1 commit into from
Apr 1, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/rules/prop-name-casing.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ function create (context) {
if (item.type !== 'Property') {
return
}
if (item.computed) {
if (item.key.type !== 'Literal') {
// TemplateLiteral | Identifier(variable) | Expression(s)
return
}
if (typeof item.key.value !== 'string') {
// (boolean | null | number | RegExp) Literal
return
}
}

const propName = item.key.type === 'Literal' ? item.key.value : item.key.name
const convertedName = converter(propName)
Expand Down
217 changes: 198 additions & 19 deletions tests/lib/rules/prop-name-casing.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,186 @@ ruleTester.run('prop-name-casing', rule, {
`,
options: ['snake_case'],
parserOptions
},
{
// computed property name
filename: 'test.vue',
code: `
export default {
props: {
['greetingText']: String
}
}
`,
parserOptions
},
{
// computed property name
filename: 'test.vue',
code: `
export default {
props: {
[('greetingText')]: String
}
}
`,
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',
code: `
export default {
props: {
[\`greeting\${'-'}text\`]: String
}
}
`,
parserOptions
},
{
// shorthand
filename: 'test.vue',
code: `
export default {
props: {
greetingText
}
}
`,
parserOptions
},
{
// valiable computed property name does not warn
filename: 'test.vue',
code: `
export default {
props: {
[greeting_text]: String
}
}
`,
parserOptions
},
{
// valiable computed property name does not warn
filename: 'test.vue',
code: `
export default {
props: {
[greeting.text]: String
}
}
`,
parserOptions
},
{
// BinaryExpression computed property name does not warn
filename: 'test.vue',
code: `
export default {
props: {
['greeting'+'-text']: String
}
}
`,
parserOptions
},
{
// CallExpression computed property name does not warn
filename: 'test.vue',
code: `
export default {
props: {
[greeting_text()]: String
}
}
`,
parserOptions
},
{
// ThisExpression computed property name does not warn
filename: 'test.vue',
code: `
export default {
props: {
[this]: String
}
}
`,
parserOptions
},
{
// ArrayExpression computed property name does not warn
filename: 'test.vue',
code: `
export default {
props: {
[['greeting-text']]: String
}
}
`,
parserOptions
},
{
// number Literal computed property name
filename: 'test.vue',
code: `
export default {
props: {
[1]: String
}
}
`,
parserOptions
},
{
// boolean Literal computed property name
filename: 'test.vue',
code: `
export default {
props: {
[true]: String
}
}
`,
parserOptions
},
{
// null Literal computed property name
filename: 'test.vue',
code: `
export default {
props: {
[null]: String
}
}
`,
parserOptions
},
{
// RegExp Literal computed property name
filename: 'test.vue',
code: `
export default {
props: {
[/greeting-text/]: String
}
}
`,
parserOptions
}
],

Expand Down Expand Up @@ -290,25 +470,6 @@ ruleTester.run('prop-name-casing', rule, {
line: 4
}]
},
{
// valiable computed property name
filename: 'test.vue',
code: `
export default {
props: {
[greeting_text]: String
}
}
`,
output: null,
parserOptions,
errors: [{
// bug ?
message: 'Prop "greeting_text" is not in camelCase.',
type: 'Property',
line: 4
}]
},
{
// emoji
filename: 'test.vue',
Expand Down Expand Up @@ -367,6 +528,24 @@ ruleTester.run('prop-name-casing', rule, {
type: 'Property',
line: 4
}]
},
{
// Parentheses computed property name
filename: 'test.vue',
code: `
export default {
props: {
[('greeting-text')]: String
}
}
`,
output: null,
parserOptions,
errors: [{
message: 'Prop "greeting-text" is not in camelCase.',
type: 'Property',
line: 4
}]
}
]
})