Agent skill
code-quality
Provides general code quality and best practices guidance applicable across languages and frameworks. Focuses on linting, testing, and type safety.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/code-quality-allenlin90-eridu-services
SKILL.md
Code Quality Skill
Provides general code quality and best practices guidance applicable across languages and frameworks. Focuses on Linting, Testing, and Type Safety.
For architecture-specific patterns (N+1 queries, Soft Deletes, etc.), refer to:
- Database Patterns
- Service Patterns
- Repository Patterns
Pre-Submission Checklist
Before marking any task as complete:
- Ensure
pnpm lintpasses (no ESLint rule disables). - Ensure
pnpm testpasses (new features have tests). - Ensure
pnpm buildsucceeds (no TypeScript errors). - Avoid
any/unknowntypes (maintain strict type safety). - Remove
console.logstatements (use a dedicated logger). - Ensure error messages are clear and actionable.
Linting
We use ESLint with strict rules.
- Command:
pnpm lint(orpnpm lint -- --fix) - Rule: NEVER disable rules with
eslint-disable. Fix the underlying issue.
Common Fixes:
@typescript-eslint/no-explicit-any: Define a proper interface/DTO.no-unused-vars: Remove the variable or prefix with_.no-console: Inject aLoggerservice.
Testing
All new features require tests.
- Unit Tests: Test individual classes (Services, Utils) with mocked dependencies.
- Integration Tests: Test interactions (Repositories) with real database/services.
Example (Unit Test):
describe('UserService', () => {
it('should return user when found', async () => {
// 1. Arrange (Mock dependencies)
const mockRepo = { findByUid: jest.fn().mockResolvedValue(user) };
const service = new UserService(mockRepo as any);
// 2. Act
const result = await service.getUser('u_1');
// 3. Assert
expect(result).toEqual(user);
expect(mockRepo.findByUid).toHaveBeenCalledWith('u_1');
});
});
TypeScript Type Safety
Strict mode is enforced.
-
❌ Avoid
any/unknown:typescript// BAD const data: any = req.body; // GOOD const data: CreateUserDto = req.body; -
✅ Use DTOs and Interfaces: Always define shapes for inputs and outputs.
-
✅ Trust the Compiler: If it compiles, it should likely run (if types are accurate).
Common Anti-Patterns (General)
- Ignoring Lint Errors: Address them immediately.
- Logic in Controllers: Controllers should only handle HTTP req/res. Move logic to Services.
- Hardcoded Strings/Magic Numbers: Use constants or enums.
- Complex Conditionals: Break down complex
if/elseblocks into helper methods. - Catch-All Error Handling: Avoid just using
console.error. Handle specific errors or let global filters handle them.
Related Skills
- database-patterns/SKILL.md: N+1 queries, Soft Deletes, Bulk Operations.
- service-pattern-nestjs/SKILL.md: Business logic errors, Transactions.
- repository-pattern-nestjs/SKILL.md: Data access rules.
- backend-controller-pattern-nestjs/SKILL.md: NestJS-specific controller rules.
- frontend-code-quality/SKILL.md: React/Frontend specific patterns.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?