Skip to content
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
5 changes: 3 additions & 2 deletions lib/rules/no-side-effects-in-computed-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ function create (context) {
return Object.assign({},
{
// this.xxx <=|+=|-=>
'AssignmentExpression > MemberExpression' (node) {
if (utils.parseMemberExpression(node)[0] === 'this') {
'AssignmentExpression' (node) {
if (node.left.type !== 'MemberExpression') return
if (utils.parseMemberExpression(node.left)[0] === 'this') {
forbiddenNodes.push(node)
}
},
Expand Down
19 changes: 19 additions & 0 deletions tests/lib/rules/no-side-effects-in-computed-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ ruleTester.run('no-side-effects-in-computed-properties', rule, {
}
})`,
parserOptions
},
{
code: `Vue.component('test', {
computed: {
test () {
let a;
a = this.something
return a
},
}
})`,
parserOptions
}
],
invalid: [
Expand All @@ -128,6 +140,10 @@ ruleTester.run('no-side-effects-in-computed-properties', rule, {
const test = this.another.something.push('example')
return 'something'
},
test5() {
this.something[index] = thing[index]
return this.something
},
}
})`,
parserOptions,
Expand All @@ -146,6 +162,9 @@ ruleTester.run('no-side-effects-in-computed-properties', rule, {
}, {
line: 17,
message: 'Unexpected side effect in "test4" computed property.'
}, {
line: 21,
message: 'Unexpected side effect in "test5" computed property.'
}]
},
{
Expand Down