Skip to content

Commit

Permalink
Update REGEX in no-side-effects-in-computed-properties (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsnik committed Dec 31, 2017
1 parent b434ff9 commit 45104ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-side-effects-in-computed-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function create (context) {
// this.xxx.func()
'CallExpression' (node) {
const code = context.getSourceCode().getText(node)
const MUTATION_REGEX = /(this.)((?!(concat|slice|map|filter)\().)*((push|pop|shift|unshift|reverse|splice|sort|copyWithin|fill)\()/g
const MUTATION_REGEX = /(this.)((?!(concat|slice|map|filter)\().)[^\)]*((push|pop|shift|unshift|reverse|splice|sort|copyWithin|fill)\()/g

if (MUTATION_REGEX.test(code)) {
forbiddenNodes.push(node)
Expand Down
14 changes: 14 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 @@ -73,6 +73,14 @@ ruleTester.run('no-side-effects-in-computed-properties', rule, {
test: 'example'
}
}
},
test9() {
return Object.keys(this.a).sort()
},
test10: {
get() {
return Object.keys(this.a).sort()
}
}
}
})`,
Expand Down Expand Up @@ -144,6 +152,9 @@ ruleTester.run('no-side-effects-in-computed-properties', rule, {
this.something[index] = thing[index]
return this.something
},
test6() {
return this.something.keys.sort()
}
}
})`,
parserOptions,
Expand All @@ -165,6 +176,9 @@ ruleTester.run('no-side-effects-in-computed-properties', rule, {
}, {
line: 21,
message: 'Unexpected side effect in "test5" computed property.'
}, {
line: 25,
message: 'Unexpected side effect in "test6" computed property.'
}]
},
{
Expand Down

0 comments on commit 45104ad

Please sign in to comment.