@codacy/tools-rubocop-1
Table of Contents
Overview
Ruby linter and formatter using RuboCop with 22+ plugin gems. Uses the CLI execution strategy -- spawns rubocop --format json via spawnTool() and parses its JSON output.
| Property | Value |
|---|---|
| Tool ID | RuboCop |
| Codacy UUID | 724f98da-f616-4e37-9606-f16919137a1e |
| Strategy | CLI |
| Languages | Ruby |
| Binary | rubocop (installed via gem install) |
| File patterns | **/*.rb, **/*.rake, **/*.gemspec, **/Gemfile, **/Rakefile |
Updating patterns
pnpm prefetch
git add src/patterns.json
Pattern IDs use underscore-separated cop names (no prefix): Style_StringLiterals, Lint_Debugger, Metrics_MethodLength, etc.
Updating the RuboCop version
- Update
RUBOCOP_VERSIONinsrc/adapter.ts - Review plugin gem compatibility -- some plugins pin specific RuboCop versions
- Run
pnpm prefetchto check for new/removed cops - Run
pnpm testto verify compatibility - If the major version changes, create a new adapter package (
rubocop-2/)
Development
pnpm build # Build with tsup
pnpm test # Run tests (requires ruby + rubocop in PATH for integration tests)
To install rubocop locally for testing:
gem install rubocop -v 1.91.0
gem install rubocop-performance rubocop-rails rubocop-rspec
Notes for maintainers
-
Preset mappings (
src/pattern-mappings.json):I18n_GetText_*gates on a newgettextentity (thegettext,gettext_i18n_railsorrubocop-i18ngem) andI18n_RailsI18n_*joins the existingruby-on-railskey, since Rails I18n ships with Rails and needs no separate entity. All six were default-off and ungated before, which meantinit --autocould never enable them — the two cop families are mutually exclusive in practice, so leaving both universal was the worst of both options. -
RuboCop requires Ruby >= 2.7. The adapter uses
ensureRuby()for portable Ruby download. -
22+ plugin gems are installed alongside rubocop, matching the Codacy
codacy-rubocopwrapper. The full list is inGEM_PACKAGESinadapter.ts. Plugin gems are installed without version pins (except rubocop itself) to let gem resolve compatible versions. -
Gems are installed in
~/.codacy/runtimes/rubocop-1/gems/viaGEM_HOME/GEM_PATH. -
Output format is JSON with
files[].offenses[]structure. -
Pattern IDs:
cop_namewith/replaced by_(e.g.Style/StringLiterals→Style_StringLiterals). -
Line/column are 1-based — direct mapping, no conversion needed.
-
Multi-line offenses:
location.start_line/location.last_linemap toIssue.line/Issue.endLine. -
Exit codes: 0 = clean, 1 = offenses found (normal success), 2 = error.
-
--force-exclusionensures config exclusions apply even for explicitly listed files. -
--cache falseensures fresh analysis on every run. -
Pattern filtering is post-hoc: RuboCop runs against all provided files with all cops, then output is filtered by the enabled patterns set.
-
Config file detection supports
.rubocop.yml,.config/.rubocop.yml,.config/rubocop/config.yml.