Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .eslint-doc-generatorrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import prettier from 'prettier'

/** @type {import('eslint-doc-generator').GenerateOptions} */
const config = {
ignoreConfig: ['legacy-all', 'legacy-recommended'],
postprocess: async (content, path) =>
prettier.format(content, {
...(await prettier.resolveConfig(path)),
parser: 'markdown',
}),
ruleDocTitleFormat: 'name',
}

export default config
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@ jobs:
- name: lint code
run: pnpm lint:js

- name: lint docs
run: pnpm lint:eslint-docs

- name: test
run: pnpm test:ci
187 changes: 93 additions & 94 deletions README.md

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions docs/rules/consistent-test-filename.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Require .spec test file pattern (`vitest/consistent-test-filename`)

⚠️ This rule _warns_ in the 🌐 `all` config.
# consistent-test-filename

<!-- end auto-generated rule header -->

Expand Down
60 changes: 27 additions & 33 deletions docs/rules/consistent-test-it.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Enforce using test or it but not both (`vitest/consistent-test-it`)

⚠️ This rule _warns_ in the 🌐 `all` config.
# consistent-test-it

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand All @@ -12,48 +10,42 @@ Examples of **incorrect** code for this rule:

```js
test('it works', () => {
// ...
// ...
})

it('it works', () => {
// ...
// ...
})
```

Examples of **correct** code for this rule:

```js
test('it works', () => {
// ...
// ...
})
```

```js
test('it works', () => {
// ...
// ...
})
```

#### Options

```json
{
"type":"object",
"properties":{
"fn":{
"enum":[
"it",
"test"
]
},
"withinDescribe":{
"enum":[
"it",
"test"
]
}
},
"additionalProperties":false
"type": "object",
"properties": {
"fn": {
"enum": ["it", "test"]
},
"withinDescribe": {
"enum": ["it", "test"]
}
},
"additionalProperties": false
}
```

Expand All @@ -68,23 +60,25 @@ Decides whether to prefer `test` or `it` when used within a `describe` block.
```js
/*eslint vitest/consistent-test-it: ["error", {"fn": "test"}]*/

test('it works', () => { // <-- Valid
// ...
test('it works', () => {
// <-- Valid
// ...
})

test.only('it works', () => { // <-- Valid
// ...
test.only('it works', () => {
// <-- Valid
// ...
})


it('it works', () => { // <-- Invalid
// ...
it('it works', () => {
// <-- Invalid
// ...
})

it.only('it works', () => { // <-- Invalid
// ...
it.only('it works', () => {
// <-- Invalid
// ...
})
```

The default configuration is top level `test` and all tests nested with `describe` to use `it`.

33 changes: 14 additions & 19 deletions docs/rules/consistent-vitest-vi.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Enforce using vitest or vi but not both (`vitest/consistent-vitest-vi`)

⚠️ This rule _warns_ in the 🌐 `all` config.
# consistent-vitest-vi

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand All @@ -11,39 +9,36 @@
Examples of **incorrect** code for this rule:

```js
vitest.mock('./src/calculator.ts', { spy: true });
vitest.mock('./src/calculator.ts', { spy: true })

vi.stubEnv('NODE_ENV', 'production');
vi.stubEnv('NODE_ENV', 'production')
```

Examples of **correct** code for this rule:

```js
vi.mock('./src/calculator.ts', { spy: true });
vi.mock('./src/calculator.ts', { spy: true })

vi.stubEnv('NODE_ENV', 'production');
vi.stubEnv('NODE_ENV', 'production')
```

```js
vitest.mock('./src/calculator.ts', { spy: true });
vitest.mock('./src/calculator.ts', { spy: true })

vitest.stubEnv('NODE_ENV', 'production');
vitest.stubEnv('NODE_ENV', 'production')
```

## Options

```json
{
"type":"object",
"properties":{
"fn":{
"enum":[
"vi",
"vitest"
]
}
},
"additionalProperties":false
"type": "object",
"properties": {
"fn": {
"enum": ["vi", "vitest"]
}
},
"additionalProperties": false
}
```

Expand Down
18 changes: 5 additions & 13 deletions docs/rules/expect-expect.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# Enforce having expectation in test body (`vitest/expect-expect`)

💼 This rule is enabled in the ✅ `recommended` config.

⚠️ This rule _warns_ in the 🌐 `all` config.
# expect-expect

<!-- end auto-generated rule header -->


## Rule Details

