From a2f8a35e2502d07d4e68e9ef6e4c0012c9e11b9a Mon Sep 17 00:00:00 2001 From: Amumu Date: Sat, 13 Nov 2021 02:38:00 +0800 Subject: [PATCH] [Fix] `no-unused-class-component-methods`: add `getChildContext` lifecycle method Fixes #3135 --- CHANGELOG.md | 2 ++ lib/rules/no-unused-class-component-methods.js | 1 + tests/lib/rules/no-unused-class-component-methods.js | 2 ++ 3 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8395d6613..dc5726045a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel ### Fixed * [`no-invalid-html-attribute`]: allow `link` `rel` to have `apple-touch-icon`, `mask-icon` ([#3132][] @ljharb) +* [`no-unused-class-component-methods`]: add `getChildContext` lifecycle method ([#3136][] @yoyo837) +[#3136]: https://github.com/yannickcr/eslint-plugin-react/pull/3136 [#3132]: https://github.com/yannickcr/eslint-plugin-react/issue/3132 ## [7.27.0] - 2021.11.09 diff --git a/lib/rules/no-unused-class-component-methods.js b/lib/rules/no-unused-class-component-methods.js index eb9b810fb1..442d29d999 100644 --- a/lib/rules/no-unused-class-component-methods.js +++ b/lib/rules/no-unused-class-component-methods.js @@ -21,6 +21,7 @@ const LIFECYCLE_METHODS = new Set([ 'componentWillReceiveProps', 'componentWillUnmount', 'componentWillUpdate', + 'getChildContext', 'getSnapshotBeforeUpdate', 'render', 'shouldComponentUpdate', diff --git a/tests/lib/rules/no-unused-class-component-methods.js b/tests/lib/rules/no-unused-class-component-methods.js index ee699413d6..dd22101067 100644 --- a/tests/lib/rules/no-unused-class-component-methods.js +++ b/tests/lib/rules/no-unused-class-component-methods.js @@ -438,6 +438,7 @@ ruleTester.run('no-unused-class-component-methods', rule, { componentDidUpdate() {} componentDidCatch() {} componentWillUnmount() {} + getChildContext() {} render() { return ; } @@ -467,6 +468,7 @@ ruleTester.run('no-unused-class-component-methods', rule, { componentDidUpdate() {}, componentDidCatch() {}, componentWillUnmount() {}, + getChildContext() {}, render() { return ; },