rubocop

17
RuboCop: Automatic code style checking For Ruby Andrew Grimm Terem Technologies Ruby or Rails Oceania November 2015

Upload: andrew-grimm

Post on 13-Apr-2017

244 views

Category:

Software


1 download

TRANSCRIPT

Page 1: RuboCop

RuboCop:Automatic code style checking For Ruby

Andrew GrimmTerem TechnologiesRuby or Rails OceaniaNovember 2015

Page 2: RuboCop

RuboCop

❖ Analysis tool for Ruby code❖ Inspired by the Ruby Style Guide❖ Detects instances of bad style and reports them

Page 3: RuboCop

Worked example

Page 4: RuboCop

Types of Cops

❖ Style❖ Lint❖ Metrics❖ Rails

Page 5: RuboCop

Style Cops❖ Detect code that works, but doesn’t meet a

consistent style

Page 6: RuboCop

Lint❖ Detects code that doesn’t make sense, and is

probably wrong

Page 7: RuboCop

Metrics❖ Detects too much of a bad thing (long lines, long

methods, long classes)

Page 8: RuboCop

Rails❖ Makes sure you’re doing things the Rails

Way(tm)

Page 9: RuboCop

Configurability

❖ Tastes differ, and so can your RuboCop configuration

Page 10: RuboCop

Totally Disabling

Page 11: RuboCop

Choosing a different style❖ For example, choosing snake_case or camelCase

for method names

Page 12: RuboCop

Values for metrics cops❖ For example, configuring the maximum number

of lines in a method

Page 13: RuboCop

Applying RuboCop to Legacy Existing Projects

Page 14: RuboCop

--auto-correct

❖ Automatically correct offenses

Page 15: RuboCop

--auto-gen-config

❖ Creates a configuration file that allows existing offenses called .rubocop_todo.yml

❖ Ordinary YAML - easily edited

Page 16: RuboCop

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

Page 17: RuboCop

Questions?

❖ RuboCop: https://github.com/bbatsov/rubocop ❖ RuboCop integration (editors, guard, rake):

https://github.com/bbatsov/rubocop#editor-integration