SuperAPI AI Directory

js-error-fixer

Coding & development

View repository

Updated 10-16 08:10

About this skill

JavaScript Error Checker and Fixer

Trigger Mapping

User input trigger words AI execution actions
"Check JS errors" / "Fix JS issues" / "JS syntax errors" Execute according to [Check and Fix Mode]
"Check folder" / "Batch process JS" / "Fix all JS" Execute according to [Batch Processing Mode]
"Check this file" / "Fix this JS" Execute according to [Single File Mode]

Execution Modes

Check and Fix Mode

Trigger: the user mentions checking or fixing JS errors

Step Execution action Specific command/operation
1 Check ESLint configuration Check whether the project has ESLint and a configuration file installed
2 Install ESLint (if needed) Run npm install --save-dev eslint globals to install dependencies
3 Configure ESLint (if needed) Create eslint.config.js configuration file
4 Run ESLint check Execute npx eslint <路径> to check JS files
5 Analyze errors Classify and count errors: syntax errors, type errors, others
6 Create to-dos Run TodoWrite to create a fix task list
7 Fix one by one Fix files one by one by priority, using Read and SearchReplace
8 Verify fixes Run ESLint again to confirm the errors have been fixed
9 Output report List the fixed files and error types

Batch Processing Mode

Trigger: the user mentions a folder or batch processing

Step Execution action Specific command/operation
1 Get directory path Ask the user or get the target folder path from context
2 Find JS files Run Glob to search for **/*.js files
3 Check ESLint Run ESLint to check all JS file errors
4 Create to-dos Run TodoWrite to list all files to be fixed
5 Batch fix Loop through each file with errors
6 Verify results Run ESLint again and output a fix report

Single File Mode

Trigger: the user specifies a certain JS file

Step Execution action Specific command/operation
1 Get file path Get the file path from user input or context
2 Read file Run Read to read the file contents
3 Check ESLint Run ESLint to check the file for errors
4 Analyze the problem Locate the specific error position and type
5 Perform the fix Use SearchReplace or rewrite the file to fix
6 Verify the fix Run ESLint again to confirm the fix is complete

ESLint Configuration Guide

Install ESLint

Step Action Command
1 Enter the project directory cd <项目路径>
2 Install ESLint npm install --save-dev eslint
3 Install the globals package npm install --save-dev globals

Create the ESLint configuration file

Create the eslint.config.js configuration file (flat config format):

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"
      ]
    }
  }
];

Run ESLint check

Check scope Command
Check a single file npx eslint <文件路径>
Check the entire directory npx eslint <目录路径>
Check all JS in the current directory npx eslint .

Common error fix strategies

Error type Error symptom Fix method
HTML entity encoding Special characters are encoded Replace the encoded characters with the actual characters
Missing closing parenthesis ) Diagnostic message "expected ')'" Find the corresponding opening parenthesis position and add it at the correct position )
Missing semicolon ; Diagnostic message "expected ';'" Add it at the end of the statement ;
Quote mismatch String quotes are not closed Check the string and complete the closing quote
Brace mismatch { The counts of and do not match } The counts do not match Find the missing { or }
Undefined variable An undeclared variable is used Check the variable scope, add a declaration, or correct the spelling

Error handling

Error scenario Error symptom Handling method
No JS files Glob search result is empty Prompt the user that no JS files were found and ask whether to adjust the path
No ESLint errors ESLint returns empty Output "No errors found" and end the task
File cannot be read Read returns an error Skip the file, record it in the report, and continue processing other files
Errors remain after fixing ESLint still reports problems after fixing Mark as "needs manual inspection" and continue processing other files
ESLint is not installed npx eslint failed Install ESLint and the globals package first

Core principles checklist

Principle Check standard Pass?
⭐⭐⭐ Human-centered Users only need to speak natural language, and the AI automatically performs checks and fixes ✅
⭐⭐⭐ AI-first Use imperative instructions, and display decision logic in tables ✅
⭐⭐⭐ Ready to use out of the box There is a trigger mapping table, mapping user input → AI actions one-to-one ✅
Progressive disclosure Core content is brief ✅
Error handling Includes a table of common error scenarios and handling methods ✅