eslint-detector

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Purpose

用途

Detect ESLint presence and available commands in a repository, returning structured JSON data specifically formatted for the quality-gates-linter agent to consume.
检测代码仓库中ESLint的存在情况及可用命令,返回专为quality-gates-linter Agent设计的结构化JSON数据。

When to Use

使用场景

Invoke this skill during Phase 0 (Environment Detection) of the quality-gates-linter agent workflow to:
  • Verify ESLint is configured in the repository
  • Identify available ESLint commands (check and fix)
  • Locate command sources for the agent to read directly
This skill should NOT be invoked for general code review or linting tasks - only for environment detection.
在quality-gates-linter Agent工作流的第0阶段(环境检测)调用此技能,以:
  • 验证代码仓库中是否配置了ESLint
  • 识别可用的ESLint命令(检查和修复)
  • 定位命令来源,供Agent直接读取
此技能不应用于常规代码审查或linting任务,仅用于环境检测。

Detection Process

检测流程

Step 1: Check for ESLint Configuration

步骤1:检查ESLint配置

Search for ESLint configuration files using Glob tool:
  • .eslintrc.js
  • .eslintrc.json
  • .eslintrc.yml
  • .eslintrc.yaml
  • eslint.config.js
    (flat config)
  • package.json
    (check for
    eslintConfig
    field)
If NO configuration files found:
  • Set
    eslintDetected: false
  • Return early with minimal JSON structure
If configuration files found:
  • Set
    eslintDetected: true
  • Record all found config files with paths and types
  • Proceed to Step 2
使用Glob工具搜索ESLint配置文件:
  • .eslintrc.js
  • .eslintrc.json
  • .eslintrc.yml
  • .eslintrc.yaml
  • eslint.config.js
    (扁平配置)
  • package.json
    (检查是否存在
    eslintConfig
    字段)
如果未找到配置文件:
  • 设置
    eslintDetected: false
  • 提前返回最简JSON结构
如果找到配置文件:
  • 设置
    eslintDetected: true
  • 记录所有找到的配置文件的路径和类型
  • 进入步骤2

Step 2: Detect ESLint Commands

步骤2:检测ESLint命令

Search for ESLint commands in priority order:
按优先级顺序搜索ESLint命令:

2a. Check CLAUDE.md (Highest Priority)

2a. 检查CLAUDE.md(最高优先级)

If
CLAUDE.md
exists:
  • Read the file
  • Search for sections: "Linting", "Development Commands", "Code Quality", "Common Commands"
  • Look for command patterns:
    • Check commands:
      eslint
      ,
      lint
      ,
      make lint
      ,
      npm run lint
    • Fix commands:
      eslint --fix
      ,
      lint-fix
      ,
      make lint-fix
      ,
      npm run lint:fix
  • Extract exact commands mentioned
  • Record CLAUDE.md as source if commands found
如果
CLAUDE.md
存在:
  • 读取该文件
  • 搜索以下章节:"Linting"、"Development Commands"、"Code Quality"、"Common Commands"
  • 查找命令模式:
    • 检查命令:
      eslint
      lint
      make lint
      npm run lint
    • 修复命令:
      eslint --fix
      lint-fix
      make lint-fix
      npm run lint:fix
  • 提取提及的准确命令
  • 如果找到命令,记录CLAUDE.md为来源

2b. Check package.json Scripts

2b. 检查package.json脚本

Read
package.json
and examine the
scripts
section:
Lint check commands (look for these script names):
  • "lint"
  • "eslint"
  • "lint:check"
  • Extract as:
    npm run <script-name>
Lint fix commands (look for these script names):
  • "lint:fix"
  • "lint-fix"
  • "fix"
  • "eslint:fix"
  • Extract as:
    npm run <script-name>
Record package.json as source if commands found.
读取
package.json
并检查
scripts
章节:
Lint检查命令(查找以下脚本名称):
  • "lint"
  • "eslint"
  • "lint:check"
  • 提取格式:
    npm run <script-name>
