AI Code Reviewer
Overview
An agentic code review pass that reads a C# script and checks it against a structured checklist of Unity-specific and general engineering quality criteria. It produces a structured report of CRITICAL, WARNING, and INFO findings, mimicking a senior engineer's code review β before the code reaches human review.
When to Use
- Use before committing a new feature to version control.
- Use after a code generation batch to verify generated code quality.
- Use during onboarding to enforce standards for new team members.
- β Do NOT use as a replacement for human code review β use it to reduce the noise.
Review Checklist
π΄ CRITICAL β Must Fix Before Merge
| ID | Check | Detection Pattern |
|----|-------|-------------------|
| C1 | GetComponent called in Update() | Update.*GetComponent regex |
| C2 | new List/Array allocation in Update() | Update.*new (List\|Array\|\[\]) |
| C3 | Find() or FindObjectOfType() in Update() | Update.*Find |
| C4 | public field not [SerializeField] private | ^public (int\|float\|string\|bool) |
| C5 | Naked Singleton (static instance, no DI) | static.*Instance.*=.*this |
| C6 | Empty Unity messages (void Update() { }) | void (Update\|FixedUpdate)\(\) *\{ *\} |
| C7 | Hardcoded magic string/number | "[a-z]+[A-Z]" in logic (non-const) |
π‘ WARNING β Should Fix
| ID | Check | Detection Pattern |
|----|-------|-------------------|
| W1 | LINQ in hot path | \.Where\(\|\.Select\(\|\.FirstOrDefault in Update |
| W2 | Missing null check after GetComponent | GetComponent not followed by if.*null |
| W3 | string += in a loop | string.*\+=.* inside loop |
| W4 | Class has >300 lines (SRP violation) | Line count |
| W5 | Method has >30 lines (Single Responsibility) | Method line count |
| W6 | No namespace declaration | File start ^using without namespace |
| W7 | TODO comment left in code | //.*TODO |
π΅ INFO β Consider Improving
| ID | Check |
|----|-------|
| I1 | Missing XML doc comment on public methods |
| I2 | Magic numbers not extracted to constants |
| I3 | MonoBehaviour without [RequireComponent] for dependencies |
Review Procedure
- Read the file: Use
read_resourceorview_fileto load the script. - Run each CRITICAL check using
mcp_unityMCP_find_in_filewith the detection regex. - Run WARNING checks similarly.
- Compile Report: Format findings as the Report Format below.
- Provide Fix Suggestions: For each CRITICAL, provide the corrected code snippet.
Report Format
π CODE REVIEW β PlayerController.cs
ββββββββββββββββββββββββββββββββββββ
π΄ CRITICAL (2)
[C1] Line 47: GetComponent<Rigidbody>() called inside Update()
β Cache in Awake(): private Rigidbody _rb; β _rb = GetComponent<Rigidbody>();
[C4] Line 12: public float Speed = 5f;
β Change to: [SerializeField] private float _speed = 5f;
π‘ WARNING (1)
[W6] No namespace found.
β Add: namespace Game.Player { ... }
π΅ INFO (1)
[I1] Public method Move() has no XML doc comment.
ββββββββββββββββββββββββββββββββββββ
Score: 6/10 β Needs fixes before merge
Few-Shot Examples
Example 1: Full Review Pass
User: "Review my PlayerController.cs before I commit it."
Agent:
- Reads
PlayerController.cs. - Runs
find_in_fileforUpdate.*GetComponentβ finds line 47. - Runs
find_in_filefor^public (int|float)β finds 3 violations. - Outputs structured report with fix snippets for each CRITICAL.
Example 2: Focused Check
User: "Check if there are any GC allocations in my Update methods."
Agent: Scans only for C1, C2, W1, W3 patterns and reports findings.
Best Practices
- β
Run this before
@automated-unit-testingβ type errors from bad patterns can cascade. - β Always provide the corrected code snippet alongside each CRITICAL finding.
- β Score the file: 0 CRITICALs = merge-ready; any = block.
- β NEVER auto-apply fixes without confirming with the user.
TDD Contract
β οΈ Legacy Skill β Refactor Pending
Este skill NO tiene tests automatizados aΓΊn. El siguiente boilerplate es un punto de partida.
// Escribe estos tests ANTES de implementar:
// Test 1: should [expected behavior] when [condition]
[Test]
public void AiCodeReviewer_Should{ExpectedBehavior}_When{Condition}()
{{
// Arrange
// TODO: Setup test fixtures
// Act
// TODO: Execute system under test
// Assert
Assert.Fail("Not implemented β write test first");
}}
// Test 2: should handle [edge case]
[Test]
public void AiCodeReviewer_ShouldHandle{EdgeCase}()
{{
// Arrange
// TODO: Setup edge case scenario
// Act
// TODO: Execute
// Assert
Assert.Fail("Not implemented");
}}
// Test 3: should throw when [invalid input]
[Test]
public void AiCodeReviewer_ShouldThrow_When{InvalidInput}()
{{
// Arrange
var invalidInput = default;
// Act & Assert
Assert.Throws<Exception>(() => {{ /* execute */ }});
}}
Pasos para completar el TDD:
- Descomenta los tests above
- Implementa la funcionalidad mΓnima para que compile
- Ejecuta los tests β deben fallar (RED)
- Implementa la funcionalidad real
- Verifica que los tests pasen (GREEN)
- Refactorea manteniendo los tests verdes
Nota: Este skill fue marcado como tdd_first: false durante la auditorΓa v2.0.1. La secciΓ³n TDD fue agregada automΓ‘ticamente pero requiere customizaciΓ³n manual para reflejar el comportamiento real del skill.
Related Skills
@unified-style-guideβ The standard this checker enforces@automated-unit-testingβ Next step after a clean review@unity-compile-fixerβ For compilation errors, not style smells@coreclr-gc-watchdogβ For deep GC analysis beyond this checklist