Ai code reviewer

From nlelouche/Unity-SkillForge · View interactive version

Ai code reviewer is an AI agent skill from the GitHub repository nlelouche/Unity-SkillForge. Agentic code review checklist for Unity C# scripts. Identifies SOLID violations, GC allocation anti-patterns, naked Singletons, missing null guards, and architectural smells before human review.

How to use this skill

Skill file

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

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

  1. Read the file: Use read_resource or view_file to load the script.
  2. Run each CRITICAL check using mcp_unityMCP_find_in_file with the detection regex.
  3. Run WARNING checks similarly.
  4. Compile Report: Format findings as the Report Format below.
  5. 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:

  1. Reads PlayerController.cs.
  2. Runs find_in_file for Update.*GetComponent β†’ finds line 47.
  3. Runs find_in_file for ^public (int|float) β†’ finds 3 violations.
  4. 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


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:

  1. Descomenta los tests above
  2. Implementa la funcionalidad mΓ­nima para que compile
  3. Ejecuta los tests β€” deben fallar (RED)
  4. Implementa la funcionalidad real
  5. Verifica que los tests pasen (GREEN)
  6. 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

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.