Skip to content

Commit

Permalink
fix: check pattern that CallExpression's arguments include CallExpres…
Browse files Browse the repository at this point in the history
…sion (#1600)
  • Loading branch information
tyankatsu0105 committed Aug 10, 2021
1 parent 45218f7 commit 308cb54
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
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().'
]
}
]
})

0 comments on commit 308cb54

Please sign in to comment.