Custom rubocop & extensions configuration
README.md

neatcop #

A curated, LLM-agent-friendly RuboCop configuration, shipped as independently toggleable fragments. Pick a base plus exactly the extension fragments a project needs — nothing else gets pulled in.

Installation #

# Gemfile
group :development do
  gem 'neatcop', require: false

  # Add only the RuboCop extension gems matching the fragments you inherit
  # below. neatcop does not depend on these itself — see "Version guard".
  gem 'rubocop-rails', require: false      # config/ext/rails.yml
  gem 'rubocop-rspec', require: false      # config/ext/rspec.yml
  gem 'rubocop-rspec_rails', require: false # config/ext/rspec_rails.yml
  gem 'rubocop-minitest', require: false   # config/ext/minitest.yml
  gem 'rubocop-factory_bot', require: false # config/ext/factory_bot.yml
  gem 'rubocop-capybara', require: false   # config/ext/capybara.yml
  gem 'rubocop-rake', require: false       # config/ext/rake.yml
  gem 'rubocop-thread_safety', require: false # config/ext/thread_safety.yml
end

Usage #

Add an .rubocop.yml to your project that inherits config/base.yml plus whichever config/ext/*.yml fragments match your stack:

inherit_gem:
  neatcop:
    - config/base.yml
    - config/ext/rails.yml
    - config/ext/rspec.yml
    - config/ext/rspec_rails.yml
    - config/ext/factory_bot.yml
    - config/ext/capybara.yml

inherit_mode:
  merge:
    - Exclude

AllCops:
  TargetRubyVersion: 3.4   # or omit and let RuboCop infer it
  TargetRailsVersion: 8.0  # only with config/ext/rails.yml
  NewCops: enable          # opt in if you want cops added by future RuboCop releases

inherit_mode: { merge: [Exclude] } is required — without it, the last fragment's AllCops: Exclude list silently replaces every earlier one instead of combining with them.

What neatcop deliberately does not set #

TargetRubyVersion, TargetRailsVersion and ParserEngine belong to your project, so no fragment sets them:

  • TargetRubyVersion — set it yourself, or leave it out and let RuboCop infer it from .ruby-version / .tool-versions / your gemspec's required_ruby_version. A pin shipped in the gem would override that inference and either flag valid syntax or suggest idioms your Ruby lacks. Note that with nothing to infer from, RuboCop silently falls back to its oldest supported version (2.7) rather than erroring — rake neatcop:doctor warns when that happens.
  • TargetRailsVersion (with config/ext/rails.yml) — many enabled cops are gated on a minimum Rails version (Rails/EnvLocal needs 7.1, Rails/ToSWithArgument 7.0, Rails/CompactBlank 6.1). A pin higher than your actual Rails autocorrects code to APIs that do not exist in it.
  • NewCops — the default is disable, so a new RuboCop release cannot silently add unreviewed cops to a config whose selling point is that it is curated. Set NewCops: enable in your own .rubocop.yml if you'd rather see them as they land.

One deliberate restriction that is shipped: Style/DisableCopsWithinSourceCodeDirective is enabled, so # rubocop:disable comments are themselves an offense — the intended escape hatch is an Exclude entry (or a cop tweak) in your .rubocop.yml, where suppressions stay visible and reviewable. Disable that one cop if your project prefers inline directives.

Available fragments #

Fragment Adds Requires
config/base.yml Layout/Lint/Metrics/Style + Performance/* (always include this) rubocop-performance
config/ext/rails.yml Rails/* rubocop-rails
config/ext/rspec.yml RSpec/* rubocop-rspec
config/ext/rspec_rails.yml RSpecRails/* (needs ext/rspec.yml too) rubocop-rspec_rails
config/ext/minitest.yml Minitest/* rubocop-minitest
config/ext/factory_bot.yml FactoryBot/* rubocop-factory_bot
config/ext/capybara.yml Capybara/* rubocop-capybara
config/ext/rake.yml Rake/* rubocop-rake
config/ext/thread_safety.yml ThreadSafety/* rubocop-thread_safety
config/ext/project_index.yml Cross-file analysis (see below) rubydex — not a RuboCop extension

config/ext/project_index.yml — the one fragment with unusual requirements #

Every other cop in neatcop sees one file at a time. This fragment turns on RuboCop's project index (AllCops/UseProjectIndex, RuboCop >= 1.89) and the three cops that only exist because of it — Lint/NameTypo, Lint/DeprecatedReference and Lint/UnusedPrivateMethod — plus it silently sharpens a dozen cops you already have on.

Two things make it different from the other fragments:

  • Its dependency, rubydex, is a plain gem (a Rust-backed indexer), not a RuboCop extension — so unlike every other fragment it declares no plugins: entry, and you add gem 'rubydex', require: false to your own Gemfile.
  • A missing rubydex degrades rather than fails: RuboCop warns that index-based analyses will be skipped and carries on. rubocop -V (the verbose banner, not plain --version) appends +Rubydex when the index is actually live.

Building the index costs time and memory proportional to the codebase, once per run. Measure before turning it on in CI for a monorepo.

Rails caveat. rubydex indexes .rb files only, so Lint/UnusedPrivateMethod cannot see a method whose only caller is a template — .erb, .haml, .slim, .jbuilder. A helper used exclusively from a view is reported as unused. Ruby-side indirection resolves correctly (before_action :name, send(:name), symbol arrays), so this is specific to non-Ruby files. The fragment ships Lint/UnusedPrivateMethod and Lint/NameTypo at Severity: warning rather than the error the Lint department otherwise carries, so a false positive reports without failing the build; exclude the affected paths if you want it silent.

Common combinations #

Plain Ruby gem/library on Minitest:

inherit_gem:
  neatcop:
    - config/base.yml
    - config/ext/minitest.yml

Plain Ruby gem/library on RSpec:

inherit_gem:
  neatcop:
    - config/base.yml
    - config/ext/rspec.yml

Rails app on Minitest (the Rails default test stack):

inherit_gem:
  neatcop:
    - config/base.yml
    - config/ext/rails.yml
    - config/ext/minitest.yml

Rails app on RSpec + FactoryBot + Capybara:

inherit_gem:
  neatcop:
    - config/base.yml
    - config/ext/rails.yml
    - config/ext/rspec.yml
    - config/ext/rspec_rails.yml
    - config/ext/factory_bot.yml
    - config/ext/capybara.yml

config/ext/rake.yml is broadly applicable (most projects have a Rakefile) and safe to add to any combination above. config/ext/thread_safety.yml is narrower — include it deliberately for apps with real concurrency (Sidekiq workers, threaded servers); it's noise on a simple single-threaded CRUD app. config/ext/project_index.yml is orthogonal to all of them and can be added to any combination, once you've added rubydex to your Gemfile — but read the Rails caveat above first if your views call private helper methods.

Per-project overrides go below the inherit_gem/inherit_mode block in your own .rubocop.yml, same as any RuboCop config.

Version guard #

neatcop does not pin the RuboCop extension gems as runtime dependencies (a plain-Ruby project shouldn't be forced to install rubocop-rails). Instead each config/ext/*.yml fragment is tested against a specific floor version (see Neatcop::TESTED_VERSIONS in lib/neatcop/compatibility.rb) — an older installed gem can rename or drop a cop neatcop references, which RuboCop reports as an "unrecognized cop" config error rather than a clear message.

A version floor only catches gems that are too old. Extension gems also remove cops as they move forward (rubocop-capybara 3.0 dropped Capybara/ClickLinkOrButtonStyle), which no floor can predict — so the doctor also has RuboCop resolve your actual config and reports whatever it says about unrecognized cops, unsupported parameters and obsolete names.

# Rakefile
require 'neatcop/rake_task'
bundle exec rake neatcop:doctor   # prints every problem, exits 1 if there are any

Or call the pieces directly (e.g. in a CI step or a spec):

require 'neatcop'
Neatcop.check_versions   # => [] or an array of warning strings
Neatcop.verify_versions! # raises Neatcop::Error if any gem is too old
Neatcop.check_config     # => [] or an array of config problems, from RuboCop itself
Neatcop.check_config(config: 'config/.rubocop_ci.yml') # a specific config
Neatcop.check_target_ruby # => [] or a warning that TargetRubyVersion fell back below 3.4

Only gems actually present in your bundle are checked — a plain-Ruby project without rubocop-rails installed is never asked to satisfy its floor. check_config shells out to rubocop, so run it where that resolves (under bundle exec); if it can't, it says so instead of raising.

Development #

bundle install
bundle exec rake test  # rspec — includes an integration spec per fragment combo
bundle exec rake lint   # rubocop, dogfooding this gem's own config/base.yml + config/ext/rspec.yml

License #

MIT.