Skip to content

Commit

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

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

function hasParentMochaFunctionCall(functionExpression) {
return astUtils.isTestCase(functionExpression.parent) || astUtils.isHookCall(functionExpression.parent);
}

function reportIfShortArrowFunction(context, node) {
if (node.body.type !== 'BlockStatement') {
context.report({
Expand Down Expand Up @@ -56,7 +52,7 @@ function reportIfFunctionWithBlock(context, node, doneName) {

module.exports = function (context) {
function check(node) {
if (node.params.length === 0 || !hasParentMochaFunctionCall(node)) {
if (node.params.length === 0 || !astUtils.hasParentMochaFunctionCall(node)) {
return;
}

Expand Down
6 changes: 1 addition & 5 deletions lib/rules/no-return-from-async.js
Expand Up @@ -2,10 +2,6 @@

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

function hasParentMochaFunctionCall(functionExpression) {
return astUtils.isTestCase(functionExpression.parent) || astUtils.isHookCall(functionExpression.parent);
}

function reportIfShortArrowFunction(context, node) {
if (node.body.type !== 'BlockStatement') {
context.report({
Expand Down Expand Up @@ -50,7 +46,7 @@ function reportIfFunctionWithBlock(context, node) {

module.exports = function (context) {
function check(node) {
if (!node.async || !hasParentMochaFunctionCall(node)) {
if (!node.async || !astUtils.hasParentMochaFunctionCall(node)) {
return;
}

Expand Down
5 changes: 5 additions & 0 deletions lib/util/ast.js
Expand Up @@ -77,6 +77,10 @@ function isStringLiteral(node) {
return node && node.type === 'Literal' && typeof node.value === 'string';
}

function hasParentMochaFunctionCall(functionExpression) {
return isTestCase(functionExpression.parent) || isHookCall(functionExpression.parent);
}

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

module.exports = {
Expand All @@ -88,5 +92,6 @@ module.exports = {
isMochaFunctionCall,
isHookCall,
isStringLiteral,
hasParentMochaFunctionCall,
findReturnStatement
};

0 comments on commit 7d7eed8

Please sign in to comment.