From 5985656c1dcd2f738f3fb222cce772a9aa58d77f Mon Sep 17 00:00:00 2001 From: Aziz Abdullaev Date: Tue, 1 Nov 2022 22:58:04 -0400 Subject: [PATCH] refactor abortion process in namespaceValidator, namespace, no-deprecated rule Helper function namespaceValidator needs to stop executing depending on callback functions. Because callback functions coming from namespace, no-deprecated rules cannot stop execution due to scope, I added a statement which is passed from namespaceValidator to the callback functions received from namespace and no-deprecated rules, and if callback functions want to stop execution, then they return the same statement and namespaceValidator stops execution --- src/core/namespaceValidator.js | 5 +++-- src/rules/namespace.js | 8 ++++---- src/rules/no-deprecated.js | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/core/namespaceValidator.js b/src/core/namespaceValidator.js index e39f69a0f0..b1141840b5 100644 --- a/src/core/namespaceValidator.js +++ b/src/core/namespaceValidator.js @@ -12,16 +12,17 @@ export default function namespaceValidator( // go deep let namespace = namespaces.get(node.object.name); const namepath = [node.object.name]; + const returnChecker = 510; // callbacks return this value if they want THIS function to stop executing // while property is namespace and parent is member expression, keep validating while (namespace instanceof Exports && node.type === 'MemberExpression') { if (node.computed) { - if (onComputed(node) === 'return') { + if (onComputed(node, returnChecker) === returnChecker) { return; } } if (onNamespaceNotFound) { - if (onNamespaceNotFound(node, namespace, namepath) === 'return') { + if (onNamespaceNotFound(node, namespace, namepath, returnChecker) === returnChecker) { return; } } diff --git a/src/rules/namespace.js b/src/rules/namespace.js index eb99131129..f000105c85 100644 --- a/src/rules/namespace.js +++ b/src/rules/namespace.js @@ -118,25 +118,25 @@ module.exports = { } function onComputed(context, allowComputed){ - return function innerOnComputed(node) { + return function innerOnComputed(node, returnChecker) { if (!allowComputed) { context.report( node.property, `Unable to validate computed reference to imported namespace '${dereference.object.name}'.`, ); } - return 'return'; + return returnChecker; }; } function onNamespaceNotFound(context) { - return function inner(node, namespace, namepath) { + return function inner(node, namespace, namepath, returnChecker) { if (!namespace.has(node.property.name)) { context.report( node.property, makeMessage(node.property, namepath), ); - return 'return'; + return returnChecker; } }; } diff --git a/src/rules/no-deprecated.js b/src/rules/no-deprecated.js index c0ec408165..18abc29555 100644 --- a/src/rules/no-deprecated.js +++ b/src/rules/no-deprecated.js @@ -122,7 +122,7 @@ module.exports = { function onComputed() { // ignore computed parts for now - return 'return'; + return arguments[2]; } namespaceValidator(