# 工具链配置 > **文档版本**:v1.1 > **最后更新**:2025-01-18 --- ## 目录 1. [ESLint 配置](#1-eslint-配置) 2. [Prettier 配置](#2-prettier-配置) 3. [Husky + lint-staged](#3-husky--lint-staged) 4. [TypeScript 配置](#4-typescript-配置) --- ## 1. ESLint 配置 ### 1.1 Flat Config ```javascript // eslint.config.js import js from "@eslint/js"; import globals from "globals"; import reactHooks from "eslint-plugin-react-hooks"; import reactRefresh from "eslint-plugin-react-refresh"; import tseslint from "typescript-eslint"; import eslintConfigPrettier from "eslint-config-prettier"; export default tseslint.config( { ignores: ["dist", "node_modules"] }, { extends: [js.configs.recommended, ...tseslint.configs.recommended], files: ["**/*.{ts,tsx}"], languageOptions: { ecmaVersion: 2020, globals: globals.browser, }, plugins: { "react-hooks": reactHooks, "react-refresh": reactRefresh, }, rules: { ...reactHooks.configs.recommended.rules, "react-refresh/only-export-components": [ "warn", { allowConstantExport: true }, ], "@typescript-eslint/no-unused-vars": [ "error", { argsIgnorePattern: "^_" }, ], "@typescript-eslint/no-explicit-any": "warn", }, }, eslintConfigPrettier, ); ``` --- ## 2. Prettier 配置 ```json // .prettierrc { "semi": true, "singleQuote": true, "tabWidth": 2, "trailingComma": "es5", "printWidth": 100, "bracketSpacing": true, "arrowParens": "always", "endOfLine": "lf", "jsxSingleQuote": false, "bracketSameLine": false } ``` --- ## 3. Husky + lint-staged ```json // package.json { "lint-staged": { "*.{ts,tsx}": ["eslint --fix", "prettier --write"], "*.{json,css,md}": ["prettier --write"] } } ``` ```bash # .husky/pre-commit #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" npx lint-staged ``` --- ## 4. TypeScript 配置 ```json // tsconfig.json { "compilerOptions": { "target": "ES2020", "useDefineForClassFields": true, "lib": ["ES2020", "DOM", "DOM.Iterable"], "module": "ESNext", "skipLibCheck": true, "moduleResolution": "bundler", "allowImportingTsExtensions": true, "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, "baseUrl": ".", "paths": { "@/*": ["src/*"] } }, "include": ["src"], "references": [{ "path": "./tsconfig.node.json" }] } ``` --- ## 相关文档 - [开发规范](./13-dev-standards.md) - [构建与开发环境](./03-build-environment.md) --- **最后更新**:2025-01-18 | **版本**:v1.1