From 35b812e594080e0a1187294065227cc2289fd7af Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Wed, 29 Apr 2026 07:41:51 +0800 Subject: [PATCH] chore(web): eslint flat-config + prettier setup --- .gitignore | 1 + web/.prettierignore | 7 +++++++ web/.prettierrc | 6 ++++++ web/eslint.config.js | 37 +++++++++++++++++++++++++++++++++++++ web/package.json | 3 ++- web/pnpm-lock.yaml | 3 +++ web/src/styles/tailwind.css | 2 +- web/src/styles/tokens.css | 5 +++-- 8 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 web/.prettierignore create mode 100644 web/.prettierrc create mode 100644 web/eslint.config.js diff --git a/.gitignore b/.gitignore index d65aa3e..5d69a75 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ coverage.html /web/dist/ /web/*.tsbuildinfo /web/*.js +!/web/eslint.config.js /web/*.d.ts /web/src/**/*.js /web/src/**/*.d.ts diff --git a/web/.prettierignore b/web/.prettierignore new file mode 100644 index 0000000..e0ff50c --- /dev/null +++ b/web/.prettierignore @@ -0,0 +1,7 @@ +node_modules +dist +pnpm-lock.yaml +*.tsbuildinfo +*.d.ts +vite.config.js +src/**/*.js diff --git a/web/.prettierrc b/web/.prettierrc new file mode 100644 index 0000000..0965e7e --- /dev/null +++ b/web/.prettierrc @@ -0,0 +1,6 @@ +{ + "semi": false, + "singleQuote": true, + "trailingComma": "all", + "printWidth": 100 +} diff --git a/web/eslint.config.js b/web/eslint.config.js new file mode 100644 index 0000000..8da663a --- /dev/null +++ b/web/eslint.config.js @@ -0,0 +1,37 @@ +// ESLint v10 flat config。 +// 覆盖范围:src/、test/ 下的 .vue/.ts/.tsx 文件。dist/、node_modules、配置类 +// 文件 (vite.config.ts、postcss.config.js 等) 默认走 ignore。 +import js from '@eslint/js' +import tseslint from 'typescript-eslint' +import vue from 'eslint-plugin-vue' +import vueParser from 'vue-eslint-parser' + +export default [ + { + ignores: ['dist/**', 'node_modules/**', '**/*.d.ts', 'src/**/*.js', 'vite.config.js'], + }, + js.configs.recommended, + ...tseslint.configs.recommended, + ...vue.configs['flat/recommended'], + { + files: ['**/*.vue'], + languageOptions: { + parser: vueParser, + parserOptions: { + parser: tseslint.parser, + ecmaVersion: 2022, + sourceType: 'module', + }, + }, + }, + { + files: ['**/*.{ts,tsx,vue}'], + rules: { + 'vue/multi-word-component-names': 'off', + '@typescript-eslint/no-unused-vars': [ + 'error', + { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }, + ], + }, + }, +] diff --git a/web/package.json b/web/package.json index 1b29eab..a33be40 100644 --- a/web/package.json +++ b/web/package.json @@ -10,7 +10,7 @@ "preview": "vite preview", "test": "vitest run", "test:watch": "vitest", - "lint": "eslint . --ext .vue,.ts,.tsx", + "lint": "eslint .", "format": "prettier -w .", "typecheck": "vue-tsc --noEmit" }, @@ -41,6 +41,7 @@ "typescript-eslint": "^8.59.1", "vite": "^8.0.10", "vitest": "^4.1.5", + "vue-eslint-parser": "^10.4.0", "vue-tsc": "^3.2.7" } } diff --git a/web/pnpm-lock.yaml b/web/pnpm-lock.yaml index ddb086b..7dfc905 100644 --- a/web/pnpm-lock.yaml +++ b/web/pnpm-lock.yaml @@ -69,6 +69,9 @@ importers: vitest: specifier: ^4.1.5 version: 4.1.5(@types/node@25.6.0)(happy-dom@20.9.0)(vite@8.0.10(@types/node@25.6.0)(jiti@2.6.1)(yaml@2.8.3)) + vue-eslint-parser: + specifier: ^10.4.0 + version: 10.4.0(eslint@10.2.1(jiti@2.6.1)) vue-tsc: specifier: ^3.2.7 version: 3.2.7(typescript@6.0.3) diff --git a/web/src/styles/tailwind.css b/web/src/styles/tailwind.css index 2ea9a8c..062569c 100644 --- a/web/src/styles/tailwind.css +++ b/web/src/styles/tailwind.css @@ -1,3 +1,3 @@ -@import "tailwindcss"; +@import 'tailwindcss'; @variant dark (&:where(.dark, .dark *)); diff --git a/web/src/styles/tokens.css b/web/src/styles/tokens.css index a002bba..0d19431 100644 --- a/web/src/styles/tokens.css +++ b/web/src/styles/tokens.css @@ -15,6 +15,7 @@ body { background: var(--color-bg); color: var(--color-fg); - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", - Arial, "Microsoft YaHei", sans-serif; + font-family: + -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, 'Microsoft YaHei', + sans-serif; }