My RuboCop configuration to be shared between different projects.
Somewhat similar to rubocop-rails-omakase, but with significantly stricter/stronger rules and style, mostly based on default configurations.
This configuration is somewhat opinionated and does not always conform to Ruby style guide. It will also probably change over time.
Currently contains configuration for:
Tip
Recommended extra plugins:
- rubocop-packaging (for gems)
- rubocop-rake
Even more extra for Rails projects:
Puts this in your .rubocop.yml
(custom file locations are not supported):
inherit_from:
- https://raw.githubusercontent.com/trinistr/rubocop-config/main/rubocop.yml
plugins:
- rubocop-performance
- rubocop-rspec
- rubocop-thread_safety
# ...other plugins
# require:
# # older plugins
# Your configuration goes here
RuboCop will download the configuration from GitHub and cache it locally. When the configuration changes, RuboCop will download the new version automatically.
Note
The plugin system is supported in RuboCop 1.72+. In earlier versions, use require
instead of plugins
.
Why is `.rubocop.yml` required?
RuboCop fails on at least some cops if they are configured, but the plugins are not loaded. As ERB preprocessing happens on file load, before we can determine the full configuration, we have to manually check a known file to determine what cops to enable.
Sadly, this means that additional plugins' activation in subfolders will not influence what is loaded in this configuration.
This configuration is written based on these versions:
- rubocop (1.76.0)
- rubocop-performance (1.25.0)
- rubocop-rspec (3.6.0)
- rubocop-thread_safety (0.7.3)
However, the only hard requirement is "rubocop", "~> 1.0"
.
All cops introduced later, and all plugins' cops are protected by version checks.
Later versions of gems will probably work, unless a major version changes cops too much,
or cops are renamed.
Using all or any of RuboCop plugins is not required, you can just not include them in your config.
All plugin cops' configurations are surrounded with a grep
test, so they won't activate if the plugin is not included.
Cop settings can be overridden as usual, see RuboCop Configuration, especially inheritance section for details.
All rubocop gems can be found at RubyGems. Official plugins are available under rubocop organization on GitHub.
These are plugins I found interesting and worth considering: