fix-eslint

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Fix ESLint Errors

修复ESLint错误

Automatically fix ESLint errors by modifying code to comply with configured linting rules.
Priorities:
  1. Never bypass rules - No eslint-disable comments, no rule modifications
  2. Fix code to comply - Modify implementation to meet linting standards
  3. Preserve functionality - Ensure fixes don't break existing behavior
  4. Follow coding standards - Apply fixes aligned with project style (FP-first, explicit naming)
通过修改代码以符合配置的代码检查规则,自动修复ESLint错误。
优先原则:
  1. 绝不绕过规则 - 不添加eslint-disable注释,不修改规则
  2. 修改代码以符合要求 - 调整代码实现以满足代码检查标准
  3. 保留原有功能 - 确保修复不会破坏现有功能
  4. 遵循编码规范 - 按照项目风格(函数式优先、命名清晰)进行修复

Workflow

工作流程

Step 1: Analyze ESLint Errors

步骤1:分析ESLint错误

Run the analysis script to understand error distribution:
bash
bash ./.claude/skills/fix-eslint/scripts/analyze_errors.sh
Or with file pattern:
bash
bash ./.claude/skills/fix-eslint/scripts/analyze_errors.sh "src/**/*.ts"
This outputs:
  • Total error count
  • Files grouped by directory
  • Directory-level breakdown
运行分析脚本以了解错误分布情况:
bash
bash ./.claude/skills/fix-eslint/scripts/analyze_errors.sh
也可指定文件匹配规则:
bash
bash ./.claude/skills/fix-eslint/scripts/analyze_errors.sh "src/**/*.ts"
该脚本会输出:
  • 错误总数
  • 按目录分组的文件
  • 目录级别的错误细分

Step 2: Choose Strategy

步骤2:选择修复策略

If ≤20 errors: Proceed to Step 3 (Direct Fix) If >20 errors: Proceed to Step 4 (Parallel Fix)

如果错误数≤20个:执行步骤3(直接修复) 如果错误数>20个:执行步骤4(并行修复)

Step 3: Direct Fix (≤20 errors)

步骤3:直接修复(错误数≤20个)

For small error counts, fix directly without spawning agents.
对于错误数量较少的情况,无需生成Agent,直接进行修复。

Process

处理流程

  1. Run ESLint to get errors:
    bash
    pnpm lint [file-or-directory]
  2. For each file with errors:
    • Read the file
    • Identify each ESLint error (rule name, line number, message)
    • Fix by modifying code to comply with the rule
    • NEVER add
      eslint-disable
      comments or modify ESLint config
    • See
      ./guidelines.md
      for detailed fixing guidelines
  3. Verify each fix:
    bash
    pnpm lint <file-path>
  4. Repeat until all errors fixed
  1. 运行ESLint获取错误信息:
    bash
    pnpm lint [file-or-directory]
  2. 针对每个存在错误的文件:
    • 读取文件内容
    • 定位每个ESLint错误(规则名称、行号、错误信息)
    • 通过修改代码以符合规则要求来修复错误
    • 绝不添加
      eslint-disable
      注释或修改ESLint配置
    • 详细修复指南请参考
      ./guidelines.md
  3. 验证每一处修复:
    bash
    pnpm lint <file-path>
  4. 重复上述步骤,直到所有错误都被修复

Report

修复报告

At the end, provide:
  • List of files processed
  • Total errors fixed
  • Brief summary (e.g., "8 unused imports removed, 3 return types added, 2 const conversions")
  • Any remaining errors (if unable to fix automatically)

修复完成后,需提供以下内容:
  • 已处理的文件列表
  • 已修复的错误总数
  • 简要总结(例如:"移除8个未使用的导入,添加3个返回类型,2处转换为const声明")
  • 剩余未修复的错误(如果无法自动修复)

Step 4: Parallel Fix (>20 errors)

步骤4:并行修复(错误数>20个)

