Slide 1

Slide 1 text

DR. RUBOCOP Or: How I Learned to Stop Worrying and Love the Codebase

Slide 2

Slide 2 text

DIFFERENT CODEBASES 100000 lines 8 years old 155 contributors 2000 lines 1 year old 6 contributors

Slide 3

Slide 3 text

HOW TO GUARANTEE UNIFORMITY? Or just avoiding some ruby pitfalls and repeating the same mistakes

Slide 4

Slide 4 text

OVER TIME AND CODEBASES How do you keep code style consistent? How do you avoid errors and bad code “practices”? How do you ensure that your code complexity remains low? How do you make sure you are not using inefficient or insecure ruby calls? How do you make sure your code is using new features or is ready for new ruby versions?

Slide 5

Slide 5 text

(DR.) RUBOCOP Rubocop is a Ruby static code analyzer. It runs a set of cops/checks on your codebase.

Slide 6

Slide 6 text

RUBOCOP IN LESS THAN 5 MINUTES (1/3) In your Gemfile: gem 'rubocop', require: false Then just install it: $ bundle install Also integrates with rake and guard.

Slide 7

Slide 7 text

Run the auto-config: $ bundle exec rubocop —auto-gen-config Run `rubocop --config .rubocop_todo.yml`, or add `inherit_from: .rubocop_todo.yml` in a .rubocop.yml file. Create and tweak your own rubocop.yml: require: - rubocop-rspec inherit_from: .rubocop_todo.yml [..] RUBOCOP IN LESS THAN 5 MINUTES (2/3)

Slide 8

Slide 8 text

Run rubocop with auto-correct enabled: $ bundle exec rubocop —auto-correct test/vixie/models/job_test.rb:216:5: W: Useless assignment to variable - job. lib/vixie/tasks/web.rb:22:17: W: Variable Resource used in void context. 52 files inspected, 891 offenses detected, 728 offenses corrected RUBOCOP IN LESS THAN 5 MINUTES (3/3)

Slide 9

Slide 9 text

WORKS WITH YOUR TOOLS Run it in your ci build, or let your favorite editor run it for you.

Slide 10

Slide 10 text

QUESTIONS?

Slide 11

Slide 11 text

Timothée Peignier Running databases so you don’t have to. @cyberdelia