Skip to content

Commit

Permalink
Merge pull request #1611 from pfhayes/node.init
Browse files Browse the repository at this point in the history
[Fix] `no-access-state-in-setstate`: Handle nodes without init
  • Loading branch information
ljharb committed Dec 20, 2017
2 parents 9b8ea5e + bb34372 commit f40b7b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-access-state-in-setstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
7 changes: 7 additions & 0 deletions tests/lib/rules/no-access-state-in-setstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [{
Expand Down

0 comments on commit f40b7b8

Please sign in to comment.