Skip to content

Commit 45104ad

Browse files
authored
Update REGEX in no-side-effects-in-computed-properties (#308)
1 parent b434ff9 commit 45104ad

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function create (context) {
2727
// this.xxx.func()
2828
'CallExpression' (node) {
2929
const code = context.getSourceCode().getText(node)
30-
const MUTATION_REGEX = /(this.)((?!(concat|slice|map|filter)\().)*((push|pop|shift|unshift|reverse|splice|sort|copyWithin|fill)\()/g
30+
const MUTATION_REGEX = /(this.)((?!(concat|slice|map|filter)\().)[^\)]*((push|pop|shift|unshift|reverse|splice|sort|copyWithin|fill)\()/g
3131

3232
if (MUTATION_REGEX.test(code)) {
3333
forbiddenNodes.push(node)

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

+14
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ ruleTester.run('no-side-effects-in-computed-properties', rule, {
7373
test: 'example'
7474
}
7575
}
76+
},
77+
test9() {
78+
return Object.keys(this.a).sort()
79+
},
80+
test10: {
81+
get() {
82+
return Object.keys(this.a).sort()
83+
}
7684
}
7785
}
7886
})`,
@@ -144,6 +152,9 @@ ruleTester.run('no-side-effects-in-computed-properties', rule, {
144152
this.something[index] = thing[index]
145153
return this.something
146154
},
155+
test6() {
156+
return this.something.keys.sort()
157+
}
147158
}
148159
})`,
149160
parserOptions,
@@ -165,6 +176,9 @@ ruleTester.run('no-side-effects-in-computed-properties', rule, {
165176
}, {
166177
line: 21,
167178
message: 'Unexpected side effect in "test5" computed property.'
179+
}, {
180+
line: 25,
181+
message: 'Unexpected side effect in "test6" computed property.'
168182
}]
169183
},
170184
{

0 commit comments

Comments
 (0)