Skip to content

Commit

Permalink
Support MemberExpressions in no-mutating-methods allowedObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Jan 1, 2021
1 parent 205861e commit e40caaa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rules/no-mutating-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ const create = function (context) {
return;
}

if (node.callee.object.type === 'MemberExpression' && allowedObjects.indexOf(node.callee.object.property.name) !== -1) {
return;
}

if (node.callee.object.name === 'Object') {
if (mutatingObjectMethods.indexOf(node.callee.property.name) !== -1) {
context.report({
Expand Down
6 changes: 6 additions & 0 deletions test/no-mutating-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ ruleTester.run('no-mutating-methods', rule, {
allowedObjects: ['R']
}]
},
{
code: 'this.$route.push(a)',
options: [{
allowedObjects: ['$route']
}]
},
'Object.keys(a)',
'Object.values(a)'
],
Expand Down

0 comments on commit e40caaa

Please sign in to comment.