Skip to content

Commit

Permalink
Revert "fix(no-done-callback): fix regression with it.each (#708)"
Browse files Browse the repository at this point in the history
This reverts commit 2f032f8.
  • Loading branch information
SimenB committed Nov 12, 2020
1 parent fe80f2f commit 0713718
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 63 deletions.
44 changes: 0 additions & 44 deletions src/rules/__tests__/no-done-callback.test.ts
Expand Up @@ -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(() => {})',
Expand Down Expand Up @@ -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,
},
],
},
],
});
23 changes: 4 additions & 19 deletions src/rules/no-done-callback.ts
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 0713718

Please sign in to comment.