Skip to content

Commit cdfd558

Browse files
committed
[Fix] no-unused-state: avoid a crash on a class field gDSFP
Fixes #3236.
1 parent 24bf594 commit cdfd558

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
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 a class field gDSFP ([#3236][] @ljharb)
10+
11+
[#3236]: https://github.com/yannickcr/eslint-plugin-react/issues/3236
12+
813
## [7.29.3] - 2022.03.03
914

1015
### Fixed

lib/rules/no-unused-state.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ module.exports = {
249249
!node.static
250250
|| name !== 'getDerivedStateFromProps'
251251
|| !node.value
252+
|| !node.value.params
252253
|| node.value.params.length < 2 // no `state` argument
253254
) {
254255
return false;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,18 @@ eslintTester.run('no-unused-state', rule, {
10521052
}
10531053
`,
10541054
features: ['types'],
1055+
},
1056+
{
1057+
code: `
1058+
export const commonMixinWrapper = ComposeComponent => class extends ComposeComponent {
1059+
static getDerivedStateFromProps = ComposeComponent.getDerivedStateFromProps;
1060+
render() { return <div />; }
1061+
}
1062+
`,
1063+
features: ['class fields'],
1064+
parserOptions: {
1065+
sourceType: 'module',
1066+
},
10551067
}
10561068
)),
10571069

0 commit comments

Comments
 (0)