---
name: "js-error-fixer"
description: "自动检查和修复 JavaScript 文件的语法错误、类型错误等问题。支持单个文件或整个文件夹批量处理。何时使用：当用户需要检查 JS 文件错误、修复 JS 语法问题、或批量处理 JS 文件时。"
metadata:
  author: "AI Assistant"
  updated: "2026-03-01"
  version: "2.0.0"
title: js-error-fixer
canonical_url: https://skilld.dev/gh/steelan9199/wechat-publisher/js-error-fixer
last_updated: 2026-10-07T07:20:50.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install steelan9199/wechat-publisher/js-error-fixer`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/js-error-fixer`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/steelan9199/wechat-publisher/js-error-fixer) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/js-error-fixer`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/js-error-fixer --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/js-error-fixer --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# JavaScript 错误检查与修复器

## 触发映射

| 用户输入触发词                                  | AI 执行动作            |
| ----------------------------------------------- | ---------------------- |
| "检查 JS 错误" / "修复 JS 问题" / "JS 语法错误" | 按【检查修复模式】执行 |
| "检查文件夹" / "批量处理 JS" / "修复所有 JS"    | 按【批量处理模式】执行 |
| "检查这个文件" / "修复这个 JS"                  | 按【单文件模式】执行   |

---

## 执行模式

### 检查修复模式

**触发**：用户提到检查或修复 JS 错误

| 步骤 | 执行动作              | 具体命令/操作                                         |
| ---- | --------------------- | ----------------------------------------------------- |
| 1    | 检查 ESLint 配置      | 检查项目是否已安装 ESLint 和配置文件                  |
| 2    | 安装 ESLint（如需要） | 运行 `npm install --save-dev eslint globals` 安装依赖 |
| 3    | 配置 ESLint（如需要） | 创建 `eslint.config.js` 配置文件                      |
| 4    | 运行 ESLint 检查      | 执行 `npx eslint <路径>` 检查 JS 文件                 |
| 5    | 分析错误              | 分类统计错误：语法错误、类型错误、其他                |
| 6    | 创建待办              | 运行 `TodoWrite` 创建修复任务列表                     |
| 7    | 逐个修复              | 按优先级逐个修复文件，使用 `Read` 和 `SearchReplace`  |
| 8    | 验证修复              | 再次运行 ESLint 确认错误已修复                        |
| 9    | 输出报告              | 列出修复的文件和错误类型                              |

---

### 批量处理模式

**触发**：用户提到文件夹或批量处理

| 步骤 | 执行动作     | 具体命令/操作                        |
| ---- | ------------ | ------------------------------------ |
| 1    | 获取目录路径 | 询问用户或从上下文获取目标文件夹路径 |
| 2    | 查找 JS 文件 | 运行 `Glob` 搜索 `**/*.js` 文件      |
| 3    | 检查 ESLint  | 运行 ESLint 检查所有 JS 文件错误     |
| 4    | 创建待办     | 运行 `TodoWrite` 列出所有待修复文件  |
| 5    | 批量修复     | 循环处理每个有错误的文件             |
| 6    | 验证结果     | 再次运行 ESLint，输出修复报告        |

---

### 单文件模式

**触发**：用户指定某个 JS 文件

| 步骤 | 执行动作     | 具体命令/操作                       |
| ---- | ------------ | ----------------------------------- |
| 1    | 获取文件路径 | 从用户输入或上下文获取文件路径      |
| 2    | 读取文件     | 运行 `Read` 读取该文件内容          |
| 3    | 检查 ESLint  | 运行 ESLint 检查该文件的错误        |
| 4    | 分析问题     | 定位具体错误位置和类型              |
| 5    | 执行修复     | 使用 `SearchReplace` 或重写文件修复 |
| 6    | 验证修复     | 再次运行 ESLint，确认修复完成       |

---

## ESLint 配置指南

### 安装 ESLint

| 步骤 | 操作            | 命令                             |
| ---- | --------------- | -------------------------------- |
| 1    | 进入项目目录    | `cd <项目路径>`                  |
| 2    | 安装 ESLint     | `npm install --save-dev eslint`  |
| 3    | 安装 globals 包 | `npm install --save-dev globals` |

### 创建 ESLint 配置文件

创建 `eslint.config.js` 配置文件（flat config 格式）：

```javascript
import globals from "globals";

export default [
  {
    languageOptions: {
      ecmaVersion: "latest",
      sourceType: "module",
      globals: {
        ...globals.node,
        ...globals.es2022
      }
    },
    rules: {
      "no-undef": "error",
      "no-unused-vars": "warn",
      "semi": [
        "error",
        "always"
      ],
      "quotes": [
        "error",
        "double"
      ]
    }
  }
];
```

### 运行 ESLint 检查

| 检查范围            | 命令                    |
| ------------------- | ----------------------- |
| 检查单个文件        | `npx eslint <文件路径>` |
| 检查整个目录        | `npx eslint <目录路径>` |
| 检查当前目录所有 JS | `npx eslint .`          |

---

## 常见错误修复策略

| 错误类型       | 错误表现              | 修复方式                               |
| -------------- | --------------------- | -------------------------------------- |
| HTML 实体编码  | 特殊字符被编码        | 将编码字符替换为实际字符               |
| 缺少右括号 `)` | 诊断提示"应为')'"     | 找到对应左括号位置，在正确位置添加 `)` |
| 缺少分号 `;`   | 诊断提示"应为';'"     | 在语句末尾添加 `;`                     |
| 引号不匹配     | 字符串引号未闭合      | 检查字符串，补全闭合引号               |
| 花括号不匹配   | `{` 和 `}` 数量不匹配 | 找到缺失的 `{` 或 `}`                  |
| 变量未定义     | 使用了未声明的变量    | 检查变量作用域，添加声明或修正拼写     |

---

## 错误处理

| 错误场景       | 错误表现               | 处理方式                                 |
| -------------- | ---------------------- | ---------------------------------------- |
| 无 JS 文件     | Glob 搜索结果为空      | 提示用户未找到 JS 文件，询问是否调整路径 |
| 无 ESLint 错误 | ESLint 返回空          | 输出"未发现错误"，结束任务               |
| 文件无法读取   | Read 返回错误          | 跳过该文件，记录到报告，继续处理其他文件 |
| 修复后仍有错误 | 修复后 ESLint 仍有问题 | 标记为"需要人工检查"，继续处理其他文件   |
| 未安装 ESLint  | `npx eslint` 失败      | 先安装 ESLint 和 globals 包              |

---

## 核心法则检查表

| 法则            | 检查标准                                  | 通过？ |
| --------------- | ----------------------------------------- | ------ |
| ⭐⭐⭐ 人类中心 | 用户只需说自然语言，AI 自动执行检查和修复 | ✅     |
| ⭐⭐⭐ AI 优先  | 使用祈使句指令，表格展示决策逻辑          | ✅     |
| ⭐⭐⭐ 即调即用 | 有触发映射表，用户输入 → AI 动作一一对应  | ✅     |
| 渐进披露        | 核心内容简短                              | ✅     |
| 错误处理        | 包含常见错误场景和处理方式表格            | ✅     |
