Dr. Rubocop

Dr. Rubocop

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

5a810a7779b19a5ac9e6cffa8531eee6?s=128

Timothée Peignier

December 01, 2016
Tweet

Transcript

  1. DR. RUBOCOP Or: How I Learned to Stop Worrying and

    Love the Codebase
  2. DIFFERENT CODEBASES 100000 lines 8 years old 155 contributors 2000

    lines 1 year old 6 contributors
  3. HOW TO GUARANTEE UNIFORMITY? Or just avoiding some ruby pitfalls

    and repeating the same mistakes
  4. 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?
  5. (DR.) RUBOCOP Rubocop is a Ruby static code analyzer. It

    runs a set of cops/checks on your codebase.
  6. 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.
  7. 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)
  8. 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)
  9. WORKS WITH YOUR TOOLS Run it in your ci build,

    or let your favorite editor run it for you.
  10. QUESTIONS?

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