Skip to main content
Use Droid Exec to fix ESLint violations across a codebase. The workflow identifies files with lint errors, applies targeted fixes, and preserves existing behavior.
This approach works with any ESLint rule - from simple formatting issues to complex architectural patterns.

How it works

The script:
  1. Finds violations: Runs ESLint to identify all route.ts files missing middleware
  2. Analyzes context: Determines the appropriate middleware type based on the route path
  3. Adds middleware: Inserts the correct handle*Middleware call as the first statement
  4. Preserves logic: Wraps existing code in the middleware callback
  5. Maintains types: Ensures TypeScript types are correctly preserved
  6. Formats code: Maintains consistent code style

Get the script

Critical for Success: When customizing this script for your own lint rules, always include concrete before/after examples in the prompt you give to Droid Exec. This dramatically improves accuracy.Good prompt structure:
  1. Describe the violation to fix
  2. Show a “before” code example with the violation
  3. Show an “after” code example with the fix applied
  4. List any edge cases or patterns to preserve
The more specific your examples, the better Droid will understand and implement the fix pattern.

Prerequisites

Before you begin, ensure you have completed the Droid Exec installation

Basic usage

Preview violations (dry run)

Always start with a dry run to see which files need fixing before making changes.
The dry run shows you which files violate the middleware rule and what type of middleware would be added:
How dry run works:
  • When DRY_RUN=true: Identifies violations and shows what middleware type would be added
  • When DRY_RUN=false (default): Actually fixes the violations by adding middleware
This helps you:
  • Understand which routes are missing middleware
  • Verify the correct middleware type will be used
  • Estimate the scope of changes

Apply fixes

Once ready, run the actual fix:

Real-world transformations

Example 1: Simple GET Handler

Missing middleware - no authentication check!

Example 2: Cron Job Handler

Cron job without authorization - anyone could trigger it!

Best practices

Follow these best practices for safe and effective middleware addition.
1

Start with dry run

Preview changes before applying:
2

Process by app

Fix one application at a time for easier review: