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..ca5a85e28a 100644 --- a/tests/lib/rules/destructuring-assignment.js +++ b/tests/lib/rules/destructuring-assignment.js @@ -126,7 +126,16 @@ 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'] }], + invalid: [{ code: `const MyComponent = (props) => { return (
)