Skip to content

Commit

Permalink
feat: support vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
chouchouji committed Jan 16, 2025
1 parent c2ed753 commit 89e83cd
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@eslint-react/eslint-plugin": "^1.23.1",
"@typescript-eslint/eslint-plugin": "^8.19.0",
"@typescript-eslint/parser": "^8.19.0",
"@vitest/eslint-plugin": "^1.1.25",
"eslint-plugin-import-x": "^4.6.1",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react-hooks": "^5.1.0",
Expand Down
33 changes: 23 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './react'
export * from './ignores'
export * from './comments'
export * from './prettier'
export * from './vitest'
27 changes: 27 additions & 0 deletions src/configs/vitest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import vitestPlugin from '@vitest/eslint-plugin'
import { Linter } from 'eslint'
import { createConfigName } from '../utils'

export function createVitestConfig(): Linter.Config[] {
return [
{
name: createConfigName('vitest/setup'),
plugins: {
vitest: vitestPlugin,
},
},
{
name: createConfigName('vitest/rules'),
rules: {
'vitest/expect-expect': 'error',
'vitest/no-commented-out-tests': 'warn',
'vitest/no-identical-title': 'error',
'vitest/no-import-node-test': 'warn',
'vitest/require-local-test-context-for-concurrent-snapshots': 'warn',
'vitest/valid-describe-callback': 'error',
'vitest/valid-expect': 'error',
'vitest/valid-title': 'error',
},
},
]
}
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
createPrettierConfig,
createReactConfig,
createTsConfig,
createVitestConfig,
createVueConfig,
type CreateVueConfigOptions,
} from './configs'
Expand Down Expand Up @@ -35,6 +36,11 @@ export interface DefineConfigOptions {
* @default false
*/
react?: boolean
/**
* Enable Vitest support
* @default false
*/
vitest?: boolean
/**
* Enable eslint comments support
* @default true
Expand All @@ -60,6 +66,7 @@ export function defineConfig(options: DefineConfigOptions = {}): Linter.Config[]
jsx = true,
vue = true,
react = false,
vitest = false,
comments = true,
ignores = [],
rules = {},
Expand Down Expand Up @@ -88,5 +95,9 @@ export function defineConfig(options: DefineConfigOptions = {}): Linter.Config[]
configs.push(...createReactConfig())
}

if (vitest) {
configs.push(...createVitestConfig())
}

return [...configs, ...createRulesConfig(rules), ...overrides]
}

0 comments on commit 89e83cd

Please sign in to comment.