Skip to content

Commit

Permalink
[Fix] no-unused-state: avoid a crash on type-only gDSFP declarations
Browse files Browse the repository at this point in the history
Fixes #3225
  • Loading branch information
ljharb committed Feb 27, 2022
1 parent e972bd7 commit 9090999
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/rules/no-unused-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ module.exports = {
if (
!node.static
|| name !== 'getDerivedStateFromProps'
|| !node.value
|| node.value.params.length < 2 // no `state` argument
) {
return false;
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/rules/no-unused-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,14 @@ eslintTester.run('no-unused-state', rule, {
}
`,
features: ['ts'],
},
{
code: `
class AutoControlledComponent<P = {}, S = {}> extends UIComponent<P, S> {
static getDerivedStateFromProps: React.GetDerivedStateFromProps<any, any>
}
`,
features: ['types'],
}
)),

Expand Down

0 comments on commit 9090999

Please sign in to comment.