diff --git a/lib/rules/no-unused-state.js b/lib/rules/no-unused-state.js index 9484819e6b..0e5e392a18 100644 --- a/lib/rules/no-unused-state.js +++ b/lib/rules/no-unused-state.js @@ -101,7 +101,7 @@ module.exports = { parent && parent.type === 'MethodDefinition' && ( parent.static && parent.key.name === 'getDerivedStateFromProps' || - classMethods.indexOf(parent.key.name !== -1) + classMethods.indexOf(parent.key.name) !== -1 ) && parent.value.type === 'FunctionExpression' && parent.value.params[1] && diff --git a/tests/lib/rules/no-unused-state.js b/tests/lib/rules/no-unused-state.js index 4919f9c94e..d69e2646c8 100644 --- a/tests/lib/rules/no-unused-state.js +++ b/tests/lib/rules/no-unused-state.js @@ -1059,6 +1059,26 @@ eslintTester.run('no-unused-state', rule, { errors: getErrorMessages(['foo']), parser: parsers.BABEL_ESLINT }, + { + code: `class UseStateParameterOfNonLifecycleTest extends Component { + constructor(props) { + super(props); + this.state = { + foo: 123, + }; + } + nonLifecycle(someProps, someState) { + doStuff(someState.foo) + } + render() { + return ( + + ); + } + }`, + errors: getErrorMessages(['foo']), + parser: parsers.BABEL_ESLINT + }, { code: `class MissingStateParameterTest extends Component { constructor(props) {