Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vuejs/eslint-config-typescript
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v14.2.0
Choose a base ref
...
head repository: vuejs/eslint-config-typescript
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v14.3.0
Choose a head ref
  • 4 commits
  • 106 files changed
  • 2 contributors

Commits on Dec 25, 2024

  1. Copy the full SHA
    3a3b13c View commit details

Commits on Jan 14, 2025

  1. fix: typo in index.ts (#128)

    aparajita authored Jan 14, 2025
    Copy the full SHA
    6296f39 View commit details
  2. feat: a more intuitive way to configure and override (#123)

    haoqunjiang authored Jan 14, 2025
    Copy the full SHA
    f7bd7b7 View commit details
  3. 14.3.0

    haoqunjiang committed Jan 14, 2025
    Copy the full SHA
    cdbecf6 View commit details
Showing with 4,081 additions and 1,788 deletions.
  1. +62 −83 README.md
  2. +12 −11 examples/allow-js/eslint.config.js
  3. +5 −5 examples/allow-js/package.json
  4. +6 −0 examples/api-before-14.3/.editorconfig
  5. +30 −0 examples/api-before-14.3/.gitignore
  6. +7 −0 examples/api-before-14.3/.prettierrc.json
  7. +8 −0 examples/api-before-14.3/.vscode/extensions.json
  8. +61 −0 examples/api-before-14.3/README.md
  9. +8 −0 examples/api-before-14.3/cypress.config.ts
  10. +8 −0 examples/api-before-14.3/cypress/e2e/example.cy.ts
  11. +5 −0 examples/api-before-14.3/cypress/fixtures/example.json
  12. +39 −0 examples/api-before-14.3/cypress/support/commands.ts
  13. +20 −0 examples/api-before-14.3/cypress/support/e2e.ts
  14. +8 −0 examples/api-before-14.3/cypress/tsconfig.json
  15. +1 −0 examples/api-before-14.3/env.d.ts
  16. +34 −0 examples/api-before-14.3/eslint.config.js
  17. +13 −0 examples/api-before-14.3/index.html
  18. +48 −0 examples/api-before-14.3/package.json
  19. BIN examples/api-before-14.3/public/favicon.ico
  20. +85 −0 examples/api-before-14.3/src/App.vue
  21. +86 −0 examples/api-before-14.3/src/assets/base.css
  22. +1 −0 examples/api-before-14.3/src/assets/logo.svg
  23. +35 −0 examples/api-before-14.3/src/assets/main.css
  24. +41 −0 examples/api-before-14.3/src/components/HelloWorld.vue
  25. +88 −0 examples/api-before-14.3/src/components/TheWelcome.vue
  26. +87 −0 examples/api-before-14.3/src/components/WelcomeItem.vue
  27. +11 −0 examples/api-before-14.3/src/components/__tests__/HelloWorld.spec.ts
  28. +7 −0 examples/api-before-14.3/src/components/icons/IconCommunity.vue
  29. +7 −0 examples/api-before-14.3/src/components/icons/IconDocumentation.vue
  30. +7 −0 examples/api-before-14.3/src/components/icons/IconEcosystem.vue
  31. +7 −0 examples/api-before-14.3/src/components/icons/IconSupport.vue
  32. +19 −0 examples/api-before-14.3/src/components/icons/IconTooling.vue
  33. +14 −0 examples/api-before-14.3/src/main.ts
  34. +24 −0 examples/api-before-14.3/src/router/index.ts
  35. +12 −0 examples/api-before-14.3/src/stores/counter.ts
  36. +15 −0 examples/api-before-14.3/src/views/AboutView.vue
  37. +9 −0 examples/api-before-14.3/src/views/HomeView.vue
  38. +14 −0 examples/api-before-14.3/tsconfig.app.json
  39. +17 −0 examples/api-before-14.3/tsconfig.json
  40. +19 −0 examples/api-before-14.3/tsconfig.node.json
  41. +11 −0 examples/api-before-14.3/tsconfig.vitest.json
  42. +20 −0 examples/api-before-14.3/vite.config.ts
  43. +14 −0 examples/api-before-14.3/vitest.config.ts
  44. +6 −0 examples/custom-type-checked-rules-on-and-off/.editorconfig
  45. +30 −0 examples/custom-type-checked-rules-on-and-off/.gitignore
  46. +7 −0 examples/custom-type-checked-rules-on-and-off/.vscode/extensions.json
  47. +39 −0 examples/custom-type-checked-rules-on-and-off/README.md
  48. +1 −0 examples/custom-type-checked-rules-on-and-off/env.d.ts
  49. +28 −0 examples/custom-type-checked-rules-on-and-off/eslint.config.js
  50. +13 −0 examples/custom-type-checked-rules-on-and-off/index.html
  51. +31 −0 examples/custom-type-checked-rules-on-and-off/package.json
  52. BIN examples/custom-type-checked-rules-on-and-off/public/favicon.ico
  53. +47 −0 examples/custom-type-checked-rules-on-and-off/src/App.vue
  54. +86 −0 examples/custom-type-checked-rules-on-and-off/src/assets/base.css
  55. +1 −0 examples/custom-type-checked-rules-on-and-off/src/assets/logo.svg
  56. +35 −0 examples/custom-type-checked-rules-on-and-off/src/assets/main.css
  57. +41 −0 examples/custom-type-checked-rules-on-and-off/src/components/HelloWorld.vue
  58. +94 −0 examples/custom-type-checked-rules-on-and-off/src/components/TheWelcome.vue
  59. +87 −0 examples/custom-type-checked-rules-on-and-off/src/components/WelcomeItem.vue
  60. +7 −0 examples/custom-type-checked-rules-on-and-off/src/components/icons/IconCommunity.vue
  61. +7 −0 examples/custom-type-checked-rules-on-and-off/src/components/icons/IconDocumentation.vue
  62. +7 −0 examples/custom-type-checked-rules-on-and-off/src/components/icons/IconEcosystem.vue
  63. +7 −0 examples/custom-type-checked-rules-on-and-off/src/components/icons/IconSupport.vue
  64. +19 −0 examples/custom-type-checked-rules-on-and-off/src/components/icons/IconTooling.vue
  65. +6 −0 examples/custom-type-checked-rules-on-and-off/src/main.ts
  66. +12 −0 examples/custom-type-checked-rules-on-and-off/tsconfig.app.json
  67. +11 −0 examples/custom-type-checked-rules-on-and-off/tsconfig.json
  68. +18 −0 examples/custom-type-checked-rules-on-and-off/tsconfig.node.json
  69. +18 −0 examples/custom-type-checked-rules-on-and-off/vite.config.ts
  70. +5 −5 examples/minimal/eslint.config.js
  71. +5 −5 examples/minimal/package.json
  72. +6 −6 examples/type-checked/eslint.config.js
  73. +9 −9 examples/type-checked/package.json
  74. +7 −7 examples/with-cypress/eslint.config.js
  75. +6 −6 examples/with-cypress/package.json
  76. +20 −13 examples/with-jsx-in-vue/eslint.config.js
  77. +5 −5 examples/with-jsx-in-vue/package.json
  78. +5 −5 examples/with-jsx/eslint.config.js
  79. +5 −5 examples/with-jsx/package.json
  80. +5 −5 examples/with-nightwatch/eslint.config.js
  81. +7 −7 examples/with-nightwatch/package.json
  82. +5 −5 examples/with-playwright/eslint.config.js
  83. +5 −5 examples/with-playwright/package.json
  84. +5 −5 examples/with-prettier/eslint.config.js
  85. +5 −5 examples/with-prettier/package.json
  86. +11 −10 examples/with-tsx-in-vue/eslint.config.js
  87. +5 −5 examples/with-tsx-in-vue/package.json
  88. +5 −5 examples/with-tsx/eslint.config.js
  89. +5 −5 examples/with-tsx/package.json
  90. +5 −5 examples/with-vitest/eslint.config.js
  91. +7 −7 examples/with-vitest/package.json
  92. +8 −7 package.json
  93. +1,652 −1,286 pnpm-lock.yaml
  94. +82 −0 src/configs.ts
  95. +56 −0 src/createConfig.ts
  96. +36 −0 src/groupVueFiles.ts
  97. +16 −229 src/index.ts
  98. +165 −0 src/internals.ts
  99. +0 −3 src/shim.d.ts
  100. +182 −0 src/utilities.ts
  101. +10 −9 test/fixtures/file-based-routing/eslint.config.js
  102. +6 −6 test/fixtures/file-based-routing/package.json
  103. +8 −5 test/fixtures/with-older-espree/eslint.config.js
  104. +5 −5 test/fixtures/with-older-espree/package.json
  105. +28 −3 test/index.spec.ts
  106. +1 −1 tsconfig.json
145 changes: 62 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -25,91 +25,83 @@ Please also make sure that you have `typescript` and `eslint` installed.

## Usage

Because of the complexity of this config, it is exported as a factory function that takes an options object and returns an ESLint configuration object.
Because of the complexity of the configurations, this package exports several utilities:

This package exports 2 utility functions:

- `defineConfig`, as a re-export of the [`config` function from `typescript-eslint`](https://typescript-eslint.io/packages/typescript-eslint#config).
- `createConfig`, used for creating an ESLint configuration array that extends from the [`typescript-eslint` shared configs](https://typescript-eslint.io/users/configs).
- `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 ESLint 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. `vueTsConfigs.recommendedTypeChecked`), and applies to `.vue` files in addition to TypeScript files.
- a Vue-specific config factory: `configureVueProject({ scriptLangs, rootDir })`. More info below.

### Minimal Setup

```js
// eslint.config.mjs
import pluginVue from 'eslint-plugin-vue'
import {
defineConfig,
createConfig as vueTsEslintConfig,
defineConfigWithVueTs,
vueTsConfigs,
} from '@vue/eslint-config-typescript'

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

The above configuration enables [the essential rules for Vue 3](https://eslint.vuejs.org/rules/#priority-a-essential-error-prevention) and [the recommended rules for TypeScript](https://typescript-eslint.io/rules/?=recommended).

All the `<script>` blocks in `.vue` files _MUST_ be written in TypeScript (should be either `<script setup lang="ts">` or `<script lang="ts">`).
All the `<script>` blocks in `.vue` files *MUST* be written in TypeScript (should be either `<script setup lang="ts">` or `<script lang="ts">`).

### Advanced Setup

```js
// eslint.config.mjs
import pluginVue from 'eslint-plugin-vue'
import {
defineConfig,
createConfig as vueTsEslintConfig,
defineConfigWithVueTs,
vueTsConfigs,
configureVueProject,
} from '@vue/eslint-config-typescript'

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

vueTsEslintConfig({
// Optional: extend additional configurations from `typescript-eslint`.
// Supports all the configurations in
// https://typescript-eslint.io/users/configs#recommended-configurations
extends: [
// By default, only the recommended rules are enabled.
'recommended',
// You can also manually enable the stylistic rules.
// "stylistic",

// Other utility configurations, such as `eslintRecommended`, (note that it's in camelCase)
// are also extendable here. But we don't recommend using them directly.
],

// Optional: specify the script langs in `.vue` files
// Defaults to `{ ts: true, js: false, tsx: false, jsx: false }`
supportedScriptLangs: {
ts: true,

// [!DISCOURAGED]
// Set to `true` to allow plain `<script>` or `<script setup>` blocks.
// This might result-in false positive or negatives in some rules for `.vue` files.
// Note you also need to configure `allowJs: true` and `checkJs: true`
// in corresponding `tsconfig.json` files.
js: false,

// [!STRONGLY DISCOURAGED]
// Set to `true` to allow `<script lang="tsx">` blocks.
// This would be in conflict with all type-aware rules.
tsx: false,

// [!STRONGLY DISCOURAGED]
// Set to `true` to allow `<script lang="jsx">` blocks.
// This would be in conflict with all type-aware rules and may result in false positives.
jsx: false,
},

// <https://github.com/vuejs/eslint-plugin-vue/issues/1910#issuecomment-1819993961>
// Optional: the root directory to resolve the `.vue` files, defaults to `process.cwd()`.
// You may need to set this to the root directory of your project if you have a monorepo.
// This is useful when you allow any other languages than `ts` in `.vue` files.
// Our config helper would resolve and parse all the `.vue` files under `rootDir`,
// and only apply the loosened rules to the files that do need them.
rootDir: import.meta.dirname,
}),
configureVueProject({
// Optional: specify the script langs in `.vue` files
// Defaults to `['ts']`.
scriptLangs: [
'ts',

// [!DISCOURAGED]
// Include 'js' to allow plain `<script>` or `<script setup>` blocks.
// This might result-in false positive or negatives in some rules for `.vue` files.
// Note you also need to configure `allowJs: true` and `checkJs: true`
// in corresponding `tsconfig.json` files.
'js',

// [!STRONGLY DISCOURAGED]
// Include 'tsx' to allow `<script lang="tsx">` blocks.
// This would be in conflict with all type-aware rules.
'tsx',

// [!STRONGLY DISCOURAGED]
// Include 'jsx' to allow `<script lang="jsx">` blocks.
// This would be in conflict with all type-aware rules and may result in false positives.
'jsx',
],

// <https://github.com/vuejs/eslint-plugin-vue/issues/1910#issuecomment-1819993961>
// Optional: the root directory to resolve the `.vue` files, defaults to `process.cwd()`.
// You may need to set this to the root directory of your project if you have a monorepo.
// This is useful when you allow any other languages than `ts` in `.vue` files.
// Our config helper would resolve and parse all the `.vue` files under `rootDir`,
// and only apply the loosened rules to the files that do need them.
rootDir: import.meta.dirname,
})

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.
vueTsConfigs.base,
)
```

@@ -122,39 +114,26 @@ It is not always easy to set up the type-checking environment for ESLint without
So we don't recommend you to configure individual type-aware rules and the corresponding language options all by yourself.
Instead, you can start by extending from the `recommendedTypeChecked` configuration and then turn on/off the rules you need.

As of now, all the rules you need to turn on must appear _before_ calling `vueTsEslintConfig({ extends: ['recommendedTypeChecked'] })`, and all the rules you need to turn off must appear _after_ calling it.

```js
// eslint.config.mjs
import pluginVue from 'eslint-plugin-vue'
import {
defineConfig,
createConfig as vueTsEslintConfig,
defineConfigWithVueTs,
vueTsConfigs,
} from '@vue/eslint-config-typescript'

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

{
files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.vue'],
rules: {
// Turn on other rules that you need.
'@typescript-eslint/require-array-sort-compare': 'error',
},
},

vueTsEslintConfig({ extends: ['recommendedTypeChecked'] }),

{
files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.vue'],
rules: {
// Turn off the recommended rules that you don't need.
'@typescript-eslint/no-redundant-type-constituents': 'off',
},
},
vueTsConfigs.recommendedTypeChecked
)
```

## Use As a Normal Shared ESLint Config (Not Recommended)

You can use this package as a normal ESLint config, without the `defineConfigWithVueTs` helper. But in this case, overriding the rules for `.vue` files would be more difficult and comes with many nuances. Please be cautious.

You can check [the documentation for 14.1 and earlier versions](https://github.com/vuejs/eslint-config-typescript/tree/v14.1.4#usage) for more information.

## Further Reading

- [All the extendable configurations from `typescript-eslint`](https://typescript-eslint.io/users/configs).
23 changes: 12 additions & 11 deletions examples/allow-js/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import pluginVue from "eslint-plugin-vue";
import vueTsEslintConfig from "@vue/eslint-config-typescript";
import pluginVue from 'eslint-plugin-vue'
import {
defineConfigWithVueTs,
vueTsConfigs,
configureVueProject,
} from '@vue/eslint-config-typescript'

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

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

...pluginVue.configs["flat/essential"],
...vueTsEslintConfig({
supportedScriptLangs: {
ts: true,
js: true
}
}),
]
pluginVue.configs['flat/essential'],
vueTsConfigs.recommended,
)
10 changes: 5 additions & 5 deletions examples/allow-js/package.json
Original file line number Diff line number Diff line change
@@ -16,15 +16,15 @@
},
"devDependencies": {
"@tsconfig/node20": "^20.1.4",
"@types/node": "^20.17.10",
"@types/node": "^20.17.12",
"@vitejs/plugin-vue": "^5.2.1",
"@vue/eslint-config-typescript": "workspace:*",
"@vue/tsconfig": "^0.7.0",
"eslint": "^9.17.0",
"eslint": "^9.18.0",
"eslint-plugin-vue": "^9.32.0",
"npm-run-all2": "^7.0.2",
"typescript": "~5.6.3",
"vite": "^6.0.5",
"vue-tsc": "^2.1.10"
"typescript": "~5.7.3",
"vite": "^6.0.7",
"vue-tsc": "^2.2.0"
}
}
6 changes: 6 additions & 0 deletions examples/api-before-14.3/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue}]
charset = utf-8
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
30 changes: 30 additions & 0 deletions examples/api-before-14.3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
.DS_Store
dist
dist-ssr
coverage
*.local

/cypress/videos/
/cypress/screenshots/

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

*.tsbuildinfo
7 changes: 7 additions & 0 deletions examples/api-before-14.3/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"singleQuote": true,
"arrowParens": "avoid"
}
8 changes: 8 additions & 0 deletions examples/api-before-14.3/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"Vue.volar",
"vitest.explorer",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
61 changes: 61 additions & 0 deletions examples/api-before-14.3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# api-before-14.3

