Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow LHS in destructuring-assignment #1825

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test case doesn't require babel-eslint, let's remove this line

}],

invalid: [{
code: `const MyComponent = (props) => {
return (<div id={props.id} />)
Expand Down