Skip to content

Commit

Permalink
Feat/update docs with flat configs (#417)
Browse files Browse the repository at this point in the history
* feat(lint): apply lint

* chore(docs): update descriptions for rules

* feat(test): fix tests

* chore(ci): update node version

* chore(checkout): update version of checkout action

* chore(action): update pnpm action
  • Loading branch information
veritem authored Apr 9, 2024
1 parent eceb58a commit e885ca2
Show file tree
Hide file tree
Showing 135 changed files with 8,474 additions and 8,397 deletions.
24 changes: 16 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,31 @@ jobs:

strategy:
matrix:
node-version: [18.x, 19.x]
node-version: [20.x, 21.x]
os: [ubuntu-latest, windows-latest]

fail-fast: false

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v3
with:
version: 7.16.1
version: 8
run_install: false

- name: ${{ matrix.node-version }}
uses: actions/setup-node@v3
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: install
run: pnpm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "21"
registry-url: https://registry.npmjs.org/
- run: npm install
- run: npm run test --if-present
Expand Down
149 changes: 55 additions & 94 deletions README.md

Large diffs are not rendered by default.

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

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/consistent-test-it.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prefer test or it but not both (`vitest/consistent-test-it`)
# Enforce using test or it but not both (`vitest/consistent-test-it`)

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-called-with.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()` (`vitest/prefer-called-with`)
# Enforce using `toBeCalledWith()` or `toHaveBeenCalledWith()` (`vitest/prefer-called-with`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-comparison-matcher.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using the built-in comparison matchers (`vitest/prefer-comparison-matcher`)
# Enforce using the built-in comparison matchers (`vitest/prefer-comparison-matcher`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-each.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prefer `each` rather than manual loops (`vitest/prefer-each`)
# Enforce using `each` rather than manual loops (`vitest/prefer-each`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-equality-matcher.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using the built-in quality matchers (`vitest/prefer-equality-matcher`)
# Enforce using the built-in quality matchers (`vitest/prefer-equality-matcher`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-expect-assertions.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using expect assertions instead of callbacks (`vitest/prefer-expect-assertions`)
# Enforce using expect assertions instead of callbacks (`vitest/prefer-expect-assertions`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-expect-resolves.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using `expect().resolves` over `expect(await ...)` syntax (`vitest/prefer-expect-resolves`)
# Enforce using `expect().resolves` over `expect(await ...)` syntax (`vitest/prefer-expect-resolves`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-hooks-in-order.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prefer having hooks in consistent order (`vitest/prefer-hooks-in-order`)
# Enforce having hooks in consistent order (`vitest/prefer-hooks-in-order`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-hooks-on-top.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest having hooks before any test cases (`vitest/prefer-hooks-on-top`)
# Enforce having hooks before any test cases (`vitest/prefer-hooks-on-top`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-mock-promise-shorthand.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prefer mock resolved/rejected shorthands for promises (`vitest/prefer-mock-promise-shorthand`)
# Enforce mock resolved/rejected shorthands for promises (`vitest/prefer-mock-promise-shorthand`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-snapshot-hint.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prefer including a hint with external snapshots (`vitest/prefer-snapshot-hint`)
# Enforce including a hint with external snapshots (`vitest/prefer-snapshot-hint`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-spy-on.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using `vi.spyOn` (`vitest/prefer-spy-on`)
# Enforce using `vi.spyOn` (`vitest/prefer-spy-on`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-strict-equal.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prefer strict equal over equal (`vitest/prefer-strict-equal`)
# Enforce strict equal over equal (`vitest/prefer-strict-equal`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-to-be-falsy.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using toBeFalsy() (`vitest/prefer-to-be-falsy`)
# Enforce using toBeFalsy() (`vitest/prefer-to-be-falsy`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-to-be-object.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prefer toBeObject() (`vitest/prefer-to-be-object`)
# Enforce using toBeObject() (`vitest/prefer-to-be-object`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-to-be-truthy.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using `toBeTruthy` (`vitest/prefer-to-be-truthy`)
# Enforce using `toBeTruthy` (`vitest/prefer-to-be-truthy`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-to-be.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using toBe() (`vitest/prefer-to-be`)
# Enforce using toBe() (`vitest/prefer-to-be`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-to-contain.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prefer using toContain() (`vitest/prefer-to-contain`)
# Enforce using toContain() (`vitest/prefer-to-contain`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-to-have-length.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using toHaveLength() (`vitest/prefer-to-have-length`)
# Enforce using toHaveLength() (`vitest/prefer-to-have-length`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-todo.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using `test.todo` (`vitest/prefer-todo`)
# Enforce using `test.todo` (`vitest/prefer-todo`)

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

Expand Down
49 changes: 23 additions & 26 deletions eslint-remote-tester.config.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
import type { Config } from 'eslint-remote-tester'
import {
getPathIgnorePattern,
getRepositories
} from 'eslint-remote-tester-repositories'
import { getPathIgnorePattern, getRepositories } from 'eslint-remote-tester-repositories'

const config: Config = {
repositories: getRepositories(),
pathIgnorePattern: getPathIgnorePattern(),
extensions: ['js', 'jsx', 'ts', 'tsx', 'cts', 'mts'],
repositories: getRepositories(),
pathIgnorePattern: getPathIgnorePattern(),
extensions: ['js', 'jsx', 'ts', 'tsx', 'cts', 'mts'],

concurrentTasks: 3,
cache: false,
logLevel: 'info',
concurrentTasks: 3,
cache: false,
logLevel: 'info',

eslintrc: {
root: true,
env: { es6: true },
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: { jsx: true }
},
overrides: [
{
files: ['*.ts', '*.tsx', '*.mts', '*.cts'],
parser: '@typescript-eslint/parser'
}
],
extends: ['plugin:vitest/all']
}
eslintrc: {
root: true,
env: { es6: true },
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: { jsx: true }
},
overrides: [
{
files: ['*.ts', '*.tsx', '*.mts', '*.cts'],
parser: '@typescript-eslint/parser'
}
],
extends: ['plugin:vitest/all']
}
}

export default config
27 changes: 24 additions & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
import vitest from 'eslint-plugin-vitest'
import stylistic from '@stylistic/eslint-plugin'
import eslintPlugin from 'eslint-plugin-eslint-plugin'
import parser from '@typescript-eslint/parser'

const styleConfigs = stylistic.configs.customize({
indent: 2,
quotes: 'single',
semi: false,
jsx: true,
commaDangle: 'never'
})

export default [
eslintPlugin.configs['flat/recommended'],
{
files: ['tests/**'], // or any other pattern
files: ['**/*.ts', '**/*.js'], // or any other pattern
plugins: {
vitest
vitest,
'@stylistic': stylistic
},
rules: {
...vitest.configs.recommended.rules
...styleConfigs.rules,
...vitest.configs.recommended.rules,
'eslint-plugin/require-meta-docs-description': 'error'
},
settings: {
vitest: {
typecheck: true
}
},
languageOptions: {
parser: parser,
globals: {
...vitest.environments.env.globals
}
Expand Down
41 changes: 36 additions & 5 deletions fixtures/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
import vitest from 'eslint-plugin-vitest'

export default [
vitest.configs.recommended
]
// import tseslint from 'typescript-eslint'
// import js from '@eslint/js'
// import vitest from 'eslint-plugin-vitest'
//
// export default tseslint.config(
// js.configs.recommended,
// {
// files: ['**/*.js'],
// languageOptions: {
// sourceType: 'module',
// ecmaVersion: 2024,
// parserOptions: {
// ecmaFeatures: {
// impliedStrict: true
// }
// }
// },
//
// // (first parameter of a rule) 0: off, 1: warning, 2: error
// rules: {
// // my rules…
// }
// },
// {
// files: ['**/*.test.js'],
// plugins: { vitest },
// rules: {
// ...vitest.configs.recommended.rules
// },
// languageOptions: {
// globals: {
// ...vitest.environments.env.globals
// }
// }
// }
// )
8 changes: 4 additions & 4 deletions fixtures/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { bench } from 'vitest'

bench('normal sorting', () => {
const x = [1, 5, 4, 2, 3]
x.sort((a, b) => {
return a - b
})
const x = [1, 5, 4, 2, 3]
x.sort((a, b) => {
return a - b
})
}, { time: 1000 })
6 changes: 4 additions & 2 deletions fixtures/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
"license": "MIT",
"dependencies": {
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-vitest": "0.4.2-beta.2",
"eslint-plugin-vitest": "0.4.2-beta.5",
"vitest": "^1.4.0"
},
"devDependencies": {
"@eslint/js": "^9.0.0",
"@vitest/ui": "^1.4.0",
"eslint": "^8.57.0"
"eslint": "^8.57.0",
"typescript-eslint": "^7.6.0"
}
}
Loading

0 comments on commit e885ca2

Please sign in to comment.