diff --git a/CHANGELOG.md b/CHANGELOG.md index a12e145c72..1602073a95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ## Unreleased +### Fixed +* [`no-unused-state`]: avoid a crash on type-only gDSFP declarations ([#3225][] @ljharb) + +[#3225]: https://github.com/yannickcr/eslint-plugin-react/issues/3225 + ## [7.29.2] - 2022.02.25 ### Fixed diff --git a/lib/rules/no-unused-state.js b/lib/rules/no-unused-state.js index 0854d0740f..2b00728bab 100644 --- a/lib/rules/no-unused-state.js +++ b/lib/rules/no-unused-state.js @@ -248,6 +248,7 @@ module.exports = { if ( !node.static || name !== 'getDerivedStateFromProps' + || !node.value || node.value.params.length < 2 // no `state` argument ) { return false; diff --git a/tests/lib/rules/no-unused-state.js b/tests/lib/rules/no-unused-state.js index d255378267..182d749c57 100644 --- a/tests/lib/rules/no-unused-state.js +++ b/tests/lib/rules/no-unused-state.js @@ -1044,6 +1044,14 @@ eslintTester.run('no-unused-state', rule, { } `, features: ['ts'], + }, + { + code: ` + class AutoControlledComponent

extends UIComponent { + static getDerivedStateFromProps: React.GetDerivedStateFromProps + } + `, + features: ['types'], } )),