For large error counts, orchestrate parallel fix-eslint agents by directory.
⚠️ CRITICAL: Follow steps IN ORDER. DO NOT skip ahead.
对于错误数量较多的情况,按目录编排并行的ESLint修复Agent。
⚠️ 重要提示:请严格按照步骤顺序操作,切勿跳过任何步骤。

4.1: Group Files by Directory and Create Todos (BLOCKING)

4.1:按目录分组文件并创建待办事项(阻塞步骤)

⚠️ MUST complete before Step 4.2
Use the output from Step 1 (the analyze_errors.sh script) to create directory-to-files mapping:
  • src/auth/
    → [login.ts, register.ts, session.ts]
  • src/api/
    → [users.ts, posts.ts]
  • src/components/
    → [Button.tsx, Header.tsx, Footer.tsx]
Grouping rules:
  • Group files by immediate parent directory
  • If directory has 10+ files, consider splitting into sub-directories or smaller batches
  • If all errors in 1 file, skip parallelization and use Step 3 instead
Use TodoWrite to create one todo per directory:
javascript
TodoWrite: [
  {content: "Fix ESLint errors in src/auth/", activeForm: "Fixing ESLint errors in src/auth/", status: "pending"},
  {content: "Fix ESLint errors in src/api/", activeForm: "Fixing ESLint errors in src/api/", status: "pending"},
  {content: "Fix ESLint errors in src/components/", activeForm: "Fixing ESLint errors in src/components/", status: "pending"}
]
CHECKPOINT: Verify all todos created before Step 4.2
⚠️ 必须在完成步骤4.2之前完成此步骤
使用步骤1的输出结果(analyze_errors.sh脚本的输出)来创建目录-文件映射:
  • src/auth/
    → [login.ts, register.ts, session.ts]
  • src/api/
    → [users.ts, posts.ts]
  • src/components/
    → [Button.tsx, Header.tsx, Footer.tsx]
分组规则:
  • 按直接父目录对文件进行分组
  • 如果目录包含10个以上文件,考虑按子目录拆分或分成更小的批次
  • 如果所有错误都集中在一个文件中,跳过并行处理,直接使用步骤3进行修复
使用TodoWrite为每个目录创建一个待办事项:
javascript
TodoWrite: [
  {content: "修复src/auth/目录下的ESLint错误", activeForm: "正在修复src/auth/目录下的ESLint错误", status: "pending"},
  {content: "修复src/api/目录下的ESLint错误", activeForm: "正在修复src/api/目录下的ESLint错误", status: "pending"},
  {content: "修复src/components/目录下的ESLint错误", activeForm: "正在修复src/components/目录下的ESLint错误", status: "pending"}
]
检查点:在进行步骤4.2之前,确认所有待办事项已创建完成

4.2: Spawn Parallel Agents (ONLY AFTER Step 4.1 Complete)

4.2:生成并行Agent(仅在步骤4.1完成后执行)

⚠️ DO NOT START until Step 4.1 fully complete
Update all todos to in_progress:
javascript
TodoWrite: [
  {content: "Fix ESLint errors in src/auth/", activeForm: "Fixing ESLint errors in src/auth/", status: "in_progress"},
  {content: "Fix ESLint errors in src/api/", activeForm: "Fixing ESLint errors in src/api/", status: "in_progress"},
  {content: "Fix ESLint errors in src/components/", activeForm: "Fixing ESLint errors in src/components/", status: "in_progress"}
]
IMPORTANT: Spawn ALL agents in SINGLE message using multiple Task tool calls.
Example Task invocations:
markdown
Task 1 (src/auth/):
prompt: "Fix all ESLint errors in the src/auth/ directory.

Files with errors:
- src/auth/login.ts
- src/auth/register.ts
- src/auth/session.ts

See ./.claude/skills/fix-eslint/guidelines.md for detailed guidelines.

Process:
1. For each file, run: pnpm lint <file-path>
2. Read the file with errors
3. Fix each error by modifying code to comply with rule
4. NEVER add eslint-disable comments or modify eslint config
5. Verify: run pnpm lint <file-path> again to confirm fix

