From c0c7befd52411d63c02bde13edf386972ffa2f09 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Mon, 5 Apr 2021 17:03:53 +1200 Subject: [PATCH] refactor: remove unneeded utils --- src/rules/utils.ts | 33 --------------------------------- src/rules/valid-describe.ts | 4 ++-- src/rules/valid-title.ts | 3 +-- 3 files changed, 3 insertions(+), 37 deletions(-) diff --git a/src/rules/utils.ts b/src/rules/utils.ts index 4e721fbe0..4cb2f1f92 100644 --- a/src/rules/utils.ts +++ b/src/rules/utils.ts @@ -794,39 +794,6 @@ export const isDescribeCall = ( return false; }; -/** - * Checks if the given node` is a call to `.each(...)()`. - * If `true`, the code must look like `.each(...)()`. - * - * @param {JestFunctionCallExpression} node - * - * @return {node is JestFunctionCallExpressionWithMemberExpressionCallee & {parent: TSESTree.CallExpression}} - */ -export const isEachCall = ( - node: JestFunctionCallExpression, -): node is JestEachCallExpression => - 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} node - * - * @return {Expression[]} - */ -export const getJestFunctionArguments = ( - node: JestFunctionCallExpression, -) => - 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(); diff --git a/src/rules/valid-describe.ts b/src/rules/valid-describe.ts index 908aa3c81..2c288e3f0 100644 --- a/src/rules/valid-describe.ts +++ b/src/rules/valid-describe.ts @@ -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[], @@ -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), diff --git a/src/rules/valid-title.ts b/src/rules/valid-title.ts index 81422e8e9..6902f1262 100644 --- a/src/rules/valid-title.ts +++ b/src/rules/valid-title.ts @@ -7,7 +7,6 @@ import { StringNode, TestCaseName, createRule, - getJestFunctionArguments, getNodeName, getStringValue, isDescribeCall, @@ -165,7 +164,7 @@ export default createRule<[Options], MessageIds>({ return; } - const [argument] = getJestFunctionArguments(node); + const [argument] = node.arguments; if (!argument) { return;