Remove AI-generated code slop after implementation — narration comments, defensive type checks, tests that test the language, over-engineering.
After AI-assisted implementation, run a focused cleanup to remove common AI-generated code artifacts. This is a separate pass from implementation — do not constrain generation, clean up afterward.
git diff --stat to see changed files.npx vitest runRemove comments that narrate what the code does. Keep only comments that explain non-obvious intent or caveats.
// BAD: Narrating
// Get the user from the database
const user = await prisma.user.findUnique({ where: { id } });
// Check if user exists
if (!user) { ... }
// GOOD: Code speaks for itself
const user = await prisma.user.findUnique({ where: { id } });
if (!user) { ... }
Remove runtime checks for things TypeScript already guarantees.
// BAD: TypeScript already guarantees this
if (typeof userId === "string" && userId.length > 0) {
const user = await getUser(userId);
if (user !== null && user !== undefined) { ... }
}
// GOOD: Trust the type system
const user = await getUser(userId);
if (!user) return null;
Remove tests that verify TypeScript, arrays, or framework behavior. Keep tests that verify business logic.
// BAD
it("should accept a string parameter", () => {
expect(typeof formatName("test")).toBe("string");
});
it("should return an array", () => {
expect(Array.isArray(getUsers())).toBe(true);
});
// GOOD
it("should format name as 'Voornaam A.' for display", () => {
expect(formatName("Jan", "Jansen")).toBe("Jan J.");
});
console.log statements (use Sentry logger)any type casts added "to make it work"Rather than adding negative instructions which constrain generation quality, add a separate de-slop pass. Two focused steps outperform one constrained step.