Lint and Fix Loop: Trunk
Purpose
An autonomous loop for the agent to identify, fix, and verify linting and formatting violations using Trunk.
Loop Logic
- •Format: Run
pnpm format(which executestrunk fmt) to automatically fix trivial formatting issues. - •Identify: Run
pnpm lint(which executestrunk check) to list any remaining violations. - •Analyze: Examine the output from Trunk, focusing on the file path, line number, and error message. Refer to ../common-references/troubleshooting.md for environment or runtime issues.
- •Fix: Apply the minimum necessary change to the source code to resolve the reported linting violations.
- •Verify: Re-run the loop (starting from Format) until all issues are resolved.
- •If
pnpm lintpasses: Finish. - •If it fails: Analyze the new failure and repeat the loop.
- •If
Termination Criteria
- •No more errors reported by
pnpm lint. - •Reached max iteration limit (default: 5).
Examples
Scenario: Fixing violations in a modified file
- •Agent runs
pnpm formatto ensure consistent style. - •Agent runs
pnpm lintand finds a linting violation insrc/index.ts. - •Agent analyzes the error and applies a manual fix.
- •Agent runs
pnpm formatagain (part of the loop). - •Agent runs
pnpm lintand it now passes.
Resources
- •Trunk CLI Reference: Common commands for linting and formatting.
- •Trunk Documentation: Official documentation for the Trunk CLI.