Skip to content

Commit

Permalink
[Fix] no-unused-state: handle optional chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot authored and ljharb committed Mar 8, 2020
1 parent 9861469 commit cb40c32
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-unused-state.js
Expand Up @@ -415,7 +415,7 @@ module.exports = {
handleAssignment(node.id, node.init);
},

MemberExpression(node) {
'MemberExpression, OptionalMemberExpression'(node) {
if (!classInfo) {
return;
}
Expand Down
22 changes: 22 additions & 0 deletions tests/lib/rules/no-unused-state.js
Expand Up @@ -231,6 +231,28 @@ eslintTester.run('no-unused-state', rule, {
}
}`,
parser: parsers.BABEL_ESLINT
}, {
code: `
class OptionalChaining extends React.Component {
constructor() {
this.state = { foo: 0 };
}
render() {
return <SomeComponent foo={this.state?.foo} />;
}
}`,
parser: parsers['@TYPESCRIPT_ESLINT']
}, {
code: `
class OptionalChaining extends React.Component {
constructor() {
this.state = { foo: 0 };
}
render() {
return <SomeComponent foo={this.state?.foo} />;
}
}`,
parser: parsers.BABEL_ESLINT
},
`class VariableDeclarationTest extends React.Component {
constructor() {
Expand Down

0 comments on commit cb40c32

Please sign in to comment.