From 2bf54d732f167d7ed41b5fdbd8309e4834f73267 Mon Sep 17 00:00:00 2001 From: Chiawen Chen Date: Sat, 16 Apr 2022 11:18:58 +0800 Subject: [PATCH] [Refactor] `no-*-set-state`: improve performance --- CHANGELOG.md | 2 ++ lib/util/makeNoMethodSetStateRule.js | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13182296ca..e3f1f80580 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange * [Refactor] improve performance for detecting function components ([#3265][] @golopot) * [Refactor] improve performance for detecting class components ([#3267][] @golopot) * [Refactor] [`no-deprecated`]: improve performance ([#3271][] @golopot) +* [Refactor] [`no-did-mount-set-state`], [`no-did-update-set-state`], [`no-will-update-set-state`]: improve performance ([#3272][] @golopot) +[#3272]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3272 [#3271]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3271 [#3267]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3267 [#3266]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3266 diff --git a/lib/util/makeNoMethodSetStateRule.js b/lib/util/makeNoMethodSetStateRule.js index f1be5c16ae..23346a9a6b 100644 --- a/lib/util/makeNoMethodSetStateRule.js +++ b/lib/util/makeNoMethodSetStateRule.js @@ -73,16 +73,16 @@ module.exports = function makeNoMethodSetStateRule(methodName, shouldCheckUnsafe return false; } + if (shouldBeNoop(context, methodName)) { + return {}; + } + // -------------------------------------------------------------------------- // Public // -------------------------------------------------------------------------- return { CallExpression(node) { - if (shouldBeNoop(context, methodName)) { - return; - } - const callee = node.callee; if ( callee.type !== 'MemberExpression'