Config files for Rubocop and its extensions.
Default values commented and presented here for convenience.
Property Enabled
always presented.
Preferences:
- Reduce amount of changed lines in diff.
- Always use consistent indentation (2 spaces per indentation level).
- Code structure follows its semantics. See Layout/ClassStructure.
Config files will be updated in this repository about once a month after updating Rubocop and its extensions.
You may select which config files should be included into your project:
# In your .rubocop.yml file:
inherit_gem:
rubocop-configs:
- _all_cops.yml
# _ruby.yml includes:
# layout.yml
# lint.yml
# metrics.yml
# migration.yml
# naming.yml
# security.yml
# style.yml
- _ruby.yml
- bundler.yml
- capybara.yml
- factory_bot.yml
- gemspec.yml
- graphql.yml
- performance.yml
- rails.yml
- rake.yml
- rspec.yml
- rspec_rails.yml
- rswag.yml
- sequel.yml
You may override any config values in your .rubocop.yml file, as usual.
Also you have to include gems for Rubocop and its extensions into your Gemfile. Theirs versions should match specified versions in these config files.
And add this gem too:
gem "rubocop-configs", require: false, git: "https://github.com/crosspath/rubocop-configs.git"
Let's take an example! Suppose you're building typical Rails project, you have to do:
- Prepend this code to
.rubocop.yml
:
inherit_gem:
rubocop-configs:
- _all_cops.yml
- _ruby.yml
- bundler.yml
- rails.yml
- rake.yml
- Append these gems to
Gemfile
:
group :development, optional: true do
gem "prism" # For parser_prism in Rubocop.
gem "rubocop", "~> 1.65", require: false
gem "rubocop-configs", require: false, git: "https://github.com/crosspath/rubocop-configs.git"
gem "rubocop-rails", "~> 2.25", require: false
gem "rubocop-rake", "0.6.0", require: false
end
If you use optional
flag in Gemfile, you should enable it in bundle config
. See more
here. In short: run in console
bundle config set --global with development:test
to enable it everywhere in your user profile.
- Run
bundle install
Now you're ready to check your code with Rubocop and these config files. Run Rubocop as usual:
bundle exec rubocop
This repository includes config files for these gems and versions:
- rubocop, 1.65:
- _all_cops.yml
- _ruby.yml
- bundler.yml
- gemspec.yml
- layout.yml
- lint.yml
- metrics.yml
- migration.yml
- naming.yml
- security.yml
- style.yml
- rubocop-capybara, 2.21:
- capybara.yml
- rubocop-factory_bot, 2.26:
- factory_bot.yml
- rubocop-graphql, 1.5:
- graphql.yml
- rubocop-performance, 1.21:
- performance.yml
- rubocop-rails, 2.25:
- rails.yml
- rubocop-rake, 0.6.0:
- rake.yml
- rubocop-rspec, 3.0:
- rspec.yml
- rubocop-rspec_rails, 2.30:
- rspec_rails.yml
- rubocop-sequel, 0.3.4:
- sequel.yml
- rubocop-thread_safety, 0.5.1:
- thread_safety.yml
- rswag-specs, 2.13:
- rswag.yml
You may use rake task to compare gems' versions:
- Add this stroke of code to
Rakefile
in your project:
RubocopConfigs.load_tasks
- Run
rake rubocop_configs:versions
It outputs message Versions match!
if everything is correct. Otherwise you'll see error.
You may use this task in CI. This task exits with status 1 on error and 0 on success.
Or you may write test:
# RSpec syntax
describe RubocopConfigs do
describe ".check_versions" do
it "matches versions" do
errors = RubocopConfigs.check_versions
expect(errors).to be_empty
end
end
end
Code above does not check version of gem rswag-specs
.
Change of major version (1.*.* -> 2.*.*
) means backwards-incompatible changes in the gem code,
that requires changes in your (client) code.
Change of minor version (*.1.* -> *.2.*
) means backwards-compatible changes in the gem code, that
normally should not require changes in client code.
Change of build/patch version (*.*.1 -> *.*.2
) means backwards-compatible changes in the gem code,
that do not require changes in client code.
Minor version may be changed due to updating config files to newer version of Rubocop and its extensions, but not limited to this.
How to review and update config values?
-
Compare changes in default config files for Rubocop and its extensions. Example link:
-
Review changes in file
config/default.yml
-
Carefully update config files in this repository.
-
Use test project to ensure these config files are OK.
-
Update gem versions in README, config files and rake task.
-
Add Changelog entry.
-
Push changes to the repository and add git tag.
License: MIT.