From fcff54ed23b6326f6c91224e2ac29b5fe1cd959f Mon Sep 17 00:00:00 2001 From: Alex Zherdev Date: Wed, 13 Jun 2018 23:09:55 -0700 Subject: [PATCH] Allow LHS in destructuring-assignment Resolves #1728 --- lib/rules/destructuring-assignment.js | 3 ++- tests/lib/rules/destructuring-assignment.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/rules/destructuring-assignment.js b/lib/rules/destructuring-assignment.js index 93bbaed704..45c2af91f7 100644 --- a/lib/rules/destructuring-assignment.js +++ b/lib/rules/destructuring-assignment.js @@ -78,7 +78,8 @@ module.exports = { // this.props.Aprop || this.context.aProp || this.state.aState const isPropUsed = ( node.object.type === 'MemberExpression' && node.object.object.type === 'ThisExpression' && - (node.object.property.name === 'props' || node.object.property.name === 'context' || node.object.property.name === 'state') + (node.object.property.name === 'props' || node.object.property.name === 'context' || node.object.property.name === 'state') && + !isAssignmentToProp(node) ); if (isPropUsed && configuration === 'always') { diff --git a/tests/lib/rules/destructuring-assignment.js b/tests/lib/rules/destructuring-assignment.js index 6ce0e36cfb..752a3d8fe3 100644 --- a/tests/lib/rules/destructuring-assignment.js +++ b/tests/lib/rules/destructuring-assignment.js @@ -126,7 +126,17 @@ ruleTester.run('destructuring-assignment', rule, { };`, options: ['never'], parser: 'babel-eslint' + }, { + code: `const Foo = class extends React.PureComponent { + constructor() { + this.state = {}; + this.state.foo = 'bar'; + } + };`, + options: ['always'], + parser: 'babel-eslint' }], + invalid: [{ code: `const MyComponent = (props) => { return (
)