kjibba-code-reviewer
1
总安装量
1
周安装量
#48855
全站排名
安装命令
npx skills add https://smithery.ai
Agent 安装分布
claude-code
1
Skill 文档
Code Reviewer
Act as a senior developer performing thorough code review. Focus on correctness, security, performance, and maintainability.
ð¤ When to Activate
Automatically engage this skill when:
- User asks for code review
- Viewing recently changed files
- Before commits or deployments
- When identifying potential issues
Review Categories
ð´ Critical (Must Fix)
- Security vulnerabilities (hardcoded secrets, missing auth)
- Runtime errors (undefined access, type mismatches)
- Data loss risks (missing cascade handling, unsafe deletes)
ð¡ Warning (Should Fix)
- Missing error handling
anytypes without justification- Missing loading/error states
- Performance anti-patterns (N+1, missing memoization)
ð¢ Suggestion (Consider)
- Code style improvements
- Better naming
- Refactoring opportunities
- Documentation gaps
TypeScript Review
Check for:
// â any type
function process(data: any) { }
// â
Proper typing
function process(data: FormData) { }
// â Missing return type
function calculate(items) {
return items.reduce((sum, i) => sum + i.price, 0);
}
// â
Explicit return type
function calculate(items: Item[]): number {
return items.reduce((sum, i) => sum + i.price, 0);
}
// â Unused imports
import { useState, useEffect, useCallback } from "react";
// Only useState is used
// â
Clean imports
import { useState } from "react";
React Component Review
Client vs Server
// â useState in server component
export default function Page() {
const [data, setData] = useState([]); // Error!
}
// â
Add "use client" directive
"use client";
export default function Page() {
const [data, setData] = useState([]);
}
Hooks Rules
// â Conditional hooks
if (isLoggedIn) {
useEffect(() => { }, []);
}
// â
Always call hooks at top level
useEffect(() => {
if (isLoggedIn) { /* ... */ }
}, [isLoggedIn]);
UI Components
// â Inline styling
<button className="bg-primary-500 text-white px-4 py-2 rounded">
Save
</button>
// â
Use UI components
import { Button } from "@/components/ui";
<Button variant="primary">Save</Button>
API Route Review
Authentication
// â Missing auth check
export async function GET() {
const data = await prisma.form.findMany();
return NextResponse.json(data);
}
// â
Always verify session
export async function GET() {
const session = await getServerSession(authOptions);
if (!session?.user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const data = await prisma.form.findMany();
return NextResponse.json(data);
}
Error Handling
// â No try-catch
export async function POST(req: NextRequest) {
const body = await req.json();
const result = await prisma.form.create({ data: body });
return NextResponse.json(result);
}
// â
Proper error handling
export async function POST(req: NextRequest) {
try {
const body = await req.json();
const result = await prisma.form.create({ data: body });
return NextResponse.json(result);
} catch (error) {
console.error("Create form error:", error);
return NextResponse.json(
{ error: "Failed to create form" },
{ status: 500 }
);
}
}
Input Validation
// â No validation
const { email, name } = await req.json();
await prisma.user.create({ data: { email, name } });
// â
Validate input
import { z } from "zod";
const schema = z.object({
email: z.string().email(),
name: z.string().min(1).max(255),
});
const result = schema.safeParse(await req.json());
if (!result.success) {
return NextResponse.json({ error: result.error.issues }, { status: 400 });
}
await prisma.user.create({ data: result.data });
Security Review
Credentials
// â CRITICAL: Hardcoded secrets
const API_KEY = "sk_live_abc123";
// â
Environment variables
const API_KEY = process.env.API_KEY;
Password Exposure
// â Returning password hash
const user = await prisma.user.findUnique({ where: { id } });
return NextResponse.json(user); // Includes passwordHash!
// â
Select only needed fields
const user = await prisma.user.findUnique({
where: { id },
select: { id: true, name: true, email: true, role: true },
});
return NextResponse.json(user);
Public Endpoints
// â Exposing internal IDs
return NextResponse.json({ id: form.id, customerId: form.customerId });
// â
Use public tokens
return NextResponse.json({ token: form.token });
Performance Review
Memoization
// â Recalculates every render
const sortedItems = items.sort((a, b) => a.name.localeCompare(b.name));
// â
Memoize expensive operations
const sortedItems = useMemo(
() => items.sort((a, b) => a.name.localeCompare(b.name)),
[items]
);
Dependency Arrays
// â Missing dependencies
useEffect(() => {
fetchData(userId);
}, []); // userId not in deps
// â
Include all dependencies
useEffect(() => {
fetchData(userId);
}, [userId]);
N+1 Queries
// â N+1 query pattern
const forms = await prisma.form.findMany();
for (const form of forms) {
form.customer = await prisma.customer.findUnique({
where: { id: form.customerId }
});
}
// â
Use include
const forms = await prisma.form.findMany({
include: { customer: true }
});
Code Style Review
Import Order
- External packages (react, next)
- Internal absolute (@/…)
- Internal relative (./, ../)
- Types
Naming
- Components:
PascalCaseâJobEditModal.tsx - Functions:
camelCaseâformatDate() - Constants:
UPPER_SNAKE_CASEâMAX_FILE_SIZE - Booleans:
is/has/shouldprefix âisLoading
File Size
- Target: < 300 lines
- If larger: Split into smaller modules
Review Output Format
When performing a review, output in this format:
## Code Review: `filename.tsx`
### ð´ Critical Issues
1. **[Security]** Hardcoded API key on line 15
- Fix: Move to `.env` as `API_KEY`
### ð¡ Warnings
1. **[TypeScript]** `any` type on line 42
- Fix: Define interface for `FormData`
2. **[Performance]** Missing memoization for expensive sort
- Fix: Wrap in `useMemo`
### ð¢ Suggestions
1. **[Style]** Consider extracting validation to separate function
2. **[Naming]** `data` is too generic, consider `formSubmissions`
### â
Good Practices Observed
- Proper error handling in API routes
- Consistent use of UI components
Quick Checklist
Before approving code:
- No TypeScript errors
- No
anytypes (unless justified) - All API routes have auth checks
- Error handling with try-catch
- Input validation for user data
- No hardcoded secrets
- Proper loading/error states
- UI components used (no inline Tailwind for buttons/inputs)
- Dependencies in useEffect arrays
- No N+1 queries
- Descriptive variable names
- Files under 300 lines