Skip to content

Commit

Permalink
feat(config): add vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
ntnyq committed Aug 12, 2024
1 parent 8150f8c commit 05a7961
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@eslint/js": "^9.9.0",
"@types/eslint": "^9.6.0",
"@unocss/eslint-plugin": "^0.62.0",
"@vitest/eslint-plugin": "^1.0.1",
"eslint-config-prettier": "^9.1.0",
"eslint-flat-config-utils": "^0.3.0",
"eslint-plugin-command": "^0.2.3",
Expand Down
25 changes: 25 additions & 0 deletions pnpm-lock.yaml

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

2 changes: 2 additions & 0 deletions scripts/generateType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
typescript,
unicorn,
unocss,
// vitest,
vue,
yml,
} from '../src'
Expand All @@ -45,6 +46,7 @@ const configs = defineConfig([
...unicorn,
...unocss,
...vue,
// ...vitest,
...yml,
...toml,
])
Expand Down
6 changes: 4 additions & 2 deletions src/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ export * from './regexp'
export * from './unocss'
export * from './command'

export * from './vitest'

export * from './vue'

export * from './yml'
export * from './toml'
export * from './sort'
export * from './jsonc'
export * from './markdown'

export * from './vue'
16 changes: 16 additions & 0 deletions src/configs/vitest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from '../utils'
import { pluginVitest } from '../plugins'
import { GLOB_TEST } from '../globs'

export const vitest = defineConfig([
{
name: 'ntnyq/test',
plugins: {
vitest: pluginVitest,
},
files: [GLOB_TEST],
rules: {
...pluginVitest.configs.recommended.rules,
},
},
])
7 changes: 6 additions & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file presets
*/

import { defineConfig, hasUnoCSS, hasVue } from './utils'
import { defineConfig, hasUnoCSS, hasVitest, hasVue } from './utils'
import {
command,
comments,
Expand All @@ -22,6 +22,7 @@ import {
typescript,
unicorn,
unocss,
vitest,
vue,
yml,
} from './configs'
Expand All @@ -35,6 +36,7 @@ export function ntnyq(
{
vue: enableVue = hasVue,
unocss: enableUnoCSS = hasUnoCSS,
vitest: enableVitest = hasVitest,
prettier: enablePrettier = true,
markdown: enableMarkdown = true,
command: enableCommand = true,
Expand Down Expand Up @@ -68,6 +70,9 @@ export function ntnyq(
if (enableVue) {
configs.push(...vue)
}
if (enableVitest) {
configs.push(...vitest)
}
if (enableUnoCSS) {
configs.push(...unocss)
}
Expand Down
2 changes: 2 additions & 0 deletions src/globs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const GLOB_TS = '**/*.?([cm])ts'
export const GLOB_TSX = '**/*.?([cm])tsx'
export const GLOB_DTS = '**/*.d.?([cm])ts'

export const GLOB_TEST = '**/*.{test,spec}.?([cm])[jt]s?(x)'

export const GLOB_STYLE = '**/*.{c,le,sc}ss'
export const GLOB_CSS = '**/*.css'
export const GLOB_LESS = '**/*.less'
Expand Down
1 change: 1 addition & 0 deletions src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export { default as pluginToml } from 'eslint-plugin-toml'
export { default as pluginJsonc } from 'eslint-plugin-jsonc'
export { default as pluginJsdoc } from 'eslint-plugin-jsdoc'
export { default as pluginUnoCSS } from '@unocss/eslint-plugin'
export { default as pluginVitest } from '@vitest/eslint-plugin'
export { default as pluginUnicorn } from 'eslint-plugin-unicorn'
export { default as pluginImport } from 'eslint-plugin-import-x'
export { default as pluginPrettier } from 'eslint-plugin-prettier'
Expand Down
2 changes: 2 additions & 0 deletions src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { isPackageExists } from 'local-pkg'

export const hasTypeScript = isPackageExists('typescript')

export const hasVitest = isPackageExists('vitest')

export const hasVue =
isPackageExists('vue') ||
isPackageExists('nuxt') ||
Expand Down

0 comments on commit 05a7961

Please sign in to comment.