Переглянути джерело

chore: 添加 ESLint、Prettier 和 Husky 配置

- 新增 ESLint 配置,包含 Vue 和 TypeScript 支持
- 添加 Prettier 配置及忽略文件
- 配置 Husky 的 pre-commit 钩子
- 更新 package.json 添加相关脚本和依赖
piks 2 днів тому
батько
коміт
3276db87e1
6 змінених файлів з 641 додано та 1 видалено
  1. 1 0
      .husky/pre-commit
  2. 3 0
      .prettierignore
  3. 9 0
      .prettierrc
  4. 45 0
      eslint.config.js
  5. 22 1
      package.json
  6. 561 0
      pnpm-lock.yaml

+ 1 - 0
.husky/pre-commit

@@ -0,0 +1 @@
+npx lint-staged

+ 3 - 0
.prettierignore

@@ -0,0 +1,3 @@
+dist
+node_modules
+*.min.js

+ 9 - 0
.prettierrc

@@ -0,0 +1,9 @@
+{
+  "semi": false,
+  "singleQuote": true,
+  "printWidth": 100,
+  "tabWidth": 2,
+  "trailingComma": "es5",
+  "endOfLine": "lf",
+  "vueIndentScriptAndStyle": true
+}

+ 45 - 0
eslint.config.js

@@ -0,0 +1,45 @@
+import js from '@eslint/js'
+import tseslint from 'typescript-eslint'
+import pluginVue from 'eslint-plugin-vue'
+import prettierConfig from 'eslint-config-prettier'
+
+export default [
+  // 忽略目录
+  { ignores: ['dist/**', 'node_modules/**'] },
+
+  // JS 基础规则
+  js.configs.recommended,
+
+  // TypeScript 规则
+  ...tseslint.configs.recommended,
+
+  // Vue3 规则
+  ...pluginVue.configs['flat/recommended'],
+
+  // .vue 文件使用 ts 解析器
+  {
+    files: ['**/*.vue'],
+    languageOptions: {
+      parserOptions: {
+        parser: tseslint.parser,
+      },
+    },
+  },
+
+  // 关闭与 Prettier 冲突的规则(必须放最后)
+  prettierConfig,
+
+  // 自定义规则
+  {
+    languageOptions: {
+      globals: {
+        process: 'readonly',
+      },
+    },
+    rules: {
+      'vue/multi-word-component-names': 'off',
+      '@typescript-eslint/no-explicit-any': 'warn',
+      'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
+    },
+  },
+]

+ 22 - 1
package.json

@@ -6,7 +6,11 @@
   "scripts": {
     "dev": "vite",
     "build": "vue-tsc -b && vite build",
-    "preview": "vite preview"
+    "preview": "vite preview",
+    "prepare": "husky",
+    "lint": "eslint .",
+    "lint:fix": "eslint . --fix",
+    "format": "prettier --write ."
   },
   "dependencies": {
     "@element-plus/icons-vue": "^2.3.2",
@@ -22,17 +26,34 @@
     "vue-router": "^5.0.3"
   },
   "devDependencies": {
+    "@eslint/js": "^10.0.1",
     "@types/node": "^24.12.0",
     "@vitejs/plugin-vue": "^6.0.5",
     "@vue/tsconfig": "^0.9.0",
+    "eslint": "^10.1.0",
+    "eslint-config-prettier": "^10.1.8",
+    "eslint-plugin-vue": "^10.8.0",
     "fast-glob": "^3.3.3",
+    "husky": "^9.1.7",
+    "lint-staged": "^16.4.0",
+    "prettier": "^3.8.1",
     "sass-embedded": "^1.98.0",
     "typescript": "~5.9.3",
+    "typescript-eslint": "^8.57.2",
     "unplugin-auto-import": "^21.0.0",
     "unplugin-vue-components": "^31.0.0",
     "vite": "^8.0.0",
     "vite-plugin-compression": "^0.5.1",
     "vite-plugin-svg-icons": "^2.0.1",
     "vue-tsc": "^3.2.5"
+  },
+  "lint-staged": {
+    "*.{vue,ts,tsx,js,jsx}": [
+      "eslint --fix",
+      "prettier --write"
+    ],
+    "*.{css,scss,html,json,md}": [
+      "prettier --write"
+    ]
   }
 }

Різницю між файлами не показано, бо вона завелика
+ 561 - 0
pnpm-lock.yaml


Деякі файли не було показано, через те що забагато файлів було змінено