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(no-use-computed-property-like-method): Check the case CallExpression's arguments has include CallExpression at least #1600

Merged
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
3 changes: 3 additions & 0 deletions lib/rules/no-use-computed-property-like-method.js
Expand Up @@ -228,6 +228,9 @@ module.exports = {

if (node.parent.type !== 'MemberExpression') return
if (node.parent.property.type !== 'Identifier') return
if (node.parent.parent.type !== 'CallExpression') return
if (node.parent.parent.callee.type !== 'MemberExpression') return
if (!Object.is(node.parent.parent.callee, node.parent)) return

const thisMember = node.parent.property.name

Expand Down
64 changes: 64 additions & 0 deletions tests/lib/rules/no-use-computed-property-like-method.js
Expand Up @@ -418,6 +418,26 @@ tester.run('no-use-computed-property-like-method', rule, {
}
</script>
`
},
{
filename: 'test.vue',
code: `
<script>
export default {
computed: {
computedReturnArray() {
return [1,2,3,4,5]
},
computedReturnArray2() {
return [1,2,3,4,5]
},
computedReturnComputedReturnString() {
return this.computedReturnArray.map(() => this.computedReturnArray2)
}
}
}
</script>
`
}
],
invalid: [
Expand Down Expand Up @@ -698,6 +718,50 @@ tester.run('no-use-computed-property-like-method', rule, {
errors: [
'Use this.computedReturnNothing instead of this.computedReturnNothing().'
]
},
{
filename: 'test.vue',
code: `
<script>
export default {
computed: {
computedReturnString() {
return 'computedReturnString'
},
computedReturnComputedReturnString() {
return this.computedReturnString()
}
}
}
</script>
`,
errors: [
'Use this.computedReturnString instead of this.computedReturnString().'
]
},
{
filename: 'test.vue',
code: `
<script>
export default {
computed: {
computedReturnArray() {
return [1,2,3,4,5]
},
computedReturnArray2() {
return [1,2,3,4,5]
},
computedReturnComputedReturnString() {
return this.computedReturnArray.map([...this.computedReturnArray(), ...this.computedReturnArray2()])
}
}
}
</script>
`,
errors: [
'Use this.computedReturnArray instead of this.computedReturnArray().',
'Use this.computedReturnArray2 instead of this.computedReturnArray2().'
]
}
]
})