This rule aims to enforce having at least one expectation in test body to ensure that the test is actually testing something.
Expand All @@ -15,7 +10,7 @@ Examples of **incorrect** code for this rule:

```js
test('myLogic', () => {
console.log('myLogic')
console.log('myLogic')
})

test('myLogic', () => {})
Expand Down Expand Up @@ -52,20 +47,17 @@ If you're using Vitest's [type-testing feature](https://vitest.dev/guide/testing

An array of strings that are the names of the functions that are used for assertions. Function names can also be wildcard patterns like `expect*`,`function.**.expect` or `expect.anything`.


The following is an example of correct code for this rule with the option `assertFunctionNames`:

```js
import CheckForMe from 'check-for-me'
test('myLogic', () => {
expect("myLogic").toBe("myOutput")
expect('myLogic').toBe('myOutput')
})
```


### `additionalTestBlockFunctions`


```json
{
"rules": {
Expand All @@ -85,8 +77,8 @@ The following is an example of correct code for this rule with the option `addit
import CheckForMe from 'check-for-me'
checkForMe('myLogic', () => {
checkForMe('myLogic', () => {
const actual = myLogic()
expect(actual).toBe(true)
const actual = myLogic()
expect(actual).toBe(true)
})
})
```
4 changes: 1 addition & 3 deletions docs/rules/max-expects.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Enforce a maximum number of expect per test (`vitest/max-expects`)

⚠️ This rule _warns_ in the 🌐 `all` config.
# max-expects

<!-- end auto-generated rule header -->

Expand Down
14 changes: 6 additions & 8 deletions docs/rules/max-nested-describe.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Require describe block to be less than set max value or default value (`vitest/max-nested-describe`)

⚠️ This rule _warns_ in the 🌐 `all` config.
# max-nested-describe

<!-- end auto-generated rule header -->

Expand All @@ -10,17 +8,17 @@ Examples of **incorrect** code for this rule with `max: 1`:

```js
describe('outer', () => {
describe('inner', () => {
// ...
})
describe('inner', () => {
// ...
})
})
```

Examples of **correct** code for this rule:

```js
describe('inner', () => {
// ...
// ...
})
```

Expand All @@ -32,6 +30,6 @@ Maximum number of nested `describe` blocks.

```js
{
max: number
max: number
}
```
6 changes: 1 addition & 5 deletions docs/rules/no-alias-methods.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# Disallow alias methods (`vitest/no-alias-methods`)

⚠️ This rule _warns_ in the 🌐 `all` config.
# no-alias-methods

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

<!-- end auto-generated rule header -->


## Rule Details

This rule disallows alias methods and forces the use of the original method.
Expand All @@ -21,7 +18,6 @@ expect(a).toBeCalled()
expect(a).toBeCalledTimes(1)
```


Examples of **correct** code for this rule:

```js
Expand Down
6 changes: 1 addition & 5 deletions docs/rules/no-commented-out-tests.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# Disallow commented out tests (`vitest/no-commented-out-tests`)

💼 This rule is enabled in the ✅ `recommended` config.

⚠️ This rule _warns_ in the 🌐 `all` config.
# no-commented-out-tests

<!-- end auto-generated rule header -->

Expand Down
6 changes: 2 additions & 4 deletions docs/rules/no-conditional-expect.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Disallow conditional expects (`vitest/no-conditional-expect`)

⚠️ This rule _warns_ in the 🌐 `all` config.
# no-conditional-expect

<!-- end auto-generated rule header -->

Expand All @@ -13,7 +11,7 @@ Examples of **incorrect** code for this rule:
```ts
test('foo', () => {
if (true) {
expect(1).toBe(1)
expect(1).toBe(1)
}
})
```
Expand Down
9 changes: 4 additions & 5 deletions docs/rules/no-conditional-in-test.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Disallow conditional tests (`vitest/no-conditional-in-test`)

⚠️ This rule _warns_ in the 🌐 `all` config.
# no-conditional-in-test

<!-- end auto-generated rule header -->

### Rule Details

This rule aims to prevent conditional tests.
Expand All @@ -12,7 +11,7 @@ Examples of **incorrect** code for this rule:
```js
test('my test', () => {
if (true) {
doTheThing()
doTheThing()
}
})
```
Expand All @@ -21,6 +20,6 @@ Examples of **correct** code for this rule:

```js
test('my test', () => {
expect(true).toBe(true)
expect(true).toBe(true)
})
```
Loading