Code Standards Configuration
This document details the project's code standard configurations, including the purpose and usage of tools like EditorConfig, Prettier, and ESLint.
📚 Configuration Files Overview
The project uses the following configuration files to ensure code quality and consistency:
1. EditorConfig - Editor Basic Configuration
🎯 Purpose
- Cross-editor unified coding style
- Native editor support without any tools
- All developers use the same editor settings
📋 Configuration Content
💡 When It Takes Effect
- When opening a file - Editor automatically applies these settings
- When creating a new file - Editor automatically uses these settings
- When saving a file - Auto-formatting (if editor supports it)
🔍 Supported Editors
- VS Code (built-in support)
- WebStorm (built-in support)
- Sublime Text (plugin required)
- Vim (plugin required)
- And more...
2. Prettier - Code Formatting Configuration
🎯 Purpose
- Automatically format code
- Unified code style
- Reduce formatting disputes in code reviews
📋 Configuration Content
💡 Usage
🔍 Formatting Example
Before formatting:
After formatting:
3. ESLint - Code Quality Check Configuration
🎯 Purpose
- Check code quality issues
- Find potential errors
- Enforce best practices
- Work with Prettier to avoid conflicts
📋 Configuration Content
💡 Usage
🔍 Check Example
Problematic code:
Fixed code:
4. Ignore Files
.prettierignore
.eslintignore
💡 Why Ignore Files Are Needed
- Build output - Should not be modified or checked
- Minified files - Already optimized
- Lock files - Auto-generated, should not be modified
🔄 Relationship Between the Three
Workflow
Division of Responsibilities
Working Together
✅ Correct Configuration Order
💡 Why prettier Should Be Last
- Disables ESLint rules that conflict with Prettier
- Let Prettier handle formatting
- Let ESLint handle code quality
🎯 Practical Use Cases
Case 1: Creating New File
Case 2: Formatting Existing Code
Case 3: CI/CD Check
📊 Summary Comparison
💡 Best Practices
1. Editor Configuration
Install in VS Code:
- EditorConfig for VS Code
- Prettier - Code formatter
- ESLint
2. Auto-formatting
Configure in .vscode/settings.json:
3. Pre-commit Check
Use Husky + lint-staged: