关于 configure-linting
为编码 Agent 提供的代码检查配置技能,可检测 JavaScript/TypeScript、Python 和 Rust 项目中的 Linter 设置,并生成合规报告或配置工具及 CI 集成。
主要功能
- 01检测语言与现有 Linter
- 02检查规则、格式化与忽略配置
- 03生成合规报告与建议
- 04配置 Linter 及 npm 脚本
- 05设置 pre-commit 与 CI 检查
- 06支持仅检查、自动修复和指定 Linter
适用场景
- 01为新项目建立代码检查配置
- 02从 ESLint 或 Flake8 迁移
- 03检查格式化、pre-commit 与 CI 集成情况
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ laurigates/ claude-plugins --skill configure-linting安装后在 Claude Code 中输入/configure-linting确认已加载。
附带文件REFERENCE.md
详细介绍
/configure:linting
根据现代最佳实践检查并配置代码检查工具。
何时使用此技能
| 在以下情况下使用此技能…… | 在以下情况下使用其他方法…… |
|---|---|
| 设置现代代码检查工具(Biome、Ruff、Clippy) | 仅运行代码检查工具(使用 /lint:check 技能) |
| 从 ESLint/Prettier 迁移到 Biome | 代码检查工具已正确配置 |
| 验证代码检查工具配置 | 修复特定的代码检查错误(运行代码检查工具并修复) |
| 确保遵循语言特定的最佳实践 | 不需要代码检查的简单脚本 |
| 配置 pre-commit 代码检查集成 | 调试代码检查工具问题(查看代码检查工具日志) |
上下文
- 项目根目录:!
pwd - Biome 配置:!
find . -maxdepth 1 -name 'biome.json' -o -name 'biome.jsonc' - Ruff 配置:!
grep -l 'tool.ruff' pyproject.toml - Clippy 配置:!
grep -l 'lints.clippy' Cargo.toml - 旧版代码检查工具:!
find . -maxdepth 1 \( -name '.eslintrc*' -o -name '.flake8' -o -name '.pylintrc' \) - 包文件:!
find . -maxdepth 1 \( -name 'package.json' -o -name 'pyproject.toml' -o -name 'Cargo.toml' \) - Pre-commit 配置:!
find . -maxdepth 1 -name '.pre-commit-config.yaml' - CI 工作流:!
find .github/workflows -maxdepth 1 -name '*.yml'
参数
从 $ARGUMENTS 中解析:
--check-only:报告代码检查合规状态,不做任何修改--fix:自动应用所有修复,无需提示--linter <biome|ruff|clippy>:覆盖自动检测结果,强制使用指定的代码检查工具
现代代码检查偏好:
- JavaScript/TypeScript:Biome(集代码检查工具和格式化工具于一体,速度快)
- Python:Ruff(替代 flake8、isort、pyupgrade)
- Rust:Clippy(配合工作区级 lint)
执行
执行此代码检查配置检查:
第 1 步:检测项目语言和现有代码检查工具
读取上方的上下文值并确定:
| 指标 | 语言 | 检测到的代码检查工具 |
|---|---|---|
biome.json | JavaScript/TypeScript | Biome |
pyproject.toml [tool.ruff] | Python | Ruff |
.flake8 | Python | Flake8(旧版) |
Cargo.toml [lints.clippy] | Rust | Clippy |
如果设置了 --linter 标志,则无论检测结果如何,都使用指定的代码检查工具。
第 2 步:验证工具的最新版本
使用 WebSearch 或 WebFetch 检查当前版本:
- Biome:查看 biomejs.dev 或 GitHub releases
- Ruff:查看 docs.astral.sh/ruff 或 GitHub releases
- Clippy:查看 Rust releases
第 3 步:分析当前代码检查工具配置
针对每个检测到的代码检查工具,检查配置是否完整:
Biome(适用于 JS/TS):
- 配置文件存在且包含代码检查规则
- 已配置格式化工具
- 已设置文件模式和忽略项
- 已启用推荐规则
Ruff(适用于 Python):
pyproject.toml中包含[tool.ruff]节- 已选择规则(E、F、I、N 等)
- 已设置行长度和目标 Python 版本
Clippy:
Cargo.toml中包含[lints.clippy]节- 已启用 Pedantic lint
- 适用时已配置工作区级 lint
第 4 步:生成合规报告
输出一份合规报告,涵盖以下内容:
- 配置文件状态(存在 / 缺失)
- 代码检查工具启用状态
- 规则配置(推荐 / 最低限度 / 缺失)
- 格式化工具集成
- 忽略模式
package.json/ Makefile 中的 lint 脚本- Pre-commit 钩子集成
- CI/CD 检查集成
最后给出问题总数和建议。
如果设置了 --check-only,则在此处停止。
步骤 5:配置 lint(如果使用 --fix 或用户确认)
使用 REFERENCE.md 中的模板应用配置。
对于 Biome(JS/TS):
- 将 Biome 安装为开发依赖
- 创建包含推荐规则的
biome.json - 添加 npm 脚本(
lint、lint:fix、format、check)
对于 Ruff(Python):
- 通过
uv add --group dev ruff安装 Ruff - 在
pyproject.toml中添加[tool.ruff]部分 - 配置规则、行长度和目标版本
对于 Clippy(Rust):
- 在
Cargo.toml中添加[lints.clippy]部分 - 启用 pedantic lint
- 在适用时配置工作区级别的 lint
如果检测到旧版 lint 工具(ESLint、Flake8 等),则提供迁移选项。请参阅 REFERENCE.md 中的迁移指南。
步骤 6:配置 pre-commit 和 CI 集成
- 将 linter pre-commit 钩子添加到
.pre-commit-config.yaml - 将 linter CI 检查添加到 GitHub Actions 工作流
- 使用 REFERENCE.md 中的模板
步骤 7:更新标准跟踪
更新 .project-standards.yaml:
components:
linting: "2025.1"
linting_tool: "[biome|ruff|clippy]"
linting_pre_commit: true
linting_ci: true
步骤 8:打印最终合规报告
打印已应用的所有更改、新增的脚本、配置的集成,以及为用户提供的后续步骤的摘要。
如需详细的配置模板、迁移指南和 CI 集成模式,请参阅 REFERENCE.md。
Agentic 优化
| 上下文 | 命令 |
|---|---|
| 检测 linter 配置 | find . -maxdepth 1 \( -name 'biome.json' -o -name 'ruff.toml' -o -name '.eslintrc*' \) 2>/dev/null |
| 检查 Biome 配置 | test -f biome.json && jq -c '.linter' biome.json 2>/dev/null |
| 检查 pyproject 中的 Ruff | grep -A5 '\[tool.ruff\]' pyproject.toml 2>/dev/null |
| 列出 lint 脚本 | jq -r '.scripts | to_entries[] | select(.key | contains("lint")) | "\\(.key): \\(.value)"' package.json 2>/dev/null |
| 快速合规检查 | /configure:linting --check-only |
| 自动修复配置 | /configure:linting --fix |
标志
| 标志 | 描述 |
|---|---|
--check-only | 报告状态,不提供修复选项 |
--fix | 自动应用所有修复,不提示 |
--linter <linter> | 覆盖 linter 检测结果(biome、ruff、clippy) |
示例
# Check compliance and offer fixes
/configure:linting
# Check only, no modifications
/configure:linting --check-only
# Auto-fix and migrate to Biome
/configure:linting --fix --linter biome
错误处理
- 检测到多个 linter:警告存在冲突,并建议迁移
- 未找到包管理器:无法安装 linter,报错
- 配置无效:报告解析错误,并提供替换为模板的选项
- 缺少依赖项:提供安装所需软件包的选项
另请参阅
/configure:formatting- 配置代码格式/configure:pre-commit- 配置 pre-commit 钩子/configure:all- 运行所有合规检查- Biome 文档:https://biomejs.dev
- Ruff 文档:https://docs.astral.sh/ruff
- Clippy 文档:https://doc.rust-lang.org/clippy
评论
支持 Markdown