Convention Over Configuration
🦾 RuboCop LTS - Rules for Rubies: Rubocop + Standard + Betterlint + Shopify + Gradual
đź’ˇ See the intro blog post!
The RuboCop LTS family of gems is the distillation of almost 20 years of my own Ruby expertise and source code diving, built on the shoulders of the expertise of many others; organizing that expertise into per-Ruby-version sets of configurations.
Although the situation has improved somewhat, it remains unsafe to upgrade RuboCop, or Standard, in a project that supports EOL Rubies.
I hope it helps others avoid some of the challenges I’ve had with library maintenance, and supporting decade-old mission-critical applications.
Avoid bike-shedding, use rubocop-lts
in every project, and
let it manage your linting complexity!
If the rubocop-lts
stack of libraries has helped you, or your organization,
please support my efforts by making a donation, or becoming a sponsor.
đź—ż Conventions > Configuration
The major version you need depends on the supported version(s) of Ruby for your project.
Supported Rubies
Odd major version releases have been deprecated, and no further add major releases are planned.
All future releases will be even major releases.
EOL Rubies
RuboCop needs to run on a recent, non-EOL ruby in order to apply the rules for an older EOL version of ruby.
Version Conventions
Even Major Release
Versions like:
"0.x" # Runs on Ruby 2.7+ and analyzes Ruby 1.8
"2.x" # Runs on Ruby 2.7+ and analyzes Ruby 1.9
"4.x" # Runs on Ruby 2.7+ and analyzes Ruby 2.0
"6.x" # Runs on Ruby 2.7+ and analyzes Ruby 2.1
"8.x" # Runs on Ruby 2.7+ and analyzes Ruby 2.2
"10.x" # Runs on Ruby 2.7+ and analyzes Ruby 2.3
"12.x" # Runs on Ruby 2.7+ and analyzes Ruby 2.4
"14.x" # Runs on Ruby 2.7+ and analyzes Ruby 2.5
"16.x" # Runs on Ruby 2.7+ and analyzes Ruby 2.6
"18.x" # Runs on Ruby 2.7+ and analyzes Ruby 2.7
"20.x" # Runs on Ruby 3.0+ and analyzes Ruby 3.0
"22.x" # Runs on Ruby 3.1+ and analyzes Ruby 3.1
"24.x" # Runs on Ruby 3.2+ and analyzes Ruby 3.2
required_ruby_version
is locked to the forward range of Rubies on which the gem can be installed and run,
but the analysis only targets a single minor version of Ruby.
E.g. version 16.0 has a required_ruby_version
of '>= 2.7'
will install on any version
of ruby from 2.7
on, but it will analyze based on rules intended for Ruby 2.6.
Odd Major Release
These are deprecated. Please upgrade to an even version release.
Usage
Intended for applications and libraries that lint against a range of Ruby versions.
Even versions will help projects upgrade to newer Rubies while keeping the same underlying version of RuboCop version, so change can be introduced one step at a time.
Minimum Runtime Ruby | Your Gemfile | Your Gemfile.lock | Your .rubocop.yml |
---|---|---|---|
1.8.x |
gem "rubocop-lts", "~> 0.0" |
rubocop-ruby1_8 |
inherit_gem:\n rubocop-lts: rubocop-lts.yml (note: or one of the other options in config/) |
1.9.x |
gem "rubocop-lts", "~> 2.0" |
rubocop-ruby1_9 |
👆️ (no change) |
2.0.x |
gem "rubocop-lts", "~> 4.0" |
rubocop-ruby2_0 |
👆️ (no change) |
2.1.x |
gem "rubocop-lts", "~> 6.0" |
rubocop-ruby2_1 |
👆️ (no change) |
2.2.x |
gem "rubocop-lts", "~> 8.0" |
rubocop-ruby2_2 |
👆️ (no change) |
2.3.x |
gem "rubocop-lts", "~> 10.0" |
rubocop-ruby2_3 |
👆️ (no change) |
2.4.x |
gem "rubocop-lts", "~> 12.0" |
rubocop-ruby2_4 |
👆️ (no change) |
2.5.x |
gem "rubocop-lts", "~> 14.0" |
rubocop-ruby2_5 |
👆️ (no change) |
2.6.x |
gem "rubocop-lts", "~> 16.0" |
rubocop-ruby2_6 |
👆️ (no change) |
2.7.x |
gem "rubocop-lts", "~> 18.0" |
rubocop-ruby2_7 |
👆️ (no change) |
3.0.x |
gem "rubocop-lts", "~> 20.0" |
rubocop-ruby3_0 |
👆️ (no change) |
3.1.x |
gem "rubocop-lts", "~> 22.0" |
rubocop-ruby3_1 |
👆️ (no change) |
3.2.x |
gem "rubocop-lts", "~> 24.0" |
rubocop-ruby3_2 |
👆️ (no change) |
Options
Default loads the configs for the relevant version of Ruby, and RSpec.
inherit_gem:
rubocop-lts: rubocop-lts.yml
In other words, the default is equivalent to the following:
inherit_gem:
rubocop-lts: config/ruby_rspec.yml
If you are using Ruby, but not RSpec, there’s a config for that.
inherit_gem:
rubocop-lts: config/ruby.yml
If you are building a RubyGem try this:
inherit_gem:
rubocop-lts: config/rubygem.yml
If your RubyGem is tested with RSpec, simply do:
inherit_gem:
rubocop-lts: config/rubygem_rspec.yml
If you are building a Rails app, then copy paste:
inherit_gem:
rubocop-lts: config/rails.yml
If your Rails app is tested with RSpec, then do one better:
inherit_gem:
rubocop-lts: config/rails_rspec.yml
If you only want the RSpec configs:
inherit_gem:
rubocop-lts: config/rspec.yml
If you have ideas for other “collections of rules”, I’m open to suggestions. I’ve thought about a minitest collection, but I haven’t used it much.
Tracking Branches
Each major version will have a tracking branch named accordingly, for development.