Lint修复命令(查找以下脚本名称):
  • "lint:fix"
  • "lint-fix"
  • "fix"
  • "eslint:fix"
  • 提取格式:
    npm run <script-name>
如果找到命令,记录package.json为来源。

2c. Check Makefile

2c. 检查Makefile

If
Makefile
exists:
  • Read the file
  • Search for targets containing
    eslint
    or
    lint
  • Common target patterns:
    • Check:
      lint
      ,
      eslint
      ,
      check
    • Fix:
      lint-fix
      ,
      fix
      ,
      format
  • Extract as:
    make <target-name>
  • Record Makefile as source if commands found
如果
Makefile
存在:
  • 读取该文件
  • 搜索包含
    eslint
    lint
    的目标
  • 常见目标模式:
    • 检查:
      lint
      eslint
      check
    • 修复:
      lint-fix
      fix
      format
  • 提取格式:
    make <target-name>
  • 如果找到命令,记录Makefile为来源

2d. Fallback Commands

2d. 备用命令

If no commands found in any source:
  • Use fallback commands:
    • Check:
      npx eslint .
    • Fix:
      npx eslint --fix .
  • Record source as:
    "fallback"
如果在所有来源中都未找到命令:
  • 使用备用命令:
    • 检查:
      npx eslint .
    • 修复:
      npx eslint --fix .
  • 记录来源为:
    "fallback"

Step 3: Build JSON Response

步骤3:构建JSON响应

Construct JSON object with this exact structure:
json
{
  "eslintDetected": true,
  "configFiles": [
    {
      "path": ".eslintrc.json",
      "type": "eslintrc"
    },
    {
      "path": "package.json",
      "type": "package-config"
    }
  ],
  "commands": {
    "check": {
      "command": "npm run lint",
      "source": "package.json"
    },
    "fix": {
      "command": "npm run lint:fix",
      "source": "package.json"
    }
  },
  "commandSources": [
    "package.json"
  ]
}
Field Specifications:
  • eslintDetected
    (boolean):
    true
    if config found,
    false
    otherwise
  • configFiles
    (array): List of all ESLint config files found
    • path
      (string): Relative path to config file
    • type
      (string): Config type (
      "eslintrc"
      ,
      "eslint-config-js"
      ,
      "package-config"
      )
  • commands
    (object): Contains check and fix commands
    • check
      (object): Lint check command
      • command
        (string): Exact command to run
      • source
        (string): Where command was found
    • fix
      (object): Lint fix command
      • command
        (string): Exact command to run
      • source
        (string): Where command was found
  • commandSources
    (array): Ordered list of sources where commands were found
