ESLint Auto-Fix Tool
Analyze ESLint violations or fix a specific rule in isolation.
Usage
Report Mode (No Arguments)
/lint-fix
Shows top ESLint violations by count with recommendations.
Fix Mode (With Rule Name)
/lint-fix <rule-name>
Examples:
-
/lint-fix unicorn/no-zero-fractions
-
/lint-fix unicorn/prefer-number-properties
-
/lint-fix unicorn/no-array-for-each
Instructions for AI Agent
When Invoked WITHOUT Arguments (Report Mode)
Run ESLint and analyze violations:
nx run-many -t lint:eslint 2>&1 | tee /tmp/eslint-output.txt
Count violations by rule:
grep -oE 'unicorn/[a-z-]+|@typescript-eslint/[a-z-]+|no-[a-z-]+|sonarjs/[a-z-]+' /tmp/eslint-output.txt | sort | uniq -c | sort -rn | head -20
Generate a formatted report showing:
-
Top 10-15 violations ranked by type (error > warning) then by count
-
Which rules are auto-fixable (✅) vs manual (❌)
-
Recommended next rule to fix (highest count auto-fixable)
-
Brief description of what each rule fixes
-
Total warning/error count
Format output as a table:
ESLint Violations Report
| Rank | Rule | Count | Auto-Fix | Description |
|---|---|---|---|---|
| 1 | unicorn/prefer-number-properties | 170 | ✅ | Use Number.* APIs instead of globals |
| 2 | unicorn/no-array-for-each | 166 | ✅ | Prefer for...of over .forEach() |
| 3 | no-negated-condition | 37 | ❌ | Prefer positive conditions |
...
Provide actionable recommendation:
🎯 Recommended Next Fix
unicorn/prefer-number-properties - 170 violations
- Auto-fixable: ✅ Yes
- Changes:
isNaN()→Number.isNaN(),parseInt()→Number.parseInt() - Impact: Better global scope hygiene
- Risk: Low - semantically equivalent
To fix: /lint-fix unicorn/prefer-number-properties
When Invoked WITH Arguments (Fix Mode)
Input: Rule name (e.g., unicorn/no-zero-fractions )
CRITICAL: Isolated Fixing Strategy
Each rule MUST be fixed in complete isolation to prevent merge conflicts and allow precise review:
-
Start fresh - ensure clean working directory
-
Fix ONLY the specified rule - no opportunistic fixes
-
Single commit per rule - never batch multiple rules
-
Verify before committing - ensure fix doesn't break anything
Step-by-Step Fix Process
- Verify Clean Working Directory
git status
If there are uncommitted changes:
-
STOP and warn user
-
Suggest they stash or commit existing changes first
-
Only proceed if user explicitly confirms
- Attempt Auto-Fix
nx run-many -t lint:eslint -- --rule "<rule-name>: error" --fix 2>&1 | tee /tmp/lint-fix.txt
Check results:
Count remaining violations
grep -c "<rule-name>" /tmp/lint-fix.txt || echo "0"
- If Auto-Fix Successful
Format all changes
yarn nx format
Run full lint to ensure no new issues
yarn nx lint <affected-packages>
Run type-check
yarn nx build:types <affected-packages>
If all pass:
git add -A git commit -m "fix(lint): auto-fix <rule-name> violations"
- If Manual Fix Required
For non-auto-fixable rules or remaining violations after auto-fix:
List all remaining violations:
nx run-many -t lint:eslint -- --rule "<rule-name>: error" 2>&1 | grep "<rule-name>"
Group by file/pattern for efficient fixing
Fix each file systematically:
-
Open file
-
Apply fix pattern consistently
-
Move to next file
After each batch of fixes:
Verify the fix works
nx run-many -t lint:eslint -- --rule "<rule-name>: error"
When complete:
yarn nx format yarn nx lint <affected-packages> yarn nx build:types <affected-packages>
git add -A git commit -m "fix(lint): manually fix <rule-name> violations"
Common Auto-Fixable Rules Reference
Rule Auto-Fix Typical Change
unicorn/prefer-number-properties
✅ isNaN() → Number.isNaN()
unicorn/no-array-for-each
✅ .forEach() → for...of
unicorn/no-zero-fractions
✅ 1.0 → 1
unicorn/prefer-string-slice
✅ .substr() → .slice()
@typescript-eslint/no-unused-vars
❌ Remove or use variable
no-negated-condition
❌ Invert condition logic
sonarjs/cognitive-complexity
❌ Refactor complex function
Safety Checks
Before ANY commit:
-
✅ yarn nx format passes
-
✅ yarn nx lint <affected-packages> passes
-
✅ yarn nx build:types <affected-packages> passes
-
✅ Only files related to the rule are changed
-
✅ No unrelated "opportunistic" fixes included
If any check fails: STOP and report to user