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. DR. RUBOCOP
    Or: How I Learned to
    Stop Worrying and
    Love the Codebase

    View Slide

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

    View Slide

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

    View Slide

  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?

    View Slide

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

    View Slide

  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.

    View Slide

  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)

    View Slide

  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)

    View Slide

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

    View Slide

  10. QUESTIONS?

    View Slide

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

    View Slide