This template should help get you started developing with Vue 3 in Vite.

## Recommended IDE Setup

[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).

## Type Support for `.vue` Imports in TS

TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.

## Customize configuration

See [Vite Configuration Reference](https://vite.dev/config/).

## Project Setup

```sh
npm install
```

### Compile and Hot-Reload for Development

```sh
npm run dev
```

### Type-Check, Compile and Minify for Production

```sh
npm run build
```

### Run Unit Tests with [Vitest](https://vitest.dev/)

```sh
npm run test:unit
```

### Run End-to-End Tests with [Cypress](https://www.cypress.io/)

```sh
npm run test:e2e:dev
```

This runs the end-to-end tests against the Vite development server.
It is much faster than the production build.

But it's still recommended to test the production build with `test:e2e` before deploying (e.g. in CI environments):

```sh
npm run build
npm run test:e2e
```

### Lint with [ESLint](https://eslint.org/)

```sh
npm run lint
```
8 changes: 8 additions & 0 deletions examples/api-before-14.3/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'cypress'

export default defineConfig({
e2e: {
specPattern: 'cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}',
baseUrl: 'http://localhost:4173'
}
})
8 changes: 8 additions & 0 deletions examples/api-before-14.3/cypress/e2e/example.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// https://on.cypress.io/api

describe('My First Test', () => {
it('visits the app root url', () => {
cy.visit('/')
cy.contains('h1', 'You did it!')
})
})
5 changes: 5 additions & 0 deletions examples/api-before-14.3/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
Loading