Skip to content

Commit e56376e

Browse files
committed
[Fix] no-access-state-in-setstate: handle object spread
Fixes #1657
1 parent d060041 commit e56376e

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ module.exports = {
148148
ObjectPattern(node) {
149149
const isDerivedFromThis = node.parent.init && node.parent.init.type === 'ThisExpression';
150150
node.properties.forEach(property => {
151-
if (property.key.name === 'state' && isDerivedFromThis) {
151+
if (property && property.key && property.key.name === 'state' && isDerivedFromThis) {
152152
vars.push({
153153
node: property.key,
154154
scope: context.getScope(),

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ const rule = require('../../../lib/rules/no-access-state-in-setstate');
1212
const RuleTester = require('eslint').RuleTester;
1313

1414
const parserOptions = {
15-
ecmaVersion: 6,
15+
ecmaVersion: 2018,
1616
ecmaFeatures: {
17+
experimentalObjectRestSpread: true,
1718
jsx: true
1819
}
1920
};
@@ -125,7 +126,7 @@ ruleTester.run('no-access-state-in-setstate', rule, {
125126
code: [
126127
'var Hello = React.createClass({',
127128
' onClick: function() {',
128-
' var {state} = this',
129+
' var {state, ...rest} = this',
129130
' this.setState({value: state.value + 1})',
130131
' }',
131132
'});'

0 commit comments

Comments
 (0)