review-code
Perform comprehensive csharp/dotnet code reviews focusing on clean code, security, testing, performance, and documentation
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Perform comprehensive csharp/dotnet code reviews focusing on clean code, security, testing, performance, and documentation
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Create a new implementation plan file for new features, refactoring existing code or upgrading packages, design, architecture or infrastructure.
Use when documenting significant technical or architectural decisions that need context, rationale, and consequences recorded. Invoke when choosing between technology options, making infrastructure decisions, establishing standards, migrating systems, or when team needs to understand why a decision was made. Use when user mentions ADR, architecture decision, technical decision record, or decision documentation.
Use when designing new system architecture, reviewing existing designs, or making architectural decisions. Invoke for system design, architecture review, design patterns, ADRs, scalability planning.
Automatically creates or updates changelogs from git commits by analyzing commit history, categorizing changes and transforming technical commits into clear, customer-friendly release notes. Turns hours of manual changelog writing into minutes of automated generation.
Write modern, high-performance C# code using records, pattern matching, value objects, async/await, Span<T>/Memory<T>, and best-practice API design patterns. Emphasizes functional-style programming with C# 12+ features.
Manage NuGet packages using Central Package Management (CPM), dotnet CLI, and dotnet-outdated (command `dotnet outdated`) to inspect/update dependencies and diagnose restore issues. Never edit XML directly—prefer dotnet commands and dotnet-outdated.
| name | review-code |
| description | Perform comprehensive csharp/dotnet code reviews focusing on clean code, security, testing, performance, and documentation |
This skill provides comprehensive code review guidelines for GitHub Copilot focused on C# and .NET development. It follows industry best practices and provides a structured approach to evaluating code quality, security, testing, performance, and architecture.
What This Skill Does:
.editorconfig standardsWhen to Apply: Use this skill when reviewing pull requests, conducting code audits, or validating code quality before merge. This skill is on-demand (not automatic) - invoke it explicitly when performing code reviews.
When performing a code review, prioritize issues in the following order:
Issues that must be fixed before merging. These represent serious risks to security, correctness, or system stability.
Security Vulnerabilities:
Correctness Issues:
Breaking Changes:
Data Loss Risks:
Resource Management:
IDisposable objects (DbContext, streams, HttpClient).editorconfig Violations (ERROR level):
csharp_style_namespace_declarations = file_scoped:error)var usage violations (csharp_style_var_*:error)csharp_using_directive_placement = inside_namespace:error)Issues that should be addressed but may not block merge if there's a valid reason to defer.
Code Quality:
Test Coverage:
Performance Issues:
Architecture Violations:
Async/Await Issues:
.Result, .Wait()) - can cause deadlocksCancellationToken parameters in async methodsImprovements that enhance code quality but don't require immediate action.
Readability:
Optimization Opportunities:
Span<T> could improve performanceValueTask<T> over Task<T>ReadOnlySpan<T> for string operationsBest Practices:
Documentation:
<summary> descriptions<param> or <returns> tagsModern C# Features:
Follow these principles when conducting code reviews:
Use these checklists for systematic code review:
File: checklists/01-code-quality.md
Focus Areas:
I prefix).editorconfig)var usage (🔴 MANDATORY - enforced by .editorconfig)When to Use: Every code review should check these fundamentals.
File: checklists/02-security.md
Focus Areas:
When to Use: Always check when code handles sensitive data, external inputs, or database operations.
File: checklists/03-testing.md
Focus Areas:
Should_ExpectedBehavior_When_Condition)When to Use: When reviewing test code or checking if new features have adequate tests.
File: checklists/04-performance.md
Focus Areas:
.Result, .Wait())When to Use: When reviewing performance-critical code, async code, or long-running operations.
File: checklists/05-documentation.md
Focus Areas:
<summary>, <param>, <returns>)<exception> tags) only for public methods and methods that throw and do not return a Result or ResultWhen to Use: When reviewing public APIs or complex domain logic.
This project enforces code style through .editorconfig rules. The following rules are MANDATORY (error level) and violations are 🔴 CRITICAL:
Rule: csharp_style_namespace_declarations = file_scoped:error
What it means: All C# files must use file-scoped namespace syntax (not block-scoped).
Example:
// 🔴 WRONG: Block-scoped namespace (CRITICAL VIOLATION)
namespace MyApp.Services {
public class PaymentService { }
}
// ✅ CORRECT: File-scoped namespace (MANDATORY)
namespace MyApp.Services;
public class PaymentService { }
Why it matters: File-scoped namespaces reduce indentation, improve readability, and are the modern C# convention (C# 10+).
How to fix: Convert all block-scoped namespaces to file-scoped. Run dotnet format to auto-fix.
Rules:
csharp_style_var_elsewhere = true:errorcsharp_style_var_for_built_in_types = true:errorcsharp_style_var_when_type_is_apparent = true:errorWhat it means: Always use var for local variables (unless there's a specific reason not to).
Example:
// 🔴 WRONG: Explicit type when obvious (CRITICAL VIOLATION)
Customer customer = new Customer();
int count = 42;
List<string> names = new List<string>();
// ✅ CORRECT: Use var (MANDATORY)
var customer = new Customer();
var count = 42;
var names = new List<string>();
Why it matters: var reduces verbosity, improves maintainability (when types change), and is the modern C# convention.
How to fix: Replace explicit types with var. Run dotnet format to auto-fix.
Rule: csharp_using_directive_placement = inside_namespace:error
What it means: using directives must be placed inside the namespace (after the namespace declaration).
Example:
// 🔴 WRONG: Using directives outside namespace (CRITICAL VIOLATION)
using System;
using System.Collections.Generic;
namespace MyApp.Services;
public class PaymentService { }
// ✅ CORRECT: Using directives inside namespace (MANDATORY)
namespace MyApp.Services;
using System;
using System.Collections.Generic;
public class PaymentService { }
Why it matters: Placement inside namespace prevents naming conflicts and follows project conventions.
How to fix: Move using directives after the namespace declaration. Run dotnet format to auto-fix.
Run formatter:
dotnet format
This will automatically fix most .editorconfig violations including the three CRITICAL rules above.
Check for violations (dry run):
dotnet format --verify-no-changes
This reports violations without modifying files. Use in CI/CD pipelines to block PRs with violations.
See examples/editorconfig-compliance.md for detailed examples of:
Use these example files for code patterns:
File: examples/clean-code-examples.md
Contains:
var usage patternsWhen to Use: Reference when reviewing code style, naming, or C# idioms.
File: examples/security-examples.md
Contains:
When to Use: Reference when reviewing security-sensitive code.
File: examples/testing-examples.md
Contains:
When to Use: Reference when reviewing test code or suggesting test improvements.
File: examples/editorconfig-compliance.md
Contains:
dotnet formatWhen to Use: Reference when identifying or fixing .editorconfig violations.
Use these templates for consistent, actionable review comments.
File: templates/review-comment-template.md
Provides:
When to Use: When writing review comments to ensure they're specific, contextual, and actionable.
File: templates/review-summary-template.md
Provides:
When to Use: At the end of a review to summarize findings and provide clear next steps.
Here's a step-by-step workflow for conducting a comprehensive code review:
Focus: Security, correctness, resource management, .editorconfig ERROR violations
Process:
using statements).Result, .Wait())Action: Flag any CRITICAL issues immediately. These must be fixed before merge.
Focus: SOLID principles, test coverage, architecture, async patterns
Process:
Action: Discuss IMPORTANT issues with the author. Decide if they block merge or can be deferred.
Focus: Readability, modern C# features, documentation, optimizations
Process:
Action: Provide SUGGESTIONS for improvements. Mark as non-blocking.
Reference the appropriate checklists based on the code being reviewed:
When suggesting changes, reference the example files:
examples/clean-code-examples.mdexamples/security-examples.mdexamples/testing-examples.mdexamples/editorconfig-compliance.mdUse the comment template (templates/review-comment-template.md) to structure feedback:
Use the summary template (templates/review-summary-template.md) to wrap up:
🔴 CRITICAL - Security: Hardcoded Database Password
**Issue**: Line 42 contains a hardcoded database password in the connection string.
**Why This Matters**: Hardcoded secrets in source code are a critical security vulnerability. They are visible in version control, can be accidentally exposed, and cannot be rotated without code changes.
**Suggested Fix**:
```csharp
// Current (WRONG):
var connectionString = "Server=myserver;Database=mydb;User Id=admin;Password=secret123;";
// Corrected (CORRECT):
var connectionString = this.configuration.GetConnectionString("MyDatabase");
Then store the actual connection string in:
appsettings.json (for local dev, not committed)Reference: See examples/security-examples.md for more secure configuration patterns.
## Integration with Other Skills
This skill works well with other repository skills:
### domain-add-aggregate
When reviewing new domain aggregates, use both skills:
- **review-code**: Check code quality, security, testing
- **domain-add-aggregate**: Verify DDD patterns, layer boundaries, aggregate structure
### review-architecture
For architectural reviews, use both skills:
- **review-code**: Focus on implementation details, security, performance
- **review-architecture**: Focus on DDD patterns, Clean Architecture boundaries, CQRS
### adr-writer
When identifying architectural issues, reference ADRs or create new ones:
- Use **review-code** to identify patterns that should be documented
- Use **adr-writer** to document architectural decisions
## Core Rules
1. **ALWAYS start with CRITICAL issues** (🔴): Security and correctness come first
2. **ALWAYS check .editorconfig compliance**: File-scoped namespaces, var usage, using placement are MANDATORY
3. **ALWAYS provide context**: Explain WHY something is an issue, not just WHAT
4. **ALWAYS suggest solutions**: Show corrected code, don't just point out problems
5. **ALWAYS be specific**: Reference exact locations, methods, line numbers
6. **ALWAYS use priority indicators**: 🔴🟡🟢 to clearly communicate severity
7. **ALWAYS be constructive**: Focus on improving code, not criticizing the author
8. **NEVER demand unrelated refactoring**: Keep feedback scoped to the PR
9. **NEVER block on style issues**: Use formatters (`dotnet format`) for style consistency
10. **NEVER forget to recognize good code**: Acknowledge excellent practices when you see them
## When to Use This Skill
**Use this skill when**:
- Reviewing pull requests before merge
- Conducting code quality audits
- Onboarding new team members (teach review standards)
- Preparing for production releases (final quality check)
- Identifying technical debt (catalog issues for future work)
**DO NOT use this skill when**:
- Code is generated (migrations, scaffolding)
- Code is third-party/vendored (not under your control)
- Review is purely architectural (use `review-architecture` instead)
- Quick bug fix in emergency (defer review to post-fix PR)
## Success Criteria
A successful code review includes:
✅ **All CRITICAL issues identified and fixed** (🔴)
✅ **IMPORTANT issues discussed with author** (🟡)
✅ **Suggestions provided for future improvements** (🟢)
✅ **.editorconfig compliance verified** (file-scoped namespaces, var usage, using placement)
✅ **Security vulnerabilities caught** (hardcoded secrets, SQL injection, input validation)
✅ **Test coverage adequate** (critical paths tested, new features have tests)
✅ **Performance bottlenecks identified** (no blocking async, proper resource disposal)
✅ **Documentation complete** (public APIs have XML comments)
✅ **Feedback is specific and actionable** (includes corrected code examples)
✅ **Review summary provided** (using template, with prioritized next steps)
## Additional Resources
- **Checklists**: See `checklists/` for systematic review guides
- **Examples**: See `examples/` for WRONG vs CORRECT code patterns
- **Templates**: See `templates/` for structured comment and summary formats
- **Project .editorconfig**: See root `.editorconfig` for complete style rules
- **C# Coding Conventions**: [Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions)
- **.NET Best Practices**: [Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/)