Skip to content

Commit

Permalink
refactor!: rename defineConfig to defineConfigWithVueTs; `configs…
Browse files Browse the repository at this point in the history
…` to `vueTsConfigs`
  • Loading branch information
haoqunjiang committed Dec 27, 2024
1 parent de86921 commit e33db0b
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 66 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Because of the complexity of this config, it is exported as a factory function t

This package exports:

- `defineConfig`, a utility function whose type signature is the same as the [`config` function from `typescript-eslint`](https://typescript-eslint.io/packages/typescript-eslint#config).
- `configs`, contains all the [shared configruations from `typescript-eslint`](https://typescript-eslint.io/users/configs) (in camelCase, e.g. `configs.recommendedTypeChecked`).
- `defineConfigWithVueTs`, a utility function whose type signature is the same as the [`config` function from `typescript-eslint`](https://typescript-eslint.io/packages/typescript-eslint#config), but will modify the given config to work with Vue.js + TypeScript.
- `vueTsConfigs`, contains all the [shared configruations from `typescript-eslint`](https://typescript-eslint.io/users/configs) (in camelCase, e.g. `configs.recommendedTypeChecked`).
- a Vue-specific config factory: `configureVueProject({ scriptLangs, rootDir })`. More info below.

### Minimal Setup
Expand All @@ -39,13 +39,13 @@ This package exports:
// eslint.config.mjs
import pluginVue from 'eslint-plugin-vue'
import {
defineConfig,
configs,
defineConfigWithVueTs,
vueTsConfigs,
} from '@vue/eslint-config-typescript'

export default defineConfig(
export default defineConfigWithVueTs(
pluginVue.configs['flat/essential'],
configs.recommended,
vueTsConfigs.recommended,
)
```

Expand All @@ -59,9 +59,9 @@ All the `<script>` blocks in `.vue` files *MUST* be written in TypeScript (shoul
// eslint.config.mjs
import pluginVue from 'eslint-plugin-vue'
import {
defineConfig,
defineConfigWithVueTs,
vueTsConfigs,
configureVueProject,
configs,
} from '@vue/eslint-config-typescript'

configureVueProject({
Expand Down Expand Up @@ -97,13 +97,13 @@ configureVueProject({
rootDir: import.meta.dirname,
})

export default defineConfig(
export default defineConfigWithVueTs(
pluginVue.configs["flat/essential"],

// We STRONGLY RECOMMEND you to start with `recommended` or `recommendedTypeChecked`.
// But if you are determined to configure all rules by yourself,
// you can start with `base`, and then turn on/off the rules you need.
configs.base,
vueTsConfigs.base,
)
```

Expand All @@ -120,13 +120,13 @@ Instead, you can start by extending from the `recommendedTypeChecked` configurat
// eslint.config.mjs
import pluginVue from 'eslint-plugin-vue'
import {
defineConfig,
configs,
defineConfigWithVueTs,
vueTsConfigs,
} from '@vue/eslint-config-typescript'

export default defineConfig(
export default defineConfigWithVueTs(
pluginVue.configs['flat/essential'],
configs.recommendedTypeChecked
vueTsConfigs.recommendedTypeChecked
)
```

Expand Down
8 changes: 4 additions & 4 deletions examples/allow-js/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import pluginVue from 'eslint-plugin-vue'
import {
defineConfig,
defineConfigWithVueTs,
vueTsConfigs,
configureVueProject,
configs,
} from '@vue/eslint-config-typescript'

configureVueProject({ scriptLangs: ['js', 'ts'] })

export default defineConfig(
export default defineConfigWithVueTs(
{
name: 'app/files-to-lint',
files: ['**/*.js', '**/*.mjs', '**/*.ts', '**/*.mts', '**/*.vue'],
Expand All @@ -19,5 +19,5 @@ export default defineConfig(
},

pluginVue.configs['flat/essential'],
configs.recommended,
vueTsConfigs.recommended,
)
8 changes: 4 additions & 4 deletions examples/minimal/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pluginVue from 'eslint-plugin-vue'
import { defineConfig, configs } from '@vue/eslint-config-typescript'
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'

export default defineConfig(
export default defineConfigWithVueTs(
{
name: 'app/files-to-lint',
files: ['**/*.ts', '**/*.mts', '**/*.vue'],
Expand All @@ -12,6 +12,6 @@ export default defineConfig(
ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**'],
},

...pluginVue.configs['flat/essential'],
configs.recommended,
pluginVue.configs['flat/essential'],
vueTsConfigs.recommended,
)
6 changes: 3 additions & 3 deletions examples/type-checked/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pluginVue from 'eslint-plugin-vue'
import { defineConfig, configs } from '@vue/eslint-config-typescript'
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'
import pluginVitest from '@vitest/eslint-plugin'
import pluginCypress from 'eslint-plugin-cypress/flat'
import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'

export default defineConfig(
export default defineConfigWithVueTs(
{
name: 'app/files-to-lint',
files: ['**/*.{ts,mts,tsx,vue}'],
Expand All @@ -16,7 +16,7 @@ export default defineConfig(
},

pluginVue.configs['flat/essential'],
configs.recommendedTypeChecked,
vueTsConfigs.recommendedTypeChecked,

{
...pluginVitest.configs.recommended,
Expand Down
6 changes: 3 additions & 3 deletions examples/with-cypress/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pluginVue from 'eslint-plugin-vue'
import pluginCypress from 'eslint-plugin-cypress/flat'
import { defineConfig, configs } from '@vue/eslint-config-typescript'
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'

export default defineConfig(
export default defineConfigWithVueTs(
{
name: 'app/files-to-lint',
files: ['**/*.ts', '**/*.mts', '**/*.vue'],
Expand All @@ -14,7 +14,7 @@ export default defineConfig(
},

pluginVue.configs['flat/essential'],
configs.recommended,
vueTsConfigs.recommended,

{
...pluginCypress.configs.recommended,
Expand Down
10 changes: 5 additions & 5 deletions examples/with-jsx-in-vue/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import pluginVue from 'eslint-plugin-vue'
import {
defineConfig,
defineConfigWithVueTs,
vueTsConfigs,
configureVueProject,
configs,
} from '@vue/eslint-config-typescript'

configureVueProject({ scriptLangs: ['js', 'jsx', 'ts', 'tsx'] })

export default defineConfig(
export default defineConfigWithVueTs(
{
name: 'app/files-to-lint',
files: [
Expand All @@ -26,6 +26,6 @@ export default defineConfig(
ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**'],
},

...pluginVue.configs['flat/essential'],
configs.recommended,
pluginVue.configs['flat/essential'],
vueTsConfigs.recommended,
)
6 changes: 3 additions & 3 deletions examples/with-jsx/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pluginVue from 'eslint-plugin-vue'
import { defineConfig, configs } from '@vue/eslint-config-typescript'
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'

export default defineConfig(
export default defineConfigWithVueTs(
{
name: 'app/files-to-lint',
files: ['**/*.js', '**/*.mjs', '**/*.jsx', '**/*.ts', '**/*.mts', '**/*.tsx', '**/*.vue'],
Expand All @@ -13,5 +13,5 @@ export default defineConfig(
},

pluginVue.configs['flat/essential'],
configs.recommended,
vueTsConfigs.recommended,
)
6 changes: 3 additions & 3 deletions examples/with-nightwatch/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pluginVue from 'eslint-plugin-vue'
import { defineConfig, configs } from '@vue/eslint-config-typescript'
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'

export default defineConfig(
export default defineConfigWithVueTs(
{
name: 'app/files-to-lint',
files: ['**/*.ts', '**/*.mts', '**/*.vue'],
Expand All @@ -13,7 +13,7 @@ export default defineConfig(
},

pluginVue.configs['flat/essential'],
configs.recommended,
vueTsConfigs.recommended,

{
// nightwatch specs
Expand Down
6 changes: 3 additions & 3 deletions examples/with-playwright/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pluginVue from 'eslint-plugin-vue'
import pluginPlaywright from 'eslint-plugin-playwright'
import { defineConfig, configs } from '@vue/eslint-config-typescript'
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'

export default defineConfig(
export default defineConfigWithVueTs(
{
name: 'app/files-to-lint',
files: ['**/*.ts', '**/*.mts', '**/*.vue'],
Expand All @@ -14,7 +14,7 @@ export default defineConfig(
},

pluginVue.configs['flat/essential'],
configs.recommended,
vueTsConfigs.recommended,

{
...pluginPlaywright.configs['flat/recommended'],
Expand Down
6 changes: 3 additions & 3 deletions examples/with-prettier/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pluginVue from 'eslint-plugin-vue'
import { defineConfig, configs } from '@vue/eslint-config-typescript'
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'
import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'

export default defineConfig(
export default defineConfigWithVueTs(
{
name: 'app/files-to-lint',
files: ['**/*.ts', '**/*.mts', '**/*.vue'],
Expand All @@ -14,7 +14,7 @@ export default defineConfig(
},

pluginVue.configs['flat/essential'],
configs.recommended,
vueTsConfigs.recommended,

skipFormatting
)
10 changes: 5 additions & 5 deletions examples/with-tsx-in-vue/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import pluginVue from 'eslint-plugin-vue'
import {
defineConfig,
defineConfigWithVueTs,
vueTsConfigs,
configureVueProject,
configs,
} from '@vue/eslint-config-typescript'

configureVueProject({ scriptLangs: ['ts', 'tsx'] })

export default defineConfig(
export default defineConfigWithVueTs(
{
name: 'app/files-to-lint',
files: ['**/*.ts', '**/*.mts', '**/*.tsx', '**/*.vue'],
Expand All @@ -18,6 +18,6 @@ export default defineConfig(
ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**'],
},

...pluginVue.configs['flat/essential'],
configs.recommended,
pluginVue.configs['flat/essential'],
vueTsConfigs.recommended,
)
6 changes: 3 additions & 3 deletions examples/with-tsx/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pluginVue from 'eslint-plugin-vue'
import { defineConfig, configs } from '@vue/eslint-config-typescript'
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'

export default defineConfig(
export default defineConfigWithVueTs(
{
name: 'app/files-to-lint',
files: ['**/*.ts', '**/*.mts', '**/*.tsx', '**/*.vue'],
Expand All @@ -13,5 +13,5 @@ export default defineConfig(
},

pluginVue.configs['flat/essential'],
configs.recommended,
vueTsConfigs.recommended,
)
6 changes: 3 additions & 3 deletions examples/with-vitest/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pluginVue from 'eslint-plugin-vue'
import pluginVitest from '@vitest/eslint-plugin'
import { defineConfig, configs } from '@vue/eslint-config-typescript'
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'

export default defineConfig(
export default defineConfigWithVueTs(
{
name: 'app/files-to-lint',
files: ['**/*.ts', '**/*.mts', '**/*.vue'],
Expand All @@ -14,7 +14,7 @@ export default defineConfig(
},

pluginVue.configs['flat/essential'],
configs.recommended,
vueTsConfigs.recommended,

{
...pluginVitest.configs['recommended'],
Expand Down
4 changes: 2 additions & 2 deletions src/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import tseslint from 'typescript-eslint'
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'

const PlaceholderPrefix =
'PLACEHOLDER_THAT_MUST_BE_WRAPPED_INSIDE_defineConfig_'
'PLACEHOLDER_THAT_MUST_BE_WRAPPED_INSIDE_defineConfigWithVueTs_'

// Manually declare all the available configs as enums to make the auto-completion more user-friendly.
// It's also a good way to avoid the placeholder strings to appear in the auto-completion.
Expand All @@ -26,7 +26,7 @@ export enum VueTsPreset {
// `enum`s are just objects with reverse mapping during runtime.
// We redefine the type here only to make the auto-completion more user-friendly.
export type ExtendableConfigName = keyof typeof VueTsPreset
export const configs = VueTsPreset as {
export const vueTsConfigs = VueTsPreset as {
[key in ExtendableConfigName]: VueTsPreset
}

Expand Down
11 changes: 7 additions & 4 deletions src/createConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'

import {
configureVueProject,
defineConfig,
defineConfigWithVueTs,
type ProjectOptions,
} from './utilities'
import { configs, type ExtendableConfigName } from './configs'
import { vueTsConfigs, type ExtendableConfigName } from './configs'
import type { ScriptLang } from './internals'

type ConfigOptions = ProjectOptions & {
extends?: Array<ExtendableConfigName>
supportedScriptLangs?: Record<ScriptLang, boolean>
}

/**
* @deprecated Use `defineConfigWithVueTs` + `vueTsConfigs` instead.
*/
export default function createConfig({
extends: configNamesToExtend = ['recommended'],
supportedScriptLangs = { ts: true, tsx: false, js: false, jsx: false },
Expand Down Expand Up @@ -47,7 +50,7 @@ export default function createConfig({
) as ScriptLang[],
rootDir,
})
return defineConfig(
...configNamesToExtend.map(name => configs[name as ExtendableConfigName]),
return defineConfigWithVueTs(
...configNamesToExtend.map(name => vueTsConfigs[name as ExtendableConfigName]),
)
}
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
export {
defineConfig,
defineConfigWithVueTs,
configureVueProject,
} from './utilities'
export { configs } from './configs'
export { vueTsConfigs } from './configs'

// Compatibility layer for the `createConfig` function in <= 14.2.0
export { default as createConfig } from './createConfig'
export { default } from './createConfig'

import { defineConfigWithVueTs } from './utilities'
/**
* @deprecated `defineConfig` is renamed to `defineConfigWithVueTs` in 14.3.0
*/
export const defineConfig = defineConfigWithVueTs
Loading

0 comments on commit e33db0b

Please sign in to comment.