Report back:
- List of files processed
- Total errors fixed
- Brief summary (e.g., '8 unused imports removed, 3 return types added')
- Any remaining errors (if unable to fix)"

subagent_type: "general-purpose"
description: "Fix auth directory ESLint errors"
markdown
Task 2 (src/api/):
prompt: "Fix all ESLint errors in the src/api/ directory.

Files with errors:
- src/api/users.ts
- src/api/posts.ts

See ./.claude/skills/fix-eslint/guidelines.md for detailed guidelines.

Process:
1. For each file, run: pnpm lint <file-path>
2. Read the file with errors
3. Fix each error by modifying code to comply with rule
4. NEVER add eslint-disable comments or modify eslint config
5. Verify: run pnpm lint <file-path> again to confirm fix

Report back:
- List of files processed
- Total errors fixed
- Brief summary of main fixes
- Any remaining errors"

subagent_type: "general-purpose"
description: "Fix API directory ESLint errors"
Continue pattern for all directory batches...
Claude Code manages parallelism (up to 10 tasks concurrently).
⚠️ 请在步骤4.1完全完成后再开始此步骤
将所有待办事项的状态更新为in_progress:
javascript
TodoWrite: [
  {content: "修复src/auth/目录下的ESLint错误", activeForm: "正在修复src/auth/目录下的ESLint错误", status: "in_progress"},
  {content: "修复src/api/目录下的ESLint错误", activeForm: "正在修复src/api/目录下的ESLint错误", status: "in_progress"},
  {content: "修复src/components/目录下的ESLint错误", activeForm: "正在修复src/components/目录下的ESLint错误", status: "in_progress"}
]
重要提示: 在单条消息中通过多次调用Task工具来生成所有Agent。
任务调用示例:
markdown
Task 1 (src/auth/):
prompt: "修复src/auth/目录下的所有ESLint错误。

存在错误的文件:
- src/auth/login.ts
- src/auth/register.ts
- src/auth/session.ts

详细指南请参考./.claude/skills/fix-eslint/guidelines.md。

处理流程:
1. 对每个文件,运行:pnpm lint <file-path>
2. 读取存在错误的文件
3. 通过修改代码以符合规则要求来修复每个错误
4. 绝不添加eslint-disable注释或修改eslint配置
5. 验证:再次运行pnpm lint <file-path>以确认错误已修复

返回报告内容:
- 已处理的文件列表
- 已修复的错误总数
- 简要总结(例如:'移除8个未使用的导入,添加3个返回类型')
- 剩余未修复的错误(如果有)"

subagent_type: "general-purpose"
description: "修复auth目录ESLint错误"
markdown
Task 2 (src/api/):
prompt: "修复src/api/目录下的所有ESLint错误。

存在错误的文件:
- src/api/users.ts
- src/api/posts.ts

详细指南请参考./.claude/skills/fix-eslint/guidelines.md。

处理流程:
1. 对每个文件,运行:pnpm lint <file-path>
2. 读取存在错误的文件
3. 通过修改代码以符合规则要求来修复每个错误
4. 绝不添加eslint-disable注释或修改eslint配置
5. 验证:再次运行pnpm lint <file-path>以确认错误已修复

返回报告内容:
- 已处理的文件列表
- 已修复的错误总数
- 修复内容简要总结
- 剩余未修复的错误"

subagent_type: "general-purpose"
description: "修复API目录ESLint错误"
按上述模式为所有目录批次创建任务...
Claude Code会管理并行任务(最多同时运行10个任务)。

4.3: Track Agent Completion and Update Todos

4.3:跟踪Agent完成状态并更新待办事项

As each agent completes:
  1. Parse agent's report (files processed, errors fixed)
  2. Update corresponding todo to completed:
javascript
TodoWrite: [
  {content: "Fix ESLint errors in src/auth/", activeForm: "Fixing ESLint errors in src/auth/", status: "completed"},
  {content: "Fix ESLint errors in src/api/", activeForm: "Fixing ESLint errors in src/api/", status: "in_progress"},
  {content: "Fix ESLint errors in src/components/", activeForm: "Fixing ESLint errors in src/components/", status: "in_progress"}
]
  1. Repeat for each agent as they complete
