|
4 | 4 |
|
5 | 5 | See [@typescript-eslint/eslint-plugin](https://typescript-eslint.io/rules/) for available rules.
|
6 | 6 |
|
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 |
8 | 8 | and is not meant for outside use (it can be used but some adaptations
|
9 | 9 | on the user side might be needed - for details see the config file).
|
10 | 10 |
|
11 | 11 | 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 |
13 | 13 | extended in the same resulting config.
|
14 | 14 |
|
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. |
16 | 16 |
|
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 |
18 | 18 |
|
19 | 19 | ```sh
|
20 |
| -npm add --dev @vue/eslint-config-typescript @rushstack/eslint-patch |
| 20 | +npm add --dev @vue/eslint-config-typescript |
21 | 21 | ```
|
22 | 22 |
|
23 |
| -## Usage |
| 23 | +Please also make sure that you have `typescript` and `eslint` installed. |
24 | 24 |
|
25 |
| -This package comes with 2 rulesets. |
26 |
| - |
27 |
| -### `@vue/eslint-config-typescript` |
| 25 | +## Usage |
28 | 26 |
|
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. |
32 | 28 |
|
33 |
| -An example `.eslintrc.cjs`: |
| 29 | +### Minimal setup |
34 | 30 |
|
35 | 31 | ```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 | +}] |
46 | 40 | ```
|
47 | 41 |
|
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). |
49 | 43 |
|
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">`). |
52 | 45 |
|
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 |
57 | 47 |
|
58 | 48 | ```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 | +] |
69 | 99 | ```
|
70 | 100 |
|
| 101 | +## Further Reading |
| 102 | + |
| 103 | +TODO |
| 104 | + |
71 | 105 | ### With Other Community Configs
|
72 | 106 |
|
73 | 107 | Work-In-Progress.
|
74 | 108 |
|
75 | 109 | ~~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