浏览代码

build(eslint): 添加 TypeScript 支持并更新 ESLint 配置

yz 6 天之前
父节点
当前提交
d7a648f642
共有 3 个文件被更改,包括 1076 次插入117 次删除
  1. 36 3
      .eslintrc.js
  2. 1035 113
      package-lock.json
  3. 5 1
      package.json

+ 36 - 3
.eslintrc.js

@@ -3,6 +3,8 @@ module.exports = {
   env: {
     node: true
   },
+  parser: '@typescript-eslint/parser',   // 关键
+  plugins: ['@typescript-eslint'],
   'extends': [
     'plugin:vue/essential',
     'eslint:recommended'
@@ -10,9 +12,40 @@ module.exports = {
   rules: {
     'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
     'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
-    "no-unused-vars":"off" //关闭声明后未被使用的变量或参数
+    "no-unused-vars":"off", //关闭声明后未被使用的变量或参数
+    "no-prototype-builtins": "off", // 允许直接调用Object.prototype方法
+    "vue/no-unused-components": "off", // 允许未使用的组件
+    "vue/no-unused-vars": "off", // 允许模板中未使用的变量
+    "vue/no-parsing-error": "off", // 允许Vue模板解析错误
+    "no-redeclare": "off", // 允许重复声明
+    "no-self-assign": "off", // 允许自我赋值
+    "vue/no-mutating-props": "off", // 允许修改props
+    "vue/no-use-v-if-with-v-for": "off", // 允许v-if与v-for一起使用
+    "vue/require-valid-default-prop": "off", // 允许props默认值不是函数
+    "no-irregular-whitespace": "off" // 允许不规则空白
   },
   parserOptions: {
-    parser: 'babel-eslint'
-  }
+    ecmaVersion: 2020,
+    sourceType: 'module',
+    project: './tsconfig.json',   // 如有类型检查规则
+    extraFileExtensions: ['.vue']
+  },
+  overrides: [
+    {
+      files: ['*.ts', '*.tsx', '*.d.ts'],
+      rules: {
+        // 如有需要关掉历史规则
+      }
+    },
+    {
+      files: ['*.vue'],
+      parser: 'vue-eslint-parser',
+      parserOptions: {
+        parser: '@typescript-eslint/parser',
+        extraFileExtensions: ['.vue'],
+        ecmaVersion: 2020,
+        sourceType: 'module'
+      }
+    }
+  ]
 }

文件差异内容过多而无法显示
+ 1035 - 113
package-lock.json


+ 5 - 1
package.json

@@ -46,16 +46,20 @@
     "@types/axios": "^0.14.4",
     "@types/smallwei__avue": "^3.0.5",
     "@types/webpack-env": "^1.18.8",
+    "@typescript-eslint/eslint-plugin": "^4.33.0",
+    "@typescript-eslint/parser": "^4.33.0",
     "@vue/cli-plugin-babel": "^3.1.1",
     "@vue/cli-plugin-eslint": "^3.1.5",
     "@vue/cli-service": "^3.1.4",
     "chai": "^4.1.2",
+    "eslint": "^7.32.0",
+    "eslint-plugin-vue": "^7.20.0",
     "image-webpack-loader": "^8.1.0",
     "node-sass": "^4.12.0",
     "null-loader": "^4.0.1",
     "sass-loader": "^7.0.1",
     "ts-loader": "^8.4.0",
-    "typescript": "^5.9.2",
+    "typescript": "^4.4.4",
     "vue-template-compiler": "^2.5.17",
     "webpack-bundle-analyzer": "^3.0.3"
   },

部分文件因为文件数量过多而无法显示