Skip to content

Commit

Permalink
Fix no-unused-state to detect usage of this.state as an object (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Nov 27, 2017
1 parent c7dd755 commit af6ccb0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rules/no-unused-state.js
Expand Up @@ -352,6 +352,9 @@ module.exports = {
}
// Otherwise, record that we saw this property being accessed.
addUsedStateField(node.property);
// If we see a `this.state` access in a CallExpression, give up.
} else if (isStateReference(node) && node.parent.type === 'CallExpression') {
classInfo = null;
}
},

Expand Down
12 changes: 12 additions & 0 deletions tests/lib/rules/no-unused-state.js
Expand Up @@ -479,6 +479,18 @@ eslintTester.run('no-unused-state', rule, {
}
}`,
parser: 'babel-eslint'
},
{
code: `class ThisStateAsAnObject extends React.Component {
state = {
active: true
};
render() {
return <div className={classNames('overflowEdgeIndicator', className, this.state)} />;
}
}`,
parser: 'babel-eslint'
}
],

Expand Down

0 comments on commit af6ccb0

Please sign in to comment.