diff --git a/lib/rules/no-return-and-callback.js b/lib/rules/no-return-and-callback.js index 7d6a26c..bc1198a 100644 --- a/lib/rules/no-return-and-callback.js +++ b/lib/rules/no-return-and-callback.js @@ -13,17 +13,6 @@ function reportIfShortArrowFunction(context, node) { return false; } -function isExplicitUndefined(node) { - return node && node.type === 'Identifier' && node.name === 'undefined'; -} - -function isReturnOfUndefined(node) { - const argument = node.argument; - const isImplicitUndefined = argument === null; - - return isImplicitUndefined || isExplicitUndefined(argument); -} - function isFunctionCallWithName(node, name) { return node.type === 'CallExpression' && node.callee.type === 'Identifier' && @@ -33,7 +22,7 @@ function isFunctionCallWithName(node, name) { function isAllowedReturnStatement(node, doneName) { const argument = node.argument; - if (isReturnOfUndefined(node) || argument.type === 'Literal') { + if (astUtils.isReturnOfUndefined(node) || argument.type === 'Literal') { return true; } diff --git a/lib/rules/no-return-from-async.js b/lib/rules/no-return-from-async.js index 750b3ad..9fa453d 100644 --- a/lib/rules/no-return-from-async.js +++ b/lib/rules/no-return-from-async.js @@ -13,21 +13,10 @@ function reportIfShortArrowFunction(context, node) { return false; } -function isExplicitUndefined(node) { - return node && node.type === 'Identifier' && node.name === 'undefined'; -} - -function isReturnOfUndefined(node) { - const argument = node.argument; - const isImplicitUndefined = argument === null; - - return isImplicitUndefined || isExplicitUndefined(argument); -} - function isAllowedReturnStatement(node) { const argument = node.argument; - if (isReturnOfUndefined(node) || argument.type === 'Literal') { + if (astUtils.isReturnOfUndefined(node) || argument.type === 'Literal') { return true; } diff --git a/lib/util/ast.js b/lib/util/ast.js index e03263b..88d3063 100644 --- a/lib/util/ast.js +++ b/lib/util/ast.js @@ -81,6 +81,17 @@ function hasParentMochaFunctionCall(functionExpression) { return isTestCase(functionExpression.parent) || isHookCall(functionExpression.parent); } +function isExplicitUndefined(node) { + return node && node.type === 'Identifier' && node.name === 'undefined'; +} + +function isReturnOfUndefined(node) { + const argument = node.argument; + const isImplicitUndefined = argument === null; + + return isImplicitUndefined || isExplicitUndefined(argument); +} + const findReturnStatement = R.find(R.propEq('type', 'ReturnStatement')); module.exports = { @@ -93,5 +104,6 @@ module.exports = { isHookCall, isStringLiteral, hasParentMochaFunctionCall, - findReturnStatement + findReturnStatement, + isReturnOfUndefined };