Tips for Rubocop workflow

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

Thanks! You’ve rated this material!

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:
#   *
#   *
  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()

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.

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!

    Kyiv Sofiivska 1/2a, 01001, Kyiv, Ukraine
    Dnipro Hlinky 2, of. 1003, 49000, Dnipro, Ukraine
    Kharkiv Otakara Yarosha 22, 61000, Kharkiv, Ukraine