From a09083b1ce38b7ef6704a048cf26eb96ad774d0e Mon Sep 17 00:00:00 2001 From: Mathias Stang Date: Thu, 12 Sep 2024 12:33:03 +0200 Subject: [PATCH] [Fix] `no-is-mounted`: fix logic in method name check The last change to `no-is-mounted` caused the rule to error with any method name, not just with "isMounted". --- CHANGELOG.md | 5 +++++ lib/rules/no-is-mounted.js | 3 ++- tests/lib/rules/no-is-mounted.js | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a7934cc39..a3faa4c5ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ## Unreleased +### Fixed +* [`no-is-mounted`]: fix logic in method name check ([#3821][] @Mathias-S) + +[#3821]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3821 + ## [7.36.0] - 2024.09.12 ### Added diff --git a/lib/rules/no-is-mounted.js b/lib/rules/no-is-mounted.js index 02a100251a..24d9a37d02 100644 --- a/lib/rules/no-is-mounted.js +++ b/lib/rules/no-is-mounted.js @@ -41,7 +41,8 @@ module.exports = { } if ( callee.object.type !== 'ThisExpression' - && (!('name' in callee.property) || callee.property.name !== 'isMounted') + || !('name' in callee.property) + || callee.property.name !== 'isMounted' ) { return; } diff --git a/tests/lib/rules/no-is-mounted.js b/tests/lib/rules/no-is-mounted.js index ba63e8d67e..c8b22daabb 100644 --- a/tests/lib/rules/no-is-mounted.js +++ b/tests/lib/rules/no-is-mounted.js @@ -57,6 +57,17 @@ ruleTester.run('no-is-mounted', rule, { }); `, }, + { + code: ` + class Hello extends React.Component { + notIsMounted() {} + render() { + this.notIsMounted(); + return
Hello
; + } + }; + `, + }, ]), invalid: parsers.all([