Skip to content

Commit

Permalink
[Fix] no-access-state-in-setstate: handle object spread
Browse files Browse the repository at this point in the history
Fixes #1657
  • Loading branch information
ljharb committed Jan 27, 2018
1 parent d060041 commit e56376e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
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 @@ -148,7 +148,7 @@ module.exports = {
ObjectPattern(node) {
const isDerivedFromThis = node.parent.init && node.parent.init.type === 'ThisExpression';
node.properties.forEach(property => {
if (property.key.name === 'state' && isDerivedFromThis) {
if (property && property.key && property.key.name === 'state' && isDerivedFromThis) {
vars.push({
node: property.key,
scope: context.getScope(),
Expand Down
5 changes: 3 additions & 2 deletions tests/lib/rules/no-access-state-in-setstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ const rule = require('../../../lib/rules/no-access-state-in-setstate');
const RuleTester = require('eslint').RuleTester;

const parserOptions = {
ecmaVersion: 6,
ecmaVersion: 2018,
ecmaFeatures: {
experimentalObjectRestSpread: true,
jsx: true
}
};
Expand Down Expand Up @@ -125,7 +126,7 @@ ruleTester.run('no-access-state-in-setstate', rule, {
code: [
'var Hello = React.createClass({',
' onClick: function() {',
' var {state} = this',
' var {state, ...rest} = this',
' this.setState({value: state.value + 1})',
' }',
'});'
Expand Down

0 comments on commit e56376e

Please sign in to comment.