Skip to content

Commit

Permalink
[Fix] no-unused-state: avoid a crash on a class field gDSFP
Browse files Browse the repository at this point in the history
Fixes #3236.
  • Loading branch information
ljharb committed Mar 6, 2022
1 parent 24bf594 commit cdfd558
Show file tree
Hide file tree
Showing 3 changed files with 18 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 a class field gDSFP ([#3236][] @ljharb)

[#3236]: https://github.com/yannickcr/eslint-plugin-react/issues/3236

## [7.29.3] - 2022.03.03

### 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 @@ -249,6 +249,7 @@ module.exports = {
!node.static
|| name !== 'getDerivedStateFromProps'
|| !node.value
|| !node.value.params
|| node.value.params.length < 2 // no `state` argument
) {
return false;
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/rules/no-unused-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,18 @@ eslintTester.run('no-unused-state', rule, {
}
`,
features: ['types'],
},
{
code: `
export const commonMixinWrapper = ComposeComponent => class extends ComposeComponent {
static getDerivedStateFromProps = ComposeComponent.getDerivedStateFromProps;
render() { return <div />; }
}
`,
features: ['class fields'],
parserOptions: {
sourceType: 'module',
},
}
)),

Expand Down

0 comments on commit cdfd558

Please sign in to comment.