Skip to content

Commit 9090999

Browse files
committed
[Fix] no-unused-state: avoid a crash on type-only gDSFP declarations
Fixes #3225
1 parent e972bd7 commit 9090999

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
55

66
## Unreleased
77

8+
### Fixed
9+
* [`no-unused-state`]: avoid a crash on type-only gDSFP declarations ([#3225][] @ljharb)
10+
11+
[#3225]: https://github.com/yannickcr/eslint-plugin-react/issues/3225
12+
813
## [7.29.2] - 2022.02.25
914

1015
### Fixed

lib/rules/no-unused-state.js

+1
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ module.exports = {
248248
if (
249249
!node.static
250250
|| name !== 'getDerivedStateFromProps'
251+
|| !node.value
251252
|| node.value.params.length < 2 // no `state` argument
252253
) {
253254
return false;

tests/lib/rules/no-unused-state.js

+8
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,14 @@ eslintTester.run('no-unused-state', rule, {
10441044
}
10451045
`,
10461046
features: ['ts'],
1047+
},
1048+
{
1049+
code: `
1050+
class AutoControlledComponent<P = {}, S = {}> extends UIComponent<P, S> {
1051+
static getDerivedStateFromProps: React.GetDerivedStateFromProps<any, any>
1052+
}
1053+
`,
1054+
features: ['types'],
10471055
}
10481056
)),
10491057

0 commit comments

Comments
 (0)