Skip to content

Conversation

@figueiredoluiz
Copy link
Contributor

Closes #702

Add vitest/consistent-each-for rule to enforce consistent usage of .each or .for for parameterized tests across test, it, describe, and suite functions.

  {
    'vitest/consistent-each-for': ['warn', { test: 'for', describe: 'each' }]
  }

Comment on lines 7 to 8
export type EachOrFor = 'each' | 'for'
export type BaseFnName = 'test' | 'it' | 'describe' | 'suite'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you have any reason to why these are exported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right - these are only used internally. I've removed the exports to match the pattern I see in consistent-test-it and other rules. Thanks for pointing that out!

{
name: 'test.only.each when configured to prefer each',
code: 'test.only.each([1, 2, 3])("test", (n) => { expect(n).toBeDefined() })',
options: [{ test: 'each' as const }],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these marked const? I'm curious?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized it's unnecessary here - TypeScript already infers the literal types correctly since the values match the union type. Removed all instances.

Copy link
Member

@veritem veritem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@veritem veritem merged commit db570c8 into vitest-dev:main Nov 24, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

proposal: add vitest/prefer-for rule

2 participants