Skip to content

Commit b9050b7

Browse files
committed
docs: update README for new major version with ESLint 9 flat config support
1 parent e0bf9da commit b9050b7

File tree

1 file changed

+78
-40
lines changed

1 file changed

+78
-40
lines changed

README.md

Lines changed: 78 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,110 @@
44
55
See [@typescript-eslint/eslint-plugin](https://typescript-eslint.io/rules/) for available rules.
66

7-
This config is specifically designed to be used by `@vue/cli` & `create-vue` setups
7+
This config is specifically designed to be used by `create-vue` setups
88
and is not meant for outside use (it can be used but some adaptations
99
on the user side might be needed - for details see the config file).
1010

1111
A part of its design is that this config may implicitly depend on
12-
other parts of `@vue/cli`/`create-vue` setups, such as `eslint-plugin-vue` being
12+
other parts of `create-vue` setups, such as `eslint-plugin-vue` being
1313
extended in the same resulting config.
1414

15-
## Installation
15+
> Note: the current version doesn't support the legacy `.eslintrc*` configuraion format. For that you need to use version 9 or earlier. See the [corresponding README](https://www.npmjs.com/package/@vue/eslint-config-typescript/v/legacy-eslintrc) for more usage instructions.
1616
17-
In order to work around [a known limitation in ESLint](https://github.com/eslint/eslint/issues/3458), we recommend you to use this package alongside `@rushstack/eslint-patch`, so that you don't have to install too many dependencies:
17+
## Installation
1818

1919
```sh
20-
npm add --dev @vue/eslint-config-typescript @rushstack/eslint-patch
20+
npm add --dev @vue/eslint-config-typescript
2121
```
2222

23-
## Usage
23+
Please also make sure that you have `typescript` and `eslint` installed.
2424

25-
This package comes with 2 rulesets.
26-
27-
### `@vue/eslint-config-typescript`
25+
## Usage
2826

29-
This ruleset is the base configuration for Vue-TypeScript projects.
30-
Besides setting the parser and plugin options, it also turns off several conflicting rules in the `eslint:recommended` ruleset.
31-
So when used alongside other sharable configs, this config should be placed at the end of the `extends` array.
27+
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.
3228

33-
An example `.eslintrc.cjs`:
29+
### Minimal setup
3430

3531
```js
36-
/* eslint-env node */
37-
require("@rushstack/eslint-patch/modern-module-resolution")
38-
39-
module.exports = {
40-
extends: [
41-
'eslint:recommended',
42-
'plugin:vue/vue3-essential',
43-
'@vue/eslint-config-typescript'
44-
]
45-
}
32+
// eslint.config.mjs
33+
import pluginVue from "eslint-plugin-vue";
34+
import vueTsEslintConfig from "@vue/eslint-config-typescript";
35+
36+
export default [
37+
...pluginVue.configs["flat/essential"],
38+
...vueTsEslintConfig(),
39+
}]
4640
```
4741

48-
### `@vue/eslint-config-typescript/recommended`
42+
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).
4943

50-
This is extended from the `@typescript-eslint/recommended` ruleset, which is an **_opinionated_** ruleset.
51-
See the [original documentation](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin/src/configs#recommended) for more information.
44+
All the `<script>` blocks in `.vue` files *MUST* be written in TypeScript (should be either `<script setup lang="ts">` or `<script lang="ts">`).
5245

53-
Some of its rules, however, might conflict with `prettier`.
54-
So when used alongside other sharable configs, this config should be placed after all other configs except for the one from `@vue/eslint-config-prettier` or `eslint-plugin-prettier` in the `extends` array.
55-
56-
An example `.eslintrc.cjs`:
46+
### Advanced setup
5747

5848
```js
59-
/* eslint-env node */
60-
require("@rushstack/eslint-patch/modern-module-resolution")
61-
62-
module.exports = {
63-
extends: [
64-
'plugin:vue/vue3-essential',
65-
'@vue/eslint-config-typescript/recommended',
66-
'@vue/eslint-config-prettier'
67-
]
68-
}
49+
// eslint.config.mjs
50+
import pluginVue from "eslint-plugin-vue";
51+
import vueTsEslintConfig from "@vue/eslint-config-typescript";
52+
53+
export default [
54+
...pluginVue.configs["flat/essential"],
55+
56+
...vueTsEslintConfig({
57+
// Supports all the configurations in https://typescript-eslint.io/users/configs#getting-started
58+
extends: [
59+
// By default, only the recommended rules are enabled.
60+
"recommended",
61+
// You can also manually enable the stylistic rules.
62+
// "stylistic",
63+
64+
// The ones with `-type-checked` are not yet tested.
65+
],
66+
67+
// Optional: specify the script langs in `.vue` files
68+
// Defaults to `{ ts: true, js: false, tsx: false, jsx: false }`
69+
scriptLang: {
70+
ts: true,
71+
72+
// [Discouraged]
73+
// Set to `true` to allow plain `<script>` or `<script setup>` blocks.
74+
// This might result-in false positive or negatives in some rules for `.vue` files.
75+
js: false,
76+
77+
// [Strongly discouraged]
78+
// Set to `true` to allow `<script lang="tsx">` blocks.
79+
// This would be in conflict with all type-aware rules.
80+
tsx: false,
81+
82+
// [Strongly discouraged]
83+
// Set to `true` to allow `<script lang="jsx">` blocks.
84+
// This would be in conflict with all type-aware rules and may result in false positives.
85+
jsx: false,
86+
},
87+
88+
// [Not yet implemented]
89+
// <https://github.com/vuejs/eslint-plugin-vue/issues/1910#issuecomment-1819993961>
90+
// Optional: the root directory to resolve the `.vue` files, defaults to `process.cwd()`.
91+
//
92+
// This is useful when you allow any other languages than `ts` in `.vue` files.
93+
// Our config helper would resolve and parse all the `.vue` files under `rootDir`,
94+
// and only apply the loosened rules to the files that do need them.
95+
//
96+
// rootDir: __dirname,
97+
})
98+
]
6999
```
70100

101+
## Further Reading
102+
103+
TODO
104+
71105
### With Other Community Configs
72106

73107
Work-In-Progress.
74108

75109
~~If you are following the [`standard`](https://standardjs.com/) or [`airbnb`](https://github.com/airbnb/javascript/) style guides, don't manually extend from this package. Please use `@vue/eslint-config-standard-with-typescript` or `@vue/eslint-config-airbnb-with-typescript` instead.~~
110+
111+
## Migrating from `.eslintrc.cjs`
112+
113+
TODO

0 commit comments

Comments
 (0)