From cdfd55836fc8a667c97448dc040de2a535ba5267 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Mar 2022 12:44:04 -0800 Subject: [PATCH] [Fix] `no-unused-state`: avoid a crash on a class field gDSFP Fixes #3236. --- CHANGELOG.md | 5 +++++ lib/rules/no-unused-state.js | 1 + tests/lib/rules/no-unused-state.js | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2733092286..03d9a3dbbd 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 a class field gDSFP ([#3236][] @ljharb) + +[#3236]: https://github.com/yannickcr/eslint-plugin-react/issues/3236 + ## [7.29.3] - 2022.03.03 ### Fixed diff --git a/lib/rules/no-unused-state.js b/lib/rules/no-unused-state.js index 2b00728bab..cf8cbf917f 100644 --- a/lib/rules/no-unused-state.js +++ b/lib/rules/no-unused-state.js @@ -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; diff --git a/tests/lib/rules/no-unused-state.js b/tests/lib/rules/no-unused-state.js index 182d749c57..8c06060c3c 100644 --- a/tests/lib/rules/no-unused-state.js +++ b/tests/lib/rules/no-unused-state.js @@ -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
; } + } + `, + features: ['class fields'], + parserOptions: { + sourceType: 'module', + }, } )),