Skip to content
Merged
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
13 changes: 13 additions & 0 deletions .eslint-doc-generatorrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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',
}),
}

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

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

- name: test
run: pnpm test:ci
185 changes: 95 additions & 90 deletions README.md

Large diffs are not rendered by default.

56 changes: 26 additions & 30 deletions docs/rules/consistent-test-it.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,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 +62,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`.

29 changes: 13 additions & 16 deletions docs/rules/consistent-vitest-vi.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,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
16 changes: 5 additions & 11 deletions docs/rules/expect-expect.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# Enforce having expectation in test body (`vitest/expect-expect`)

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

⚠️ This rule _warns_ in the 🌐 `all` config.
💼⚠️ This rule is enabled in the ✅ `recommended` config. This rule _warns_ in the 🌐 `all` config.

<!-- 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 +12,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 +49,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 +79,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)
})
})
```
10 changes: 5 additions & 5 deletions docs/rules/max-nested-describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,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 +32,6 @@ Maximum number of nested `describe` blocks.

```js
{
max: number
max: number
}
```
2 changes: 0 additions & 2 deletions docs/rules/no-alias-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

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


## Rule Details

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


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

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

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

⚠️ This rule _warns_ in the 🌐 `all` config.
💼⚠️ This rule is enabled in the ✅ `recommended` config. This rule _warns_ in the 🌐 `all` config.

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-conditional-expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Examples of **incorrect** code for this rule:
```ts
test('foo', () => {
if (true) {
expect(1).toBe(1)
expect(1).toBe(1)
}
})
```
Expand Down
5 changes: 3 additions & 2 deletions docs/rules/no-conditional-in-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
⚠️ This rule _warns_ in the 🌐 `all` config.

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

### Rule Details

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

```js
test('my test', () => {
expect(true).toBe(true)
expect(true).toBe(true)
})
```
16 changes: 8 additions & 8 deletions docs/rules/no-conditional-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ Examples of **incorrect** code for this rule:

```js
describe('my tests', () => {
if (true) {
it('is awesome', () => {
doTheThing()
})
}
if (true) {
it('is awesome', () => {
doTheThing()
})
}
})
```

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

```js
describe('my tests', () => {
it('is awesome', () => {
doTheThing()
})
it('is awesome', () => {
doTheThing()
})
})
```
Loading