Skip to content

Commit

Permalink
Move isReturnOfUndefined into astUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Jul 16, 2019
1 parent 7d7eed8 commit 8085bfe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
13 changes: 1 addition & 12 deletions lib/rules/no-return-and-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' &&
Expand All @@ -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;
}

Expand Down
13 changes: 1 addition & 12 deletions lib/rules/no-return-from-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
14 changes: 13 additions & 1 deletion lib/util/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -93,5 +104,6 @@ module.exports = {
isHookCall,
isStringLiteral,
hasParentMochaFunctionCall,
findReturnStatement
findReturnStatement,
isReturnOfUndefined
};

0 comments on commit 8085bfe

Please sign in to comment.