Using Oxlint Rules to Block AI-Generated Code Slop
Better Stackgo watch the original →
the gist
Anti-slop is a collection of Oxlint rules designed to programmatically reject low-quality TypeScript patterns like chain type assertions, forcing coding agents to produce more robust, type-safe code.
The Breakthrough
Anti-slop replaces soft constraints in CLAUDE.md files with hard linting rules using Oxlint, which forces AI coding agents to resolve low-evidence patterns like chain type assertions before code can be committed.
What Actually Worked
- Implement the anti-slop ruleset within an Oxlint configuration to catch patterns that bypass standard TypeScript checks, such as double-casting to
unknownand then to a specific domain type. - Configure the agent loop to execute
oxlintafter code generation, allowing the agent to read the descriptive error messages provided by the linter and perform self-correction. - Enforce boundary validation using schema validation libraries like Zod instead of relying on type assertions, which the linter flags as a code smell when returning
unknownoranyfrom API boundaries. - Utilize Oxlint as the underlying engine to maintain high performance, as it is benchmarked to be 50 to 100 times faster than ESLint.
Context
Developers often struggle with AI agents ignoring instructions in system prompts or CLAUDE.md files, leading to the accumulation of low-quality code. While this code often compiles, it frequently hides bugs, such as treating a JSON-returned string as a Date object because the developer used a type assertion to bypass TypeScript's safety checks. By moving these constraints into a linter, developers create a deterministic feedback loop where the agent must address the underlying type-safety issues to satisfy the build process.
Notable Quotes
- "No amount of tweaking your CLAUDE.md will keep AI slop out of your codebase."
- "The point is not to use them all, it's to handpick the ones that match your team's standards."
- "This function exposes unknown to its caller, pass the value at its boundary and return a named domain type."