From 70c21f1ff3e30390466f417a0217f80e64199d34 Mon Sep 17 00:00:00 2001 From: Akul Srivastava Date: Tue, 15 Aug 2023 22:41:05 +0530 Subject: [PATCH] chore: define visitors if `checkTypes` is truthy --- lib/rules/sort-prop-types.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/rules/sort-prop-types.js b/lib/rules/sort-prop-types.js index 4a2e93551a..981633fd34 100644 --- a/lib/rules/sort-prop-types.js +++ b/lib/rules/sort-prop-types.js @@ -225,9 +225,6 @@ module.exports = { } function handleFunctionComponent(node) { - if (!checkTypes) { - return; - } const firstArg = node.params[0].typeAnnotation && node.params[0].typeAnnotation.typeAnnotation; if (firstArg && firstArg.type === 'TSTypeReference') { const propType = typeAnnotations.get(firstArg.typeName.name) @@ -252,7 +249,7 @@ module.exports = { } } - return { + return Object.assign({ CallExpression(node) { if (!sortShapeProp || !isShapeProp(node) || !(node.arguments && node.arguments[0])) { return; @@ -328,9 +325,9 @@ module.exports = { typeAnnotations.set(node.id.name, currentNode); } }, - + }, checkTypes ? { FunctionDeclaration: handleFunctionComponent, ArrowFunctionExpression: handleFunctionComponent, - }; + } : null); }, };