当每个Agent完成任务后:
  1. 解析Agent的报告(已处理的文件、已修复的错误)
  2. 将对应的待办事项状态更新为completed:
javascript
TodoWrite: [
  {content: "修复src/auth/目录下的ESLint错误", activeForm: "正在修复src/auth/目录下的ESLint错误", status: "completed"},
  {content: "修复src/api/目录下的ESLint错误", activeForm: "正在修复src/api/目录下的ESLint错误", status: "in_progress"},
  {content: "修复src/components/目录下的ESLint错误", activeForm: "正在修复src/components/目录下的ESLint错误", status: "in_progress"}
]
  1. 对每个完成任务的Agent重复上述步骤

4.4: Final Verification and Summary

4.4:最终验证与总结

After ALL agents complete:
  1. Run final verification:
    bash
    pnpm lint 2>&1
  2. Aggregate results from all agent reports:
    Summary:
    - Total directories processed: X
    - Total files modified: Y
    - Total errors fixed: Z
    - Breakdown by directory:
      • src/auth/: 12 errors fixed in 3 files
      • src/api/: 8 errors fixed in 2 files
      • src/components/: 15 errors fixed in 3 files
    - Remaining errors: N (if any)
  3. If remaining errors exist, report which files/directories still have issues

当所有Agent都完成任务后:
  1. 运行最终验证:
    bash
    pnpm lint 2>&1
  2. 汇总所有Agent的报告结果:
    总结:
    - 已处理的目录总数:X
    - 已修改的文件总数:Y
    - 已修复的错误总数:Z
    - 按目录细分:
      • src/auth/: 在3个文件中修复了12个错误
      • src/api/: 在2个文件中修复了8个错误
      • src/components/: 在3个文件中修复了15个错误
    - 剩余未修复的错误:N(如果有)
  3. 如果存在剩余未修复的错误,报告仍有问题的文件/目录

Edge Cases

边缘情况处理

Only 1 file with errors:
  • Skip parallelization
  • Fix directly using Step 3
  • No TodoWrite needed
Errors spread across many directories (15+):
  • Group by top-level directory only (e.g.,
    src/
    ,
    tests/
    ,
    lib/
    )
  • Don't over-split - let Claude Code manage parallelism
Large directory (20+ files):
  • Split by subdirectory if they exist
  • Or batch into groups of ~5 files each with separate Task calls
Agent reports remaining errors:
  • Include in final summary
  • Note specific files/rules that couldn't be auto-fixed
  • Suggest manual review

仅单个文件存在错误:
  • 跳过并行处理
  • 直接使用步骤3进行修复
  • 无需使用TodoWrite
错误分布在多个目录中(15个以上):
  • 仅按顶层目录分组(例如:
    src/
    tests/
    lib/
  • 不要过度拆分,由Claude Code来管理并行任务
大型目录(20个以上文件):
  • 如果存在子目录,按子目录拆分
  • 或者分成每组约5个文件的批次,分别调用Task
Agent报告存在剩余错误:
  • 纳入最终总结
  • 记录无法自动修复的具体文件/规则
  • 建议进行人工检查

Conflict Prevention

冲突预防措施

  • Each directory/file assigned to EXACTLY ONE agent
  • Verify no overlap before spawning
  • All Task calls in ONE message for parallel execution
  • Never let two agents modify same file

  • 每个目录/文件仅分配给一个Agent
  • 在生成Agent之前确认没有任务重叠
  • 所有Task调用都放在单条消息中以实现并行执行
  • 绝不让两个Agent修改同一个文件

Guidelines Reference

指南参考

For detailed fixing guidelines, constraints, and patterns, see:
  • ./guidelines.md
    - Complete fixing rules and process
如需详细的修复指南、约束条件和模式,请参考:
  • ./guidelines.md
    - 完整的修复规则和流程