Skip to content

Commit

Permalink
Dedupe two more occurrences of hasParentMochaFunctionCall
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Jul 16, 2019
1 parent 8085bfe commit bdc4b70
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
6 changes: 1 addition & 5 deletions lib/rules/handle-done-callback.js
Expand Up @@ -4,10 +4,6 @@ const R = require('ramda');
const astUtils = require('../util/ast');

module.exports = function (context) {
function hasParentMochaFunctionCall(functionExpression) {
return astUtils.isTestCase(functionExpression.parent) || astUtils.isHookCall(functionExpression.parent);
}

function isAsyncFunction(functionExpression) {
return functionExpression.params.length === 1;
}
Expand Down Expand Up @@ -40,7 +36,7 @@ module.exports = function (context) {
}

function check(node) {
if (hasParentMochaFunctionCall(node) && isAsyncFunction(node)) {
if (astUtils.hasParentMochaFunctionCall(node) && isAsyncFunction(node)) {
checkAsyncMochaFunction(node);
}
}
Expand Down
7 changes: 1 addition & 6 deletions lib/rules/no-synchronous-tests.js
Expand Up @@ -5,11 +5,6 @@ const astUtil = require('../util/ast');

const asyncMethods = [ 'async', 'callback', 'promise' ];

function hasParentMochaFunctionCall(functionExpression) {
return astUtil.isTestCase(functionExpression.parent) ||
astUtil.isHookIdentifier(functionExpression.parent.callee);
}

function hasAsyncCallback(functionExpression) {
return functionExpression.params.length === 1;
}
Expand Down Expand Up @@ -44,7 +39,7 @@ module.exports = function (context) {
const allowedAsyncMethods = R.isNil(options.allowed) ? asyncMethods : options.allowed;

function check(node) {
if (hasParentMochaFunctionCall(node)) {
if (astUtil.hasParentMochaFunctionCall(node)) {
// For each allowed async test method, check if it is used in the test
const testAsyncMethods = allowedAsyncMethods.map(function (method) {
switch (method) {
Expand Down

0 comments on commit bdc4b70

Please sign in to comment.