diff --git a/lib/rules/no-unused-state.js b/lib/rules/no-unused-state.js index 4040d80dc7..421678fe88 100644 --- a/lib/rules/no-unused-state.js +++ b/lib/rules/no-unused-state.js @@ -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; } }, diff --git a/tests/lib/rules/no-unused-state.js b/tests/lib/rules/no-unused-state.js index 62f9599e4c..4e627875d0 100644 --- a/tests/lib/rules/no-unused-state.js +++ b/tests/lib/rules/no-unused-state.js @@ -479,6 +479,18 @@ eslintTester.run('no-unused-state', rule, { } }`, parser: 'babel-eslint' + }, + { + code: `class ThisStateAsAnObject extends React.Component { + state = { + active: true + }; + + render() { + return
; + } + }`, + parser: 'babel-eslint' } ],