Pragmatic Ruby Styling for Projects
Setting up a new project with Rubocop can take some time. There are several decisions to make and many plugins to consider. This gem attempts to alleviate some of this hassle by both curating a default set of plugins and a default set of config overrides. Rubocop's defaults are usually top notch, but there are a few areas where the cops might be considered a little too pedantic and/or strict. This gem attempts to find a reasonable and pragmatic middle ground to get a new project off the ground and running well with Ruby's favorite linter.
Installation
gem "rubocop-pragmatic", require: false, group: [:development]Run bundle, then bundle binstubs rubocop.
Add a default .rubocop.yml file in the root of your Rails application with:
inherit_gem:
rubocop-pragmatic: rails.yml
# Your own specialized rules go hereFor a ruby gem or project (not using Rails):
inherit_gem:
rubocop-pragmatic: ruby.yml
# Your own specialized rules go hereOr to customize your own combination:
inherit_gem:
rubocop-pragmatic:
- rubocop.yml
- rubocop-factory_bot.yml
- rubocop-md.yml
- rubocop-minitest.yml
- rubocop-performance.yml
inherit_mode:
merge:
- Exclude
# Your own specialized rules go hererubocop-pragmatic is opionated about minitest, but offers the option to customize with rubocop-rspec and rubocop-rspec_rails:
inherit_gem:
rubocop-pragmatic:
- rails.yml
- rubocop-rspec.yml
- rubocop-rspec_rails.yml
Minitest:
Enabled: false
# Your own specialized rules go hereFail Level Recommendation
It's also recommended to set --fail-level=convention. Metrics and
Performance cops run at the "refactor" severity level while all other cops
run at the "convention" severity level by default. This is intentional as to
not return a failure exit code for Metrics or Performance
cops. e.g. Sometimes, these cops need to be ignored while dealing with
hotfixes or emergency PRs etc.
This can be set on a project by adding a .rubocop file in the root of your
project:
--fail-level=convention