Skip to content

Commit 5985656

Browse files
committed
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
1 parent f761be2 commit 5985656

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/core/namespaceValidator.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ export default function namespaceValidator(
1212
// go deep
1313
let namespace = namespaces.get(node.object.name);
1414
const namepath = [node.object.name];
15+
const returnChecker = 510; // callbacks return this value if they want THIS function to stop executing
1516
// while property is namespace and parent is member expression, keep validating
1617
while (namespace instanceof Exports && node.type === 'MemberExpression') {
1718
if (node.computed) {
18-
if (onComputed(node) === 'return') {
19+
if (onComputed(node, returnChecker) === returnChecker) {
1920
return;
2021
}
2122
}
2223

2324
if (onNamespaceNotFound) {
24-
if (onNamespaceNotFound(node, namespace, namepath) === 'return') {
25+
if (onNamespaceNotFound(node, namespace, namepath, returnChecker) === returnChecker) {
2526
return;
2627
}
2728
}

src/rules/namespace.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,25 @@ module.exports = {
118118
}
119119

120120
function onComputed(context, allowComputed){
121-
return function innerOnComputed(node) {
121+
return function innerOnComputed(node, returnChecker) {
122122
if (!allowComputed) {
123123
context.report(
124124
node.property,
125125
`Unable to validate computed reference to imported namespace '${dereference.object.name}'.`,
126126
);
127127
}
128-
return 'return';
128+
return returnChecker;
129129
};
130130
}
131131

132132
function onNamespaceNotFound(context) {
133-
return function inner(node, namespace, namepath) {
133+
return function inner(node, namespace, namepath, returnChecker) {
134134
if (!namespace.has(node.property.name)) {
135135
context.report(
136136
node.property,
137137
makeMessage(node.property, namepath),
138138
);
139-
return 'return';
139+
return returnChecker;
140140
}
141141
};
142142
}

src/rules/no-deprecated.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ module.exports = {
122122

123123
function onComputed() {
124124
// ignore computed parts for now
125-
return 'return';
125+
return arguments[2];
126126
}
127127

128128
namespaceValidator(

0 commit comments

Comments
 (0)