Skip to content

Commit f40b7b8

Browse files
authored
Merge pull request jsx-eslint#1611 from pfhayes/node.init
[Fix] `no-access-state-in-setstate`: Handle nodes without init
2 parents 9b8ea5e + bb34372 commit f40b7b8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/rules/no-access-state-in-setstate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ module.exports = {
143143
},
144144

145145
ObjectPattern(node) {
146-
const isDerivedFromThis = node.parent.init.type === 'ThisExpression';
146+
const isDerivedFromThis = node.parent.init && node.parent.init.type === 'ThisExpression';
147147
node.properties.forEach(property => {
148148
if (property.key.name === 'state' && isDerivedFromThis) {
149149
vars.push({

tests/lib/rules/no-access-state-in-setstate.js

+7
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ ruleTester.run('no-access-state-in-setstate', rule, {
7575
'});'
7676
].join('\n'),
7777
parserOptions: parserOptions
78+
}, {
79+
// https://github.com/yannickcr/eslint-plugin-react/pull/1611
80+
code: `
81+
function testFunction({a, b}) {
82+
};
83+
`,
84+
parserOptions: parserOptions
7885
}],
7986

8087
invalid: [{

0 commit comments

Comments
 (0)