按以下精确结构构建JSON对象:
json
{
  "eslintDetected": true,
  "configFiles": [
    {
      "path": ".eslintrc.json",
      "type": "eslintrc"
    },
    {
      "path": "package.json",
      "type": "package-config"
    }
  ],
  "commands": {
    "check": {
      "command": "npm run lint",
      "source": "package.json"
    },
    "fix": {
      "command": "npm run lint:fix",
      "source": "package.json"
    }
  },
  "commandSources": [
    "package.json"
  ]
}
字段说明:
  • eslintDetected
    (布尔值):找到配置则为
    true
    ,否则为
    false
  • configFiles
    (数组):所有找到的ESLint配置文件列表
    • path
      (字符串):配置文件的相对路径
    • type
      (字符串):配置类型(
      "eslintrc"
      "eslint-config-js"
      "package-config"
  • commands
    (对象):包含检查和修复命令
    • check
      (对象):Lint检查命令
      • command
        (字符串):要执行的精确命令
      • source
        (字符串):命令的来源
    • fix
      (对象):Lint修复命令
      • command
        (字符串):要执行的精确命令
      • source
        (字符串):命令的来源
  • commandSources
    (数组):命令来源的有序列表

Step 4: Return JSON

步骤4:返回JSON

Output the JSON structure in a code block with clear formatting:
markdown
undefined
在代码块中输出格式化清晰的JSON结构:
markdown
undefined

ESLint Detection Results

ESLint检测结果

json
{
  "eslintDetected": true,
  "configFiles": [...],
  "commands": {...},
  "commandSources": [...]
}
Summary:
  • ESLint detected: Yes/No
  • Config files: <count>
  • Commands source: <primary source>
undefined
json
{
  "eslintDetected": true,
  "configFiles": [...],
  "commands": {...},
  "commandSources": [...]
}
摘要:
  • ESLint已检测到:是/否
  • 配置文件数量:<数量>
  • 命令来源:<主要来源>
undefined

Priority Rules

优先级规则

  1. Command Priority: CLAUDE.md > package.json > Makefile > fallback
  2. Use First Match: For each command type (check/fix), use the first match found
  3. Source Transparency: Always record where commands were found
  4. Config Completeness: List ALL config files found, not just the first one
  1. 命令优先级:CLAUDE.md > package.json > Makefile > 备用命令
  2. 使用首个匹配项:对于每种命令类型(检查/修复),使用找到的首个匹配项
  3. 来源透明:始终记录命令的来源
  4. 配置完整性:列出所有找到的配置文件,而非仅首个

Edge Cases

边缘情况

Multiple config files found:
  • List all in
    configFiles
    array
  • No impact on command detection
Command found in multiple sources:
  • Use highest priority source (CLAUDE.md wins)
  • Record only the used source in
    commandSources
Only check OR only fix command found:
  • Return the found command
  • For missing command, use fallback for that specific type
No ESLint config found:
json
{
  "eslintDetected": false,
  "configFiles": [],
  "commands": {},
  "commandSources": []
}
ESLint config found but no commands:
json
{
  "eslintDetected": true,
  "configFiles": [{...}],
  "commands": {
    "check": {
      "command": "npx eslint .",
      "source": "fallback"
    },
    "fix": {
      "command": "npx eslint --fix .",
      "source": "fallback"
    }
  },
  "commandSources": ["fallback"]
}
找到多个配置文件:
  • configFiles
    数组中列出所有文件
  • 不影响命令检测
在多个来源中找到命令:
  • 使用优先级最高的来源(CLAUDE.md优先)
  • commandSources
    中仅记录使用的来源
仅找到检查命令或仅找到修复命令:
  • 返回找到的命令
  • 对于缺失的命令类型,使用对应类型的备用命令
未找到ESLint配置:
json
{
  "eslintDetected": false,
  "configFiles": [],
  "commands": {},
  "commandSources": []
}
找到ESLint配置但未找到命令:
json
{
  "eslintDetected": true,
  "configFiles": [{...}],
  "commands": {
    "check": {
      "command": "npx eslint .",
      "source": "fallback"
    },
    "fix": {
      "command": "npx eslint --fix .",
      "source": "fallback"
    }
  },
  "commandSources": ["fallback"]
}

Integration with quality-gates-linter

与quality-gates-linter的集成

The quality-gates-linter agent will:
  1. Invoke this skill during Phase 0
  2. Parse the returned JSON structure
  3. Use
    eslintDetected
    to decide whether to proceed or exit
  4. Use
    commands.check.command
    for verification runs
  5. Use
    commands.fix.command
    for auto-fix attempts
  6. Read files listed in
    commandSources
    if needed for additional context
The JSON structure is designed to provide everything the linter agent needs without requiring additional file reads for command detection.
quality-gates-linter Agent将:
  1. 在第0阶段调用此技能
  2. 解析返回的JSON结构
  3. 根据
    eslintDetected
    决定继续执行或退出
  4. 使用
    commands.check.command
    进行验证运行
  5. 使用
    commands.fix.command
    尝试自动修复
  6. 如有需要,读取
    commandSources
    中列出的文件以获取额外上下文
该JSON结构的设计目的是为linter Agent提供所需的全部信息,无需为命令检测进行额外的文件读取。