Skip to content

Commit 2a674b0

Browse files
authored
Merge pull request jsx-eslint#1825 from alexzherdev/1728-destructuring-state-assignment
[Fix] Allow LHS in destructuring-assignment
2 parents c82746c + b6e911b commit 2a674b0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/rules/destructuring-assignment.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ module.exports = {
7878
// this.props.Aprop || this.context.aProp || this.state.aState
7979
const isPropUsed = (
8080
node.object.type === 'MemberExpression' && node.object.object.type === 'ThisExpression' &&
81-
(node.object.property.name === 'props' || node.object.property.name === 'context' || node.object.property.name === 'state')
81+
(node.object.property.name === 'props' || node.object.property.name === 'context' || node.object.property.name === 'state') &&
82+
!isAssignmentToProp(node)
8283
);
8384

8485
if (isPropUsed && configuration === 'always') {

tests/lib/rules/destructuring-assignment.js

+9
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,16 @@ ruleTester.run('destructuring-assignment', rule, {
126126
};`,
127127
options: ['never'],
128128
parser: 'babel-eslint'
129+
}, {
130+
code: `const Foo = class extends React.PureComponent {
131+
constructor() {
132+
this.state = {};
133+
this.state.foo = 'bar';
134+
}
135+
};`,
136+
options: ['always']
129137
}],
138+
130139
invalid: [{
131140
code: `const MyComponent = (props) => {
132141
return (<div id={props.id} />)

0 commit comments

Comments
 (0)