Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vitest-dev/eslint-plugin-vitest
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.3.15
Choose a base ref
...
head repository: vitest-dev/eslint-plugin-vitest
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.3.16
Choose a head ref
  • 2 commits
  • 4 files changed
  • 2 contributors

Commits on Dec 11, 2023

  1. Copy the full SHA
    65e8cef View commit details
  2. chore: release v0.3.16

    veritem committed Dec 11, 2023
    Copy the full SHA
    d71c88c View commit details
Showing with 34 additions and 6 deletions.
  1. +14 −0 docs/rules/no-done-callback.md
  2. +1 −1 package.json
  3. +16 −4 src/rules/no-done-callback.ts
  4. +3 −1 tests/no-done-callback.test.ts
14 changes: 14 additions & 0 deletions docs/rules/no-done-callback.md
Original file line number Diff line number Diff line change
@@ -56,4 +56,18 @@ test('foo', async () => {
resolve()
}, 1000))
})

test.concurrent('foo', ({ expect }) => {
expect(1).toMatchSnapshot();
});

test.concurrent('foo', (context) => {
context.expect(1).toBe(1);
});

describe.concurrent('foo', () => {
test('foo', ({ expect }) => {
expect(1).toBe(1);
});
});
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-vitest",
"version": "0.3.15",
"version": "0.3.16",
"license": "MIT",
"description": "Eslint plugin for vitest",
"repository": "veritem/eslint-plugin-vitest",
20 changes: 16 additions & 4 deletions src/rules/no-done-callback.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TSESLint, AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils'
import { createEslintRule, getNodeName, isFunction } from '../utils'
import { parseVitestFnCall } from '../utils/parseVitestFnCall'
import { createEslintRule, getNodeName, isFunction, isSupportedAccessor } from '../utils'
import { isTypeOfVitestFnCall, parseVitestFnCall } from '../utils/parseVitestFnCall'

export const RULE_NAME = 'no-done-callback'
export type MessageIds = 'noDoneCallback' | 'suggestWrappingInPromise' | 'useAwaitInsteadOfCallback';
@@ -46,8 +46,20 @@ export default createEslintRule<Options, MessageIds>({
if (isVitestEach && node.callee.type !== AST_NODE_TYPES.TaggedTemplateExpression)
return

const isVitestConcurrent = getNodeName(node.callee)?.endsWith('.concurrent') ?? false
if (isVitestConcurrent) return
const isInsideConcurrentTestOrDescribe = context.getAncestors().some((ancestor) => {
if (ancestor.type !== AST_NODE_TYPES.CallExpression) return false

const isNotInsideDescribeOrTest = !isTypeOfVitestFnCall(ancestor, context, ['describe', 'test'])
if (isNotInsideDescribeOrTest) return false

const isTestRunningConcurrently =
ancestor.callee.type === AST_NODE_TYPES.MemberExpression &&
isSupportedAccessor(ancestor.callee.property, 'concurrent')

return isTestRunningConcurrently
})

if (isInsideConcurrentTestOrDescribe) return;

const callback = findCallbackArg(node, isVitestEach, context)
const callbackArgIndex = Number(isVitestEach)
4 changes: 3 additions & 1 deletion tests/no-done-callback.test.ts
Original file line number Diff line number Diff line change
@@ -21,7 +21,9 @@ ruleTester.run(RULE_NAME, rule, {
'beforeAll(async () => {})',
'afterAll(() => {})',
'afterAll(async function () {})',
'afterAll(async function () {}, 5)'
'afterAll(async function () {}, 5)',
'describe.concurrent("something", () => { it("something", ({ expect }) => { }) })',
'describe.concurrent("something", () => { it("something", context => { }) })'
],
invalid: [
{