> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# prefer-each

[Added in v0.8.2](https://github.com/web-infra-dev/rslint/releases/tag/v0.8.2)
## Configuration

| Preset                     | Configured Value |
| -------------------------- | ---------------- |
| ✅ rstestPlugin.configs.all | `"warn"`         |


```ts title=rslint.config.ts
import { defineConfig, rstestPlugin } from '@rslint/core';

export default defineConfig([
  rstestPlugin.configs.recommended,
  {
    rules: {
      'rstest/prefer-each': 'error',
    },
  },
]);
```

## Rule Details

Prefers parameterized Rstest registrations over manually registering tests, suites, or hooks inside a loop. `.each` keeps related cases together in test output and gives each case a clear title.

Loops used as ordinary test logic are allowed. When a loop registers one test, the diagnostic recommends `test.each` or `it.each`; loops that register suites, hooks, or several entries recommend `describe.each`.

## Incorrect

```ts
for (const input of [1, 2, 3]) {
  test(`doubles ${input}`, () => {
    expect(double(input)).toBe(input * 2);
  });
}
```

## Correct

```ts
test.each([1, 2, 3])('doubles %i', (input) => {
  expect(double(input)).toBe(input * 2);
});
```
