Skip to content

Commit

Permalink
Move findReturnStatement into astUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Jul 16, 2019
1 parent a548690 commit c4928ab
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
5 changes: 1 addition & 4 deletions lib/rules/no-return-and-callback.js
@@ -1,10 +1,7 @@
'use strict';

const R = require('ramda');
const astUtils = require('../util/ast');

const findReturnStatement = R.find(R.propEq('type', 'ReturnStatement'));

function hasParentMochaFunctionCall(functionExpression) {
return astUtils.isTestCase(functionExpression.parent) || astUtils.isHookCall(functionExpression.parent);
}
Expand Down Expand Up @@ -48,7 +45,7 @@ function isAllowedReturnStatement(node, doneName) {
}

function reportIfFunctionWithBlock(context, node, doneName) {
const returnStatement = findReturnStatement(node.body.body);
const returnStatement = astUtils.findReturnStatement(node.body.body);
if (returnStatement && !isAllowedReturnStatement(returnStatement, doneName)) {
context.report({
node: returnStatement,
Expand Down
5 changes: 1 addition & 4 deletions lib/rules/no-return-from-async.js
@@ -1,10 +1,7 @@
'use strict';

const R = require('ramda');
const astUtils = require('../util/ast');

const findReturnStatement = R.find(R.propEq('type', 'ReturnStatement'));

function hasParentMochaFunctionCall(functionExpression) {
return astUtils.isTestCase(functionExpression.parent) || astUtils.isHookCall(functionExpression.parent);
}
Expand Down Expand Up @@ -42,7 +39,7 @@ function isAllowedReturnStatement(node) {
}

function reportIfFunctionWithBlock(context, node) {
const returnStatement = findReturnStatement(node.body.body);
const returnStatement = astUtils.findReturnStatement(node.body.body);
if (returnStatement && !isAllowedReturnStatement(returnStatement)) {
context.report({
node: returnStatement,
Expand Down
5 changes: 4 additions & 1 deletion lib/util/ast.js
Expand Up @@ -77,6 +77,8 @@ function isStringLiteral(node) {
return node && node.type === 'Literal' && typeof node.value === 'string';
}

const findReturnStatement = R.find(R.propEq('type', 'ReturnStatement'));

module.exports = {
isDescribe,
isHookIdentifier,
Expand All @@ -85,5 +87,6 @@ module.exports = {
getNodeName,
isMochaFunctionCall,
isHookCall,
isStringLiteral
isStringLiteral,
findReturnStatement
};

0 comments on commit c4928ab

Please sign in to comment.