Description
Tell us about your environment
I try using 5f4f3ce
(last master) from this repos
-
ESLint Version: ^3.19.0
-
eslint-plugin-eslint-plugin: ^0.8.0
-
eslint-plugin-vue-libs: ^1.2.0
-
mocha: ^3.2.0
-
eslint-plugin-vue Version: version: 3.13.1
-
Node Version: 8.8.1
Please show your full configuration:
Not relevant
What did you do? Please include the actual source code causing the issue.
I write a unit test case but I can't solve the issue myself:
'use strict'
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
const rule = require('../../../lib/rules/no-side-effects-in-computed-properties')
const RuleTester = require('eslint').RuleTester
const parserOptions = {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: { experimentalObjectRestSpread: true }
}
// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------
const ruleTester = new RuleTester()
ruleTester.run('no-side-effects-in-computed-properties', rule, {
valid: [
{
code: `Vue.component('test', {
computed: {
test9 () {
let computedResult = {}
const index = ''
computedResult[index] = this.images[index]
return computedResult
},
}
})`,
parserOptions
}
],
invalid: [
{
code: `Vue.component('test', {
computed: {
test5 () {
let computedResult = {}
const index = ''
this.images[index] = computedResult[index]
return computedResult
},
}
})`,
parserOptions,
errors: [{
line: 6,
message: 'Unexpected side effect in "test5" computed property.'
}]
}
]
})
What did you expect to happen?
The first test must succeed (I don't update this.images
, just read it), the second must fail
What actually happened? Please include the actual, raw output from ESLint.
I got an Unexpected side effect
in both case.
The section of parser lib/rules/no-side-effects-in-computed-properties.js
relevant for my case is the following:
// this.xxx <=|+=|-=>
'AssignmentExpression > MemberExpression' (node) {
if (utils.parseMemberExpression(node)[0] === 'this') {
forbiddenNodes.push(node)
}
},
The grammar parser ( AssignmentExpression > MemberExpression
) see independent nodes and a console log will show the two part separately, it shouldn't.
A console.log will show the following:
[ 'computedResult', 'index' ]
[ 'this', 'images', 'index' ]