Skip to content

Commit

Permalink
Allow LHS in destructuring-assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzherdev committed Jun 14, 2018
1 parent c82746c commit fcff54e
Show file tree
Hide file tree
Showing 2 changed files with 12 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
10 changes: 10 additions & 0 deletions tests/lib/rules/destructuring-assignment.js
Expand Up @@ -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 (<div id={props.id} />)
Expand Down

0 comments on commit fcff54e

Please sign in to comment.