Skip to content

Commit b23c518

Browse files
authored
Check only left part of assignment in no-side-effects-in-computed-property rule (#231)
1 parent 5f4f3ce commit b23c518

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/rules/no-side-effects-in-computed-properties.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ function create (context) {
1212
return Object.assign({},
1313
{
1414
// this.xxx <=|+=|-=>
15-
'AssignmentExpression > MemberExpression' (node) {
16-
if (utils.parseMemberExpression(node)[0] === 'this') {
15+
'AssignmentExpression' (node) {
16+
if (node.left.type !== 'MemberExpression') return
17+
if (utils.parseMemberExpression(node.left)[0] === 'this') {
1718
forbiddenNodes.push(node)
1819
}
1920
},

tests/lib/rules/no-side-effects-in-computed-properties.js

+19
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ ruleTester.run('no-side-effects-in-computed-properties', rule, {
105105
}
106106
})`,
107107
parserOptions
108+
},
109+
{
110+
code: `Vue.component('test', {
111+
computed: {
112+
test () {
113+
let a;
114+
a = this.something
115+
return a
116+
},
117+
}
118+
})`,
119+
parserOptions
108120
}
109121
],
110122
invalid: [
@@ -128,6 +140,10 @@ ruleTester.run('no-side-effects-in-computed-properties', rule, {
128140
const test = this.another.something.push('example')
129141
return 'something'
130142
},
143+
test5() {
144+
this.something[index] = thing[index]
145+
return this.something
146+
},
131147
}
132148
})`,
133149
parserOptions,
@@ -146,6 +162,9 @@ ruleTester.run('no-side-effects-in-computed-properties', rule, {
146162
}, {
147163
line: 17,
148164
message: 'Unexpected side effect in "test4" computed property.'
165+
}, {
166+
line: 21,
167+
message: 'Unexpected side effect in "test5" computed property.'
149168
}]
150169
},
151170
{

0 commit comments

Comments
 (0)