rubocop
TRANSCRIPT
RuboCop:Automatic code style checking For Ruby
Andrew GrimmTerem TechnologiesRuby or Rails OceaniaNovember 2015
RuboCop
❖ Analysis tool for Ruby code❖ Inspired by the Ruby Style Guide❖ Detects instances of bad style and reports them
Worked example
Types of Cops
❖ Style❖ Lint❖ Metrics❖ Rails
Style Cops❖ Detect code that works, but doesn’t meet a
consistent style
Lint❖ Detects code that doesn’t make sense, and is
probably wrong
Metrics❖ Detects too much of a bad thing (long lines, long
methods, long classes)
Rails❖ Makes sure you’re doing things the Rails
Way(tm)
Configurability
❖ Tastes differ, and so can your RuboCop configuration
Totally Disabling
Choosing a different style❖ For example, choosing snake_case or camelCase
for method names
Values for metrics cops❖ For example, configuring the maximum number
of lines in a method
Applying RuboCop to Legacy Existing Projects
--auto-correct
❖ Automatically correct offenses
--auto-gen-config
❖ Creates a configuration file that allows existing offenses called .rubocop_todo.yml
❖ Ordinary YAML - easily edited
Third party code
❖ If code is automatically generated, and you’re not going to edit it, leave it well alone
❖ db/migrate/, vendor/❖ Ignore it by configuring RuboCop to exclude the
files from its analysis
Questions?
❖ RuboCop: https://github.com/bbatsov/rubocop ❖ RuboCop integration (editors, guard, rake):
https://github.com/bbatsov/rubocop#editor-integration