π Rules
Rules are guidelines that the AI must always follow to ensure code quality and team consistency.
What Are Rules?β
Rules are like team conventions:
- π¨ Code style (indentation, naming, formatting)
- π Security standards (secret management, input validation)
- ποΈ Architecture conventions (directory structure, layered design)
- π§ͺ Testing requirements (coverage, testing strategy)
Rule Hierarchyβ
1. Global Rulesβ
Apply to all projects, configured in ~/.claude/rules/:
~/.claude/rules/
βββ common/
β βββ coding-style.md
β βββ security.md
β βββ testing.md
βββ typescript/
βββ coding-style.md
βββ patterns.md
2. Project Rulesβ
Apply to specific projects, configured in the project root .codebuddy/rules/:
your-project/
βββ .codebuddy/rules/
βββ project-conventions.md
βββ api-design.md
Core Rule Examplesβ
Coding Style Rulesβ
# TypeScript Coding Style
## Naming Conventions
- Variables/Functions: camelCase
- Classes/Interfaces: PascalCase
- Constants: UPPER_SNAKE_CASE
- File names: kebab-case.ts
## Prohibited
- β Using the any type
- β console.log in production code
- β Hardcoded secrets or passwords
Security Rulesβ
# Security Rules
## Secret Management
β
CORRECT:
const apiKey = process.env.API_KEY
β WRONG:
const apiKey = "sk-xxxxx"
## Input Validation
- All user input must be validated
- Use Zod for schema validation
Testing Rulesβ
# Testing Rules
## Coverage Requirements
- Core business logic: >= 80%
- Utility functions: >= 90%
- UI components: >= 70%
## Test Naming
describe('ComponentName', () => {
it('should [expected behavior] when [condition]', () => {})
})
Rule File Formatβ
Rule files use Markdown format with the following structure:
---
name: my-rule
priority: high
scope: typescript
---
File content structure:
- # Rule Name - Rule title
- ## Background - Why this rule is needed
- ## Rule Content - Specific rule descriptions
- ## Correct Examples - Show correct code patterns
- ## Wrong Examples - Show incorrect code patterns
- ## Exceptions - When exceptions are allowed
Rule Priorityβ
Rules are applied in the following priority order:
- Project Rules - Highest priority
- Language-Specific Rules - Secondary priority
- Global Common Rules - Baseline rules
Installing Language Rule Packsβ
ECC provides pre-configured language rule packs:
# Install TypeScript rules
cp -r rules/typescript/* ~/.codebuddy/rules/
# Install Python rules
cp -r rules/python/* ~/.codebuddy/rules/
# Install Go rules
cp -r rules/golang/* ~/.codebuddy/rules/
Best Practicesβ
- Be specific - Avoid vague descriptions
- Provide examples - Show both correct and incorrect code
- Explain the why - Explain why the rule exists
- Allow exceptions - Clearly state when exceptions are acceptable
- Update regularly - Update rules as the project evolves
π‘ Tip: Good rules should be team consensus β it's recommended to discuss with the team before adding new rules!