From 071371867e435bd2aae9e133032d9488667ecc45 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 12 Nov 2020 14:13:55 +0100 Subject: [PATCH] Revert "fix(no-done-callback): fix regression with it.each (#708)" This reverts commit 2f032f8d890e3717359d099b1e93e0cc6b52996a. --- src/rules/__tests__/no-done-callback.test.ts | 44 -------------------- src/rules/no-done-callback.ts | 23 ++-------- 2 files changed, 4 insertions(+), 63 deletions(-) diff --git a/src/rules/__tests__/no-done-callback.test.ts b/src/rules/__tests__/no-done-callback.test.ts index d91c19d28..f4fc63903 100644 --- a/src/rules/__tests__/no-done-callback.test.ts +++ b/src/rules/__tests__/no-done-callback.test.ts @@ -15,10 +15,6 @@ ruleTester.run('no-done-callback', rule, { 'test("something", () => {})', 'test("something", async () => {})', 'test("something", function() {})', - 'test.each``("something", ({ a, b }) => {})', - 'test.each()("something", ({ a, b }) => {})', - 'it.each()("something", ({ a, b }) => {})', - 'it.each``("something", ({ a, b }) => {})', 'test("something", async function () {})', 'test("something", someArg)', 'beforeEach(() => {})', @@ -389,45 +385,5 @@ ruleTester.run('no-done-callback', rule, { }, ], }, - { - code: 'test.each``("something", ({ a, b }, done) => { done(); })', - errors: [ - { - messageId: 'noDoneCallback', - line: 1, - column: 37, - }, - ], - }, - { - code: 'test.each()("something", ({ a, b }, done) => { done(); })', - errors: [ - { - messageId: 'noDoneCallback', - line: 1, - column: 37, - }, - ], - }, - { - code: 'it.each``("something", ({ a, b }, done) => { done(); })', - errors: [ - { - messageId: 'noDoneCallback', - line: 1, - column: 35, - }, - ], - }, - { - code: 'it.each()("something", ({ a, b }, done) => { done(); })', - errors: [ - { - messageId: 'noDoneCallback', - line: 1, - column: 35, - }, - ], - }, ], }); diff --git a/src/rules/no-done-callback.ts b/src/rules/no-done-callback.ts index 345722dae..70fde6caa 100644 --- a/src/rules/no-done-callback.ts +++ b/src/rules/no-done-callback.ts @@ -2,22 +2,11 @@ import { AST_NODE_TYPES, TSESTree, } from '@typescript-eslint/experimental-utils'; -import { - createRule, - getNodeName, - isFunction, - isHook, - isTestCase, -} from './utils'; +import { createRule, isFunction, isHook, isTestCase } from './utils'; const findCallbackArg = ( node: TSESTree.CallExpression, - isJestEach: boolean, ): TSESTree.CallExpression['arguments'][0] | null => { - if (isJestEach) { - return node.arguments[1]; - } - if (isHook(node) && node.arguments.length >= 1) { return node.arguments[0]; } @@ -52,21 +41,17 @@ export default createRule({ create(context) { return { CallExpression(node) { - // done is the second argument for it.each, not the first - const isJestEach = getNodeName(node.callee)?.endsWith('.each') ?? false; - - const callback = findCallbackArg(node, isJestEach); - const callbackArgIndex = Number(isJestEach); + const callback = findCallbackArg(node); if ( !callback || !isFunction(callback) || - callback.params.length !== 1 + callbackArgIndex + callback.params.length !== 1 ) { return; } - const argument = callback.params[callbackArgIndex]; + const [argument] = callback.params; if (argument.type !== AST_NODE_TYPES.Identifier) { context.report({