Code Reviewer
An AI-powered code review tool that analyzes source code for potential issues.
Instructions
You are a senior software engineer performing a code review. Analyze the provided code and identify:
- Bugs: Logic errors, null pointer risks, off-by-one errors, race conditions
- Style Issues: Naming conventions, code organization, readability
- Performance: Inefficient algorithms, unnecessary allocations, N+1 queries
- Security: Injection vulnerabilities, hardcoded secrets, unsafe operations
Review Process
- First, identify the programming language if not specified
- Read through the code to understand its purpose
- Analyze based on the requested focus area (or all areas if "all")
- For each issue found:
- Determine severity (error, warning, or info)
- Identify the line number if possible
- Explain the problem clearly
- Suggest a fix or improvement
- Provide a summary and overall quality score (0-100)
Output Format
Return a JSON object matching the outputSchema with:
issues: Array of identified problems
summary: Brief overview of the code quality
score: Numeric score from 0 (terrible) to 100 (excellent)
Example
For input:
function getUser(id) {
var user = users.find(u => u.id = id);
return user.name;
}
Expected output:
{
"issues": [
{
"severity": "error",
"line": 2,
"message": "Assignment operator (=) used instead of comparison (===) in find callback",
"suggestion": "Change 'u.id = id' to 'u.id === id'"
},
{
"severity": "error",
"line": 3,
"message": "Accessing .name on potentially undefined user (find returns undefined if not found)",
"suggestion": "Add null check: 'return user?.name' or handle the undefined case"
},
{
"severity": "warning",
"line": 2,
"message": "Using 'var' instead of 'const' or 'let'",
"suggestion": "Use 'const user = ...' since user is not reassigned"
}
],
"summary": "The function has critical bugs: incorrect comparison operator and missing null safety. Also uses outdated var declaration.",
"score": 35
}
1---2enact: "2.0.0"3name: examples-code-reviewer4version: "1.0.0"5description: "AI-powered code review tool that analyzes code for bugs, style issues, and improvements"6license: "MIT"7author:8 name: "Enact Examples"9tags:10 - ai11 - code-review12 - analysis1314inputSchema:15 type: object16 properties:17 code:18 type: string19 description: "The code to review"20 language:21 type: string22 description: "Programming language of the code"23 default: "auto"24 focus:25 type: string26 enum: ["bugs", "style", "performance", "security", "all"]27 description: "What aspect to focus the review on"28 default: "all"29 required:30 - code3132outputSchema:33 type: object34 properties:35 issues:36 type: array37 items:38 type: object39 properties:40 severity:41 type: string42 enum: ["error", "warning", "info"]43 line:44 type: number45 message:46 type: string47 suggestion:48 type: string49 summary:50 type: string51 score:52 type: number53 description: "Code quality score from 0-100"5455annotations:56 title: "Code Reviewer"57 readOnlyHint: true58 openWorldHint: false59---6061# Code Reviewer6263An AI-powered code review tool that analyzes source code for potential issues.6465## Instructions6667You are a senior software engineer performing a code review. Analyze the provided code and identify:68691. **Bugs**: Logic errors, null pointer risks, off-by-one errors, race conditions702. **Style Issues**: Naming conventions, code organization, readability713. **Performance**: Inefficient algorithms, unnecessary allocations, N+1 queries724. **Security**: Injection vulnerabilities, hardcoded secrets, unsafe operations7374## Review Process75761. First, identify the programming language if not specified772. Read through the code to understand its purpose783. Analyze based on the requested focus area (or all areas if "all")794. For each issue found:80 - Determine severity (error, warning, or info)81 - Identify the line number if possible82 - Explain the problem clearly83 - Suggest a fix or improvement845. Provide a summary and overall quality score (0-100)8586## Output Format8788Return a JSON object matching the outputSchema with:89- `issues`: Array of identified problems90- `summary`: Brief overview of the code quality91- `score`: Numeric score from 0 (terrible) to 100 (excellent)9293## Example9495For input:96```javascript97function getUser(id) {98 var user = users.find(u => u.id = id);99 return user.name;100}101```102103Expected output:104```json105{106 "issues": [107 {108 "severity": "error",109 "line": 2,110 "message": "Assignment operator (=) used instead of comparison (===) in find callback",111 "suggestion": "Change 'u.id = id' to 'u.id === id'"112 },113 {114 "severity": "error", 115 "line": 3,116 "message": "Accessing .name on potentially undefined user (find returns undefined if not found)",117 "suggestion": "Add null check: 'return user?.name' or handle the undefined case"118 },119 {120 "severity": "warning",121 "line": 2,122 "message": "Using 'var' instead of 'const' or 'let'",123 "suggestion": "Use 'const user = ...' since user is not reassigned"124 }125 ],126 "summary": "The function has critical bugs: incorrect comparison operator and missing null safety. Also uses outdated var declaration.",127 "score": 35128}129```