| name | coding-standards |
| description | Detailed coding standards and best practices including clean code, SOLID, and common patterns. Use when writing or reviewing code. |
| license | Apache 2.0 |
Coding Standards
When to Use This Skill
- Writing new code
- Code reviews
- Setting up coding standards
Core Concepts
Clean Code Principles
Meaningful Names:
function calculateMonthlyInterest(principal: number, rate: number): number { ... }
const daysSinceCreation = 45;
function calc(d: number, r: number): number { ... }
const d = 45;
Small Functions:
async function createUser(data: CreateDto) {
validateData(data);
const user = await repository.create(data);
await sendWelcomeEmail(user);
return user;
}
Single Responsibility:
class UserService { getUser(id) { ... } }
class UserRepository { save(user) { ... } }
SOLID Principles
- Single Responsibility: One reason to change
- Open/Closed: Open for extension, closed for modification
- Liskov Substitution: Subtypes must be substitutable
- Interface Segregation: Many specific interfaces
- Dependency Inversion: Depend on abstractions
Error Handling
class AppError extends Error {
constructor(public code: string, message: string, public statusCode: number) {
super(message);
}
}
Logging
logger.info('User created', { userId: user.id });
logger.error('Failed', { error: err.message });
References