Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dr. Rubocop

Dr. Rubocop

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

Timothée Peignier

December 01, 2016
Tweet

More Decks by Timothée Peignier

Other Decks in Programming

Transcript

  1. 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?
  2. (DR.) RUBOCOP Rubocop is a Ruby static code analyzer. It

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

    or let your favorite editor run it for you.