1// .eslintrc.js
2module.exports = {
3 env: {
4 browser: true,
5 es2021: true,
6 node: true,
7 },
8 extends: [
9 'eslint:recommended', // eslint 推荐规范
10 '@vue/typescript/recommended', // 校验 .vue 文件的 ts,需要安装 npm i @vue/eslint-config-typescript -D
11 'plugin:@typescript-eslint/recommended', // ts 语法插件
12 'plugin:vue/vue3-recommended', // vue3解析 https://eslint.vuejs.org/
13 'plugin:prettier/recommended', // 使 eslint 使用 prettierrc 的规则来校验,避免两者之间的格式冲突,添加到数组的最后一个元素覆盖来去除不必要的规则冲突。
14 ],
15 parserOptions: {
16 ecmaVersion: 'latest',
17 parser: '@typescript-eslint/parser',
18 sourceType: 'module',
19 },
20 plugins: ['vue', '@typescript-eslint'],
21 rules: {
22 'vue/html-self-closing': 'off', // 禁用强制将 <MyComponent></MyComponent> 必须使用 <MyComponent/> 的校验
23 'vue/singleline-html-element-content-newline': 'off',
24 'vue/multi-word-component-names': 'off', // 禁用注册组件 name 不能使用 大写 的报错
25 'vue/prefer-import-from-vue': 'off', // 禁用 import x from '@vue/runtime-dom' 包以 @/ 开头的报错
26 '@typescript-eslint/no-non-null-assertion': 'off', // 允许使用 ts 语法 obj!.a
27 'vue/valid-v-for': 'off', // 禁用 v-for 语法校验, vue3 v-for 不需要绑定 :key,不禁用会报没有绑定 key 的警告
28 },
29 globals: {
30 defineOptions: 'readonly', // unplugin-vue-define-options vite 插件的全局变量
31 },
32}