Tips for Rubocop workflow

Tips for Rubocop workflow
Average rating: 0
(0 votes)

Let’s get back to Ruby! Have you ever faced CI build failures? For those of you who have Luca Guidi prepared tricks to avoid them. Would you like to explore practical tips for Rubocop workflow?

Rubocop is a Ruby static code analyzer, based on the community Ruby style guide. This linting tool for checking all Ruby source files in the current directory is one of the most used Ruby gems of all the time.

Bare minimum group of settings

# Please keep AllCops, Bundler, Layout, Style, Metrics groups and then order cops
# alphabetically
#
# References:
#   * https://github.com/bbatsov/ruby-style-guide
#   * https://rubocop.readthedocs.io/
AllCops:
  DisplayCopNames: true
  DisplayStyleGuide: true
  ExtraDetails: false
  TargetRubyVersion: 2.5

Integrate with your editor

Configure it to show not just syntax errors, but also Rubocop violations.

Integrate the autocorrect option with your editor

function! RubocopAutocorrect()
  execute "!rubocop -a " . bufname("%")
  call SyntasticCheck()
endfunction

map <silent> <Leader>cop :call RubocopAutocorrect()<cr>

Pre-commit hook

Install a Git pre-commit hook to handle situations when you don’t edit the file, yet still get CI failures.

Copy the following code into .git/hooks/pre-commit and ensure this file is an executable.

#!/bin/bash
git status -s | grep -E 'A|M|R' | awk '{print $2}' | xargs rubocop

We hope these tips will make you not afraid of CI build failures in Rubocop anymore!

Read the details here.

Rate this article, if you like it

Thanks! You’ve rated this material!

Got a project? Let's discuss it!

*By submitting this form you agree with our Privacy Policy.

Mailing & Legal Address

Syndicode Inc. 340 S Lemon Ave #3299, Walnut CA, 91789, USA

Visiting & Headquarters address
Kyiv Sofiivska 1/2a, 01001, Kyiv, Ukraine
Dnipro Hlinky 2, of. 1003, 49000, Dnipro, Ukraine
Email info@syndicode.com
Phone (+1) 9035021111