Code Review and Refactor

Category: Code Quality October 1, 2025 Source: awesome-copilot

Perform a thorough code review of selected code with actionable refactoring suggestions and best practices.

Code ReviewRefactoringBest PracticesQuality
# Code Review and Refactor

Conduct a comprehensive code review of the selected code or file, identifying issues and providing specific refactoring recommendations.

## Review Criteria

### 1. Code Quality
- **Readability**: Is the code easy to understand?
- **Maintainability**: Can the code be easily modified?
- **Consistency**: Does it follow project conventions?
- **Complexity**: Are there overly complex sections that could be simplified?

### 2. Performance
- Identify performance bottlenecks
- Suggest optimization opportunities
- Check for unnecessary computations or memory allocations
- Look for N+1 query problems in database operations

### 3. Security
- Check for common security vulnerabilities
- Validate input handling and sanitization
- Review authentication and authorization logic
- Identify potential injection vulnerabilities

### 4. Best Practices
- Design patterns appropriately used
- SOLID principles adherence
- DRY (Don't Repeat Yourself) principle
- Separation of concerns
- Error handling and logging

### 5. Testing
- Test coverage adequacy
- Edge cases handled
- Error scenarios tested
- Mock usage appropriate

## Output Format

For each issue found, provide:

1. **Severity**: Critical, High, Medium, Low
2. **Category**: Performance, Security, Readability, Best Practice, etc.
3. **Location**: File name and line number
4. **Issue Description**: Clear explanation of the problem
5. **Impact**: Why this matters
6. **Recommendation**: Specific refactoring suggestion with code example
7. **Effort**: Estimated time to fix (Small, Medium, Large)

## Refactoring Approach

- Start with high-severity issues first
- Group related changes together
- Provide before/after code examples
- Explain the reasoning behind each change
- Consider backward compatibility
- Suggest testing strategies for refactored code

## Additional Checks

- Documentation completeness
- Naming conventions (variables, functions, classes)
- Code duplication
- Dead code or unused imports
- Magic numbers or hard-coded values
- Proper use of language idioms
- API design and interface clarity