diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 363f33c51ccd6c322a73335276db24af8c6c433a..271b76a621d3edc3c0fa2cc22acdbaee1f5fa221 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -56,11 +56,96 @@ function processData(data: any) { } ``` +#### ESLint 规范 + +- 使用项目配置的 ESLint 规则 +- 在提交代码前运行 ESLint 检查 +- 修复所有 ESLint 错误和警告 + +```typescript +// ESLint 配置示例 +module.exports = { + root: true, + env: { + browser: true, + node: true, + }, + extends: [ + "plugin:vue/vue3-recommended", + "plugin:@typescript-eslint/recommended", + "@vue/typescript/recommended", + "prettier", + ], + parser: "vue-eslint-parser", + parserOptions: { + ecmaVersion: 2022, + parser: "@typescript-eslint/parser", + sourceType: "module", + }, + rules: { + // Vue 3 规则 + "vue/script-setup-uses-vars": "error", + "vue/no-unused-vars": "error", + "vue/multi-word-component-names": "error", + "vue/component-tags-order": [ + "error", + { + order: ["script", "template", "style"], + }, + ], + + // TypeScript 规则 + "@typescript-eslint/explicit-function-return-type": "off", + "@typescript-eslint/no-explicit-any": "error", + "@typescript-eslint/no-unused-vars": [ + "error", + { + argsIgnorePattern: "^_", + varsIgnorePattern: "^_", + }, + ], + + // 通用规则 + "no-console": process.env.NODE_ENV === "production" ? "warn" : "off", + "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off", + "prefer-const": "error", + "no-var": "error", + eqeqeq: ["error", "always"], + }, +}; +``` + +常见 ESLint 规则说明: + +- `vue/script-setup-uses-vars`: 确保 `