Project

caliber

0.0
A long-lived project that still receives updates
Provides a high quality style guide and configuration for your projects.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies
 Project Readme

Caliber

This gem provides global RuboCop configurations for ensuring high quality and consistent software development practices.

Table of Contents
  • Features
  • Requirements
  • Setup
  • Usage
    • Customization
    • Auto-Requires
    • Import Only
  • Development
    • Check
  • Tests
  • Troubleshooting
  • License
  • Security
  • Code of Conduct
  • Contributions
  • Versions
  • Community
  • Credits

Features

Requirements

Setup

To install, run:

gem install caliber

Usage

This gem is designed to replace all of your RuboCop setup with only a single reference to this gem. You’ll want to start with your Gemfile by adding the following:

group :code_quality do
  gem "caliber"
end

Then, in your .rubocop.yml, add the following to the top of the file:

inherit_gem:
  caliber: config/all.yml

That’s it!

Customization

Should you not want everything that this gem offers, you can customize the gem further by specifiying what you need:

inherit_gem:
  caliber:
    - config/ruby.yml
    - config/performance.yml
    - config/thread.yml
    - config/rake.yml
    - config/rspec.yml

The above is what config/all.yml expands to but now you can mix and match how you like for your needs.

Auto-Requires

When Caliber is added to your Gemfile, you don’t have to require RuboCop because Caliber does that for you by default. All RuboCop dependencies are also auto-required because they are defined in each configuration. Here’s a full breakdown of how this works:

inherit_gem:
  caliber:
    - config/all.yml

The above will auto-require and load the configurations for following gems:

  • RuboCop Performance

  • RuboCop Thread Safety

  • RuboCop Rake

  • RuboCop RSpec

When you don’t use the default all.yml configuration, then behavior changes as follows:

inherit_gem:
  caliber:
    - config/ruby.yml

The above will only load the RuboCop Ruby configuration. Nothing is required since Caliber already requires the RuboCop gem by default.

inherit_gem:
  caliber:
    - config/peformance.yml

The above will only require the RuboCop Performance gem and load the associated configuration.

inherit_gem:
  caliber:
    - config/thread.yml

The above will only require the RuboCop Thread Safety gem and load the associated configuration.

inherit_gem:
  caliber:
    - config/rake.yml

The above will only require the RuboCop Rake gem and load the associated configuration.

inherit_gem:
  caliber:
    - config/rspec.yml

The above will only require the RuboCop RSpec gem and load the associated configuration.

Import Only

Should you not want to include this gem in your project for some reason, you can directly import the configuration files supported by this project instead. To do this, you’d need to add the following to the top of your .rubocop.yml:

inherit_from:
  - https://raw.githubusercontent.com/bkuhlmann/caliber/main/config/all.yml

You’ll also want to add .rubocop-https* to your project’s .gitignore since imported RuboCop YAML configurations will be cached locally and you’ll not want them checked into your source code repository.

If importing all configurations from all.yml is too much — and much like you can do with requiring this gem directly — you can mix and match what you want to import by defining which configurations you want to use. For example, the following is what all.yml expands too:

inherit_from:
  - https://raw.githubusercontent.com/bkuhlmann/caliber/main/config/ruby.yml
  - https://raw.githubusercontent.com/bkuhlmann/caliber/main/config/performance.yml
  - https://raw.githubusercontent.com/bkuhlmann/caliber/main/config/thread.yml
  - https://raw.githubusercontent.com/bkuhlmann/caliber/main/config/rake.yml
  - https://raw.githubusercontent.com/bkuhlmann/caliber/main/config/rspec.yml

You can also target a specific version of this gem by swapping out the main path in the YAML URLs listed above with a specific version like 0.0.0.

Lastly, when using this YAML import approach, you’ll not benefit from having all gems you need required and installed for you. So you’ll need to manually require these gems in your Gemfile:

Development

To contribute, run:

git clone https://github.com/bkuhlmann/caliber.git
cd caliber
bin/setup

You can also use the IRB console for direct access to all objects:

bin/console

Check

Use the bin/check script — when upgrading to newer RuboCop gem dependencies — to check if duplicate configurations exist. This ensures Caliber configurations don’t duplicate effort provided by RuboCop. The script only identifies duplicate Caliber configurations which are enabled and have no other settings.

When both RuboCop and Caliber are in sync, the following will be output:

RUBY: ✓
PERFORMANCE: ✓
THREAD: ✓
RAKE: ✓
RSPEC: ✓

When RuboCop has finally enabled cops that Caliber already has enabled, the following will display as an example:

RUBY:
* Lint/BinaryOperatorWithIdenticalOperands
* Lint/ConstantDefinitionInBlock
PERFORMANCE: ✓
THREAD: ✓
RAKE: ✓
RSPEC:
* RSpec/StubbedMock

The above can then be used as a checklist to remove from Caliber.

Tests

To test, run:

bundle exec rake

Troubleshooting

If you are having issues requiring additional RuboCop gems in conjunction with what this gem provides for you, there is a known issue and workaround to this problem. Until the RuboCop team can fix the bug, you’ll have to re-require your dependencies until then.

Credits