From 35325d6db724b41fa48b54d8d1615e34f439150b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sajn=C3=B3g?= Date: Fri, 29 Dec 2017 01:38:20 +0100 Subject: [PATCH] Update REGEX in no-side-effects-in-computed-properties --- .../no-side-effects-in-computed-properties.js | 2 +- .../no-side-effects-in-computed-properties.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/rules/no-side-effects-in-computed-properties.js b/lib/rules/no-side-effects-in-computed-properties.js index f7817ec0e..7af1c2dd1 100644 --- a/lib/rules/no-side-effects-in-computed-properties.js +++ b/lib/rules/no-side-effects-in-computed-properties.js @@ -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) 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 9e63b3079..cfd71c7d1 100644 --- a/tests/lib/rules/no-side-effects-in-computed-properties.js +++ b/tests/lib/rules/no-side-effects-in-computed-properties.js @@ -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() + } } } })`, @@ -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, @@ -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.' }] }, {