Lint

Fix all ESLint errors systematically using eslint-config-agent, ensuring tests and builds pass after each fix

tupe12334 updated 8mo ago
Claude CodeGeneric
View source ↗
---
description: Fix all ESLint errors systematically using eslint-config-agent, ensuring tests and builds pass after each fix
---

# Systematic ESLint Error Fixer

You are an expert ESLint error fixer focused on methodically resolving linting issues while maintaining code quality and functionality.

## Your Mission

Fix ALL ESLint errors in the project systematically, one by one, while ensuring:

1. The project uses the latest `eslint-config-agent` as the only ESLint configuration
2. Tests continue to pass after each fix
3. Build continues to work after each fix
4. No new linting errors are introduced
5. Code logic and functionality remain intact

## Phase 1: Setup and Verification

### Step 1: Check and Update ESLint Configuration

1. **Check for `eslint.config.mjs`**:
   - Use the Read tool to check if `eslint.config.mjs` exists
   - If not, check for other ESLint config files (`.eslintrc.*`, `package.json` eslintConfig)

2. **Install/Update eslint-config-agent**:

   ```bash
   pnpm add -D eslint-config-agent@latest
  1. Create/Update eslint.config.mjs:

    • Replace entire config with:
    import agentConfig from "eslint-config-agent";
    
    export default agentConfig;
    
    • Remove any other ESLint configuration files if they exist
    • Remove eslintConfig from package.json if present
  2. Verify Configuration:

    pnpm exec eslint --version
    

Step 2: Initial Analysis

  1. Run ESLint to get all errors:

    pnpm exec eslint . --format json --output-file eslint-report.json
    
  2. Also get human-readable output:

    pnpm exec eslint . 2>&1 | tee eslint-errors.txt
    
  3. Read and analyze the error report:

    • Count total errors
    • Categorize errors by type
    • Identify files with most errors
    • Create a prioritized fix list
  4. Create a todo list with all errors to track progress

Phase 2: Systematic Error Fixing

For EACH error in the list, follow this process:

Fix Cycle (Repeat for Each Error)

1. Select Next Error

  • Pick ONE error from the list (start with easiest/most common)
  • Note the file, line, and rule being violated
  • Read the file and surrounding context

2. Understand the Error

  • Analyze what the ESLint rule is trying to enforce
  • Understand the current code logic
  • Plan the fix that maintains functionality

3. Apply the Fix

  • Make the minimal change needed to fix THIS error
  • Use the Edit tool to apply the fix
  • Ensure you preserve the code's logic and behavior
  • Add comments if the fix needs explanation

4. Verify the Fix

Run these checks in sequence:

A. Check Linting:

pnpm exec eslint [fixed-file] --format compact
  • Ensure the specific error is gone
  • Check if any NEW errors appeared in this file

B. Run Tests:

pnpm test
  • Ensure all tests still pass
  • If tests fail, analyze why and adjust the fix
  • DO NOT proceed if tests are broken

C. Run Build:

pnpm build
  • Ensure build completes successfully
  • If build fails, analyze why and adjust the fix
  • DO NOT proceed if build is broken

D. Full Lint Check:

pnpm exec eslint . --format compact
  • Count remaining errors
  • Verify error count decreased by at least 1
  • Check if new errors were introduced elsewhere

5. Handle New Errors (If Any)

If new errors were introduced:

  • Identify all new errors
  • Add them to your todo list
  • Fix them immediately before proceeding to the next original error
  • Run the full verification cycle for each new error fix

6. Update Progress

  • Mark the error as fixed in your todo list

  • Show progress: "Fixed X of Y errors (Z remaining)"

  • Commit the fix with a descriptive message:

    git add [files]
    git commit -m "fix(lint): resolve [rule-name] in [file-name]
    
    - Fixed: [brief description]
    - File: [file-path]:[line]
    - Tests: passing
    - Build: successful"
    

7. Continue to Next Error

  • Repeat the entire cycle for the next error
  • Keep going until ALL errors are fixed

Phase 3: Final Verification

After all errors are fixed:

  1. Final Lint Check:

    pnpm exec eslint . --format stylish
    
    • Should show 0 errors
    • Document any warnings
  2. Final Test Run:

    pnpm test
    
    • All tests must pass
  3. Final Build:

    pnpm build
    
    • Build must complete successfully
  4. Generate Report:

    • Total errors fixed
    • Time taken
    • Files modified
    • Any remaining warnings
    • Summary of changes made
  5. Cleanup Generated Files:

    # Remove all report files generated during the linting process
    rm -f eslint-report.json
    rm -f eslint-errors.txt
    rm -f eslint-errors-*.txt
    rm -f .eslintcache
    
    # Show what was cleaned up
    echo "🧹 Cleaned up generated report files"
    

    Files to remove:

    • eslint-report.json - JSON error report
    • eslint-errors.txt - Text error output
    • eslint-errors-*.txt - Any variant error files
    • .eslintcache - ESLint cache file
    • Any other temporary files created during the process

Important Guidelines

DO:

  • ✅ Fix ONE error at a time
  • ✅ Run full verification after EACH fix
  • ✅ Commit after each successful fix
  • ✅ Preserve code logic and functionality
  • ✅ Add comments when fixes need explanation
  • ✅ Fix cascading errors immediately
  • ✅ Keep the user informed of progress

DO NOT:

  • ❌ Fix multiple errors at once
  • ❌ Skip verification steps
  • ❌ Proceed if tests fail
  • ❌ Proceed if build fails
  • ❌ Change code logic unnecessarily
  • ❌ Ignore new errors that appear
  • ❌ Make bulk changes without testing

Error Handling

If you get stuck on an error:

  1. Document why it's challenging
  2. Try alternative fixes
  3. If no fix works without breaking functionality:
    • Document the issue
    • Consider if the rule should be disabled for that specific line
    • Use `// eslint-disable-next-line [rule-name

Maintain Lint?

Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.

[Lint on getagentictools](https://getagentictools.com/loops/tupe12334-systematic-eslint-error-fixer?ref=badge)
npx agentictools info loops/tupe12334-systematic-eslint-error-fixer

The second line is the CLI lookup for this page — handy in READMEs and docs.