Skip to content

Backend tooling

We enforce Ruby style with RuboCop and the easy_style gem.

Prerequisites

You have finished Set up a development environment.

Usage

The platform Gemfile already contains easy_style in the development and test groups. Other projects (RYSes, plugin repositories) need it in their Gemfile or gemspec:

gem "easy_style"

Run RuboCop on the Ruby files you changed:

bundle exec rubocop path/to/changed_file.rb

The root .rubocop.yml inherits easy_style: default.yml and .rubocop_ignore.yml. It does not inherit .rubocop_todo.yml.

CI uses .rubocop_ci.yml, which additionally inherits .rubocop_todo.yml, so local and CI results can differ. This is intentional: you are encouraged to fix existing offenses, but a pipeline does not fail because edited code is near offenses that already existed.

Dealing with offenses

  • Fix fixable offenses, or generate .rubocop_todo.yml (see below and the RuboCop documentation).
  • For offenses you cannot fix, try to refactor the code, or disable the cop in the source.

Generating .rubocop_todo.yml

To get the same result as CI, generate the file with a minimal Gemfile containing only easy_style, then restore the original files.

RYS repositories (gems.rb):

alias cop_gen_rys="echo \"source 'https://rubygems.org'\" > gems.rb && echo \"gem 'easy_style'\" >> gems.rb && bundle update && bundle exec rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 10000 && git restore .rubocop.yml && git restore gems.rb && bundle update"

Regenerating the RYS todo file:

alias cop_regen_rys="echo \"source 'https://rubygems.org'\" > gems.rb && echo \"gem 'easy_style'\" >> gems.rb && bundle update && bundle exec rubocop --regenerate-todo && git restore .rubocop.yml && git restore gems.rb && bundle update"

Platform and plugins (Gemfile):

alias cop_gen_platform="echo \"source 'https://rubygems.org'\" > Gemfile && echo \"gem 'easy_style'\" >> Gemfile && bundle update && bundle exec rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 10000 && git restore .rubocop.yml && git restore Gemfile && bundle update"

RubyMine

  1. Enable Preferences > Editor > Inspections > Ruby > Gems and gem management > RuboCop.
  2. Make sure all gems are installed in the project, also for RYS and plugin repositories (bundle install).

Offenses are listed in View > Tool Windows > Problems; press Alt + Enter for autocorrect suggestions.