diff --git a/lib/rules/no-access-state-in-setstate.js b/lib/rules/no-access-state-in-setstate.js index 72e8081520..5a8d2e36ea 100644 --- a/lib/rules/no-access-state-in-setstate.js +++ b/lib/rules/no-access-state-in-setstate.js @@ -143,7 +143,7 @@ module.exports = { }, ObjectPattern(node) { - const isDerivedFromThis = node.parent.init.type === 'ThisExpression'; + const isDerivedFromThis = node.parent.init && node.parent.init.type === 'ThisExpression'; node.properties.forEach(property => { if (property.key.name === 'state' && isDerivedFromThis) { vars.push({ diff --git a/tests/lib/rules/no-access-state-in-setstate.js b/tests/lib/rules/no-access-state-in-setstate.js index 784c6f6ed7..e908c04ec8 100644 --- a/tests/lib/rules/no-access-state-in-setstate.js +++ b/tests/lib/rules/no-access-state-in-setstate.js @@ -75,6 +75,13 @@ ruleTester.run('no-access-state-in-setstate', rule, { '});' ].join('\n'), parserOptions: parserOptions + }, { + // /~https://github.com/yannickcr/eslint-plugin-react/pull/1611 + code: ` + function testFunction({a, b}) { + }; + `, + parserOptions: parserOptions }], invalid: [{