Skip to content

Commit

Permalink
Merge pull request #1825 from alexzherdev/1728-destructuring-state-as…
Browse files Browse the repository at this point in the history
…signment

[Fix] Allow LHS in destructuring-assignment
  • Loading branch information
ljharb committed Jun 14, 2018
2 parents c82746c + b6e911b commit 2a674b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rules/destructuring-assignment.js
Expand Up @@ -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') {
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/rules/destructuring-assignment.js
Expand Up @@ -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 (<div id={props.id} />)
Expand Down

0 comments on commit 2a674b0

Please sign in to comment.