CLI 目录 横向对比 FCRS-1.0 标准 /llms.txt
← 返回 CLI 目录

RuboCop

$ rubocop 社区开源 低风险
RuboCop · 代码托管与研发协同 · MIT · macos / linux / windows

Ruby 与 Rails 生态的标准静态分析、Lint 与代码格式化工具,覆盖风格、缺陷、安全与复杂度规则。支持结构化 --format json 报告,并将安全的 --autocorrect(-a)与激进的 --autocorrect-all(-A)严格区分。

FCRS-1.0 综合评分
85 /100
良好 (Good)
中置信度 (源码/文档)
零摩擦安装命令
brew install rubocop
CLI vs MCP 选型建议 仅 CLI 可用

直接在本地分析与格式化 Ruby 文件,配合 --server 速度很快,无需 MCP。

Agent 友好度体检单

✓ 原生 JSON 输出
— 字段裁剪
✓ 无头非交互
— 支持 Dry-Run
— 只读模式开关
✓ 支持 NO_COLOR
✓ 自省/Schema 发现
— 官方 SKILL.md

当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。

FCRS-1.0 六维评分拆解

Agent 友好度 22 / 25

支持 --format json、--no-color、--only 规则过滤、--fail-level 与 --server 常驻加速。

  • --format json emits clean JSON payloads
  • --only and --except filter cops precisely
安全与权限边界 21 / 25

默认只读,且区分安全 --autocorrect 与不安全的 --autocorrect-all,但缺少干跑 diff 预演参数。

  • Safe -a vs unsafe -A autocorrection boundary
安装与运行摩擦 12 / 15

可通过 Homebrew 或 gem install rubocop / Bundler 安装,依赖 Ruby 运行时。

  • Requires Ruby runtime and project Gemfile plugins (e.g. rubocop-rails)
能力覆盖与边际价值 13 / 15

将 Ruby 检查与格式化合二为一,具备完善的 Rails/RSpec 插件与 --server 缓存。

  • Covers style, lint, security, and metrics in one CLI
维护与来源背书 9 / 10

Ruby 社区核心工具(rubocop/rubocop),以 MIT 协议积极维护。

  • Canonical rubocop/rubocop repository
文档与可验证性 8 / 10

docs.rubocop.org 提供结构清晰的 CLI 选项与全部规则文档。

  • Official docs at docs.rubocop.org

安全边界、鉴权与放权指南

鉴权方式
无需鉴权
凭证存储位置

离线本地 Ruby 静态分析器,不存储也不需要任何凭证。

潜在副作用
只读查询 本地写入
费用与配额提示

MIT 开源 Ruby 工具,完全免费。

可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# RuboCop (rubocop) Agent Rules
- Always pass `--format json --no-color` when inspecting Ruby offenses.
- Prefer `--autocorrect` (`-a`) over `--autocorrect-all` (`-A`), which can rewrite semantics.

Agent 高频安全命令配方

只读查询(安全推荐)

以 JSON 输出运行 RuboCop 诊断
rubocop --format json --no-color

以 JSON 输出逐文件的违规条目、行列位置、规则名与严重程度。

受控写入与预演

应用安全的 RuboCop 自动修复
rubocop --autocorrect --format json app/

仅对 app/ 应用安全自动修复(-a)并以 JSON 输出剩余问题。

核心优势

  • + 内置 --format json --no-color 可返回规则名、级别与精确代码位置。
  • + 清晰隔离安全修复 --autocorrect(-a)与可能改语义的 --autocorrect-all(-A)。

注意事项与踩坑点

  • ! 包含 rubocop-rails 或 rubocop-rspec 的项目应通过 bundle exec rubocop 调用而非全局二进制。
  • ! 执行 -a 写入前没有内置的 --dry-run 差异预览开关。

已验证兼容的 Agent 宿主

Claude Code Codex CLI Gemini CLI