diff --git a/lib/rules/no-side-effects-in-computed-properties.js b/lib/rules/no-side-effects-in-computed-properties.js index 9ac247d17..83035ec50 100644 --- a/lib/rules/no-side-effects-in-computed-properties.js +++ b/lib/rules/no-side-effects-in-computed-properties.js @@ -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) } }, diff --git a/tests/lib/rules/no-side-effects-in-computed-properties.js b/tests/lib/rules/no-side-effects-in-computed-properties.js index a84e6fae8..9e63b3079 100644 --- a/tests/lib/rules/no-side-effects-in-computed-properties.js +++ b/tests/lib/rules/no-side-effects-in-computed-properties.js @@ -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: [ @@ -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, @@ -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.' }] }, {