Skip to content

Commit

Permalink
refactor: remove unneeded utils
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Apr 10, 2021
1 parent 6acf878 commit c0c7bef
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 37 deletions.
33 changes: 0 additions & 33 deletions src/rules/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,39 +794,6 @@ export const isDescribeCall = (
return false;
};

/**
* Checks if the given node` is a call to `<describe|test|it>.each(...)()`.
* If `true`, the code must look like `<method>.each(...)()`.
*
* @param {JestFunctionCallExpression<DescribeAlias | TestCaseName>} node
*
* @return {node is JestFunctionCallExpressionWithMemberExpressionCallee<DescribeAlias | TestCaseName, DescribeProperty.each | TestCaseProperty.each> & {parent: TSESTree.CallExpression}}
*/
export const isEachCall = (
node: JestFunctionCallExpression<DescribeAlias | TestCaseName>,
): node is JestEachCallExpression<DescribeAlias | TestCaseName> =>
getNodeName(node).endsWith('each');

/**
* Gets the arguments of the given `JestFunctionCallExpression`.
*
* If the `node` is an `each` call, then the arguments of the actual suite
* are returned, rather then the `each` array argument.
*
* @param {JestFunctionCallExpression<DescribeAlias | TestCaseName>} node
*
* @return {Expression[]}
*/
export const getJestFunctionArguments = (
node: JestFunctionCallExpression<DescribeAlias | TestCaseName>,
) =>
node.callee.type === AST_NODE_TYPES.MemberExpression &&
isSupportedAccessor(node.callee.property, DescribeProperty.each) &&
node.parent &&
node.parent.type === AST_NODE_TYPES.CallExpression
? node.parent.arguments
: node.arguments;

const collectReferences = (scope: TSESLint.Scope.Scope) => {
const locals = new Set();
const unresolved = new Set();
Expand Down
4 changes: 2 additions & 2 deletions src/rules/valid-describe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
AST_NODE_TYPES,
TSESTree,
} from '@typescript-eslint/experimental-utils';
import { createRule, isDescribeCall, isEachCall, isFunction } from './utils';
import { createRule, getNodeName, isDescribeCall, isFunction } from './utils';

const paramsLocation = (
params: TSESTree.Expression[] | TSESTree.Parameter[],
Expand Down Expand Up @@ -77,7 +77,7 @@ export default createRule({
});
}

if (!isEachCall(node) && callback.params.length) {
if (!getNodeName(node).endsWith('each') && callback.params.length) {
context.report({
messageId: 'unexpectedDescribeArgument',
loc: paramsLocation(callback.params),
Expand Down
3 changes: 1 addition & 2 deletions src/rules/valid-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
StringNode,
TestCaseName,
createRule,
getJestFunctionArguments,
getNodeName,
getStringValue,
isDescribeCall,
Expand Down Expand Up @@ -165,7 +164,7 @@ export default createRule<[Options], MessageIds>({
return;
}

const [argument] = getJestFunctionArguments(node);
const [argument] = node.arguments;

if (!argument) {
return;
Expand Down

0 comments on commit c0c7bef

Please sign in to comment.