Slide 1

Slide 1 text

The Better RuboCop World to enjoy Ruby 2022/9/10 Yasuko Ohba (@nay3) େ৔ೡࢠ

Slide 2

Slide 2 text

Yasuko Ohba (@nay3) • Started programing in 1987 • Ruby (mostly Rails) user since 2006 • One of founders of Everyleaf Corporation (גࣜձࣾສ༿) in Japan • Recently came back to software development works • A RuboCop user

Slide 3

Slide 3 text

We are hiring! https://www.everyleaf.com/ https://note.com/everyleaf/ ສ༿note

Slide 4

Slide 4 text

In this talk I will talk about the problems that can arise in the development team using RuboCop and how to solve them RuboCopʢͷΑ͏ͳπʔϧʣΛ࢖͏͜ͱͰ
 ։ൃνʔϜʹى͜ΓಘΔ໰୊ͱ
 ͦͷղܾํ๏ʹ͍ͭͯ࿩͠·͢

Slide 5

Slide 5 text

Thanks to RuboCop !! • I like and appreciate RuboCop
 ɹRuboCopʹ͸େม͓ੈ࿩ʹͳ͓ͬͯΓײँ͍ͯ͠·͢ • I don’t intend to criticize RuboCop
 ɹRuboCopΛdisΔҙਤ͸͋Γ·ͤΜ

Slide 6

Slide 6 text

What I want to say Is there anything we can do to make RuboCop 
 (and similar tools) better and safer ?
 
 ΑΓྑ҆͘શʹRuboCopΛར༻Ͱ͖ΔΑ͏ʹɺ
 ͳʹ͔Ͱ͖Δ͜ͱ͸ͳ͍͔ʁ

Slide 7

Slide 7 text

Let me ask you questions 1. Have you used RuboCop ?
 ɹRuboCopΛ࢖ͬͨ͜ͱͷ͋Δํ✋ 2. Do you love RuboCop ?
 ɹRuboCop͕େ޷͖ͳํ✋ 3. Have you felt uncomfortable with RuboCop ?
 ɹRuboCopʹۤखײΛײͨ͜͡ͱͷ͋Δํ✋ 4. Have you written .rubocop.yml by yourself ?
 ɹRuboCopͷઃఆϑΝΠϧʢ.rubocop.ymlʣΛ࡞ΓࠐΜͩ͜ͱͷ͋Δํ✋

Slide 8

Slide 8 text

What is RuboCop ?

Slide 9

Slide 9 text

• It checks your code and extract the problems
 ɹίʔυΛνΣοΫ͠ɺ໰୊఺Λநग़ͯ͘͠Ε·͢ • Also has a function that fi xes problems automatically if possible
 ɹࣗಈͰमਖ਼ͯ͘͠ΕΔػೳ΋͋Γ·͢ https://github.com/rubocop/rubocop

Slide 10

Slide 10 text

Typical usage in teams • Prevent bad code from being committed by pre-commit hook
 ɹpre-commitͰ૸Βͤͯɺ
 ɹҧ൓͕͋Ε͹ίϛοτ͞Εͳ͍Α͏ʹ͢Δ • Prevent bad code from being merged by running RuboCop in CI
 ɹCIͰ૸Βͤͯɺ
 ɹҧ൓͕͋Ε͹Ϛʔδ͞Εͳ͍Α͏ʹ͢Δ

Slide 11

Slide 11 text

In that case • RuboCop is just like a real cop
 ɹܯ׭ͷΑ͏ʹ • It cracks down on codes that don't follow the rules
 ɹϧʔϧʹԊ͍ͬͯͳ͍ίʔυΛݫ͘͠औΓక·Δ

Slide 12

Slide 12 text

A By the way, all pictures in this slide are generated by Midjourny

Slide 13

Slide 13 text

Good point VALUES = [ 'foo'.freeze, 'bar'.freeze ] Style/MutableConstant: Freeze mutable objects assigned to constants Layout/FirstArrayElementIndentation: Indent the right bracket the same as the start of the line where the left bracket is. VALUES = [ 'foo'.freeze, 'bar'.freeze ].freeze Very Useful !!

Slide 14

Slide 14 text

It keeps code clean • Mostly you can automatically correct the code with a single command
 ɹίϚϯυҰൃͰमਖ਼Ͱ͖Δ͜ͱ͕ଟ͍ • Teammates are freed from reviewing trivial mistakes
 ɹࠣࡉͳελΠϧҧ൓ʹ͍ͭͯͷϨϏϡʔ͔Βͷղ์ • Only clean code goes into the main branch
 ɹ͖Ε͍ͳίʔυ͚͕ͩmainϒϥϯνʹೖΔ҆৺ײ

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

A happy end?

Slide 17

Slide 17 text

There is potentially a big risk જࡏతʹ େ͖ͳϦεΫ͕͋Δ

Slide 18

Slide 18 text

Sometimes the rules don't fi t the situation ϧʔϧ͸ ঢ়گʹ߹Θͳ͍͜ͱ΋͋Δ

Slide 19

Slide 19 text

Examples (In my opinion)

Slide 20

Slide 20 text

Example 1 class UsersController < ApplicationController def show end Style/EmptyMethod: Put empty method de fi nitions on a single line. • It's more convenient not to do so in this case
 ɹैΘͳ͍΄͏͕͜ͷ৔߹͸ศར def show; end def show # just render it end

Slide 21

Slide 21 text

Example 2 • Renaming makes it ambiguas in this case
 ɹ໊લΛม͑Δͱ͔͑ͬͯᐆດʹͳΔ class ParentModel < ApplicationRecord def has_child? … Naming/PredicateName: Rename has_child? to child? def child?

Slide 22

Slide 22 text

I can introduce a lot, but that is not the purpose, so not here ͨ͘͞Μ঺հͰ͖ΔΜ͚ͩͲ ͦΕ͕໨తͰ͸ͳ͍ͷͰׂѪ

Slide 23

Slide 23 text

The rules are not "wrong" ϧʔϧ͕ʮؒҧ͍ͬͯΔʯ Θ͚Ͱ͸ͳ͍

Slide 24

Slide 24 text

It's just that sometimes it doesn't fi t the situation ঢ়گʹ߹Θͳ͍͜ͱ͕͋Δͱ͍͏͚ͩ

Slide 25

Slide 25 text

Let’s imagine a development team using RuboCop RuboCopΛ࢖͍ͬͯΔ։ൃνʔϜΛ ࢥ͍ු͔΂͍ͯͩ͘͞

Slide 26

Slide 26 text

Let’s imagine how a junior engineer behaves when RuboCop detects a violation RuboCopͰҧ൓͕ݕग़͞ΕͨΒɺ δϡχΞΤϯδχΞ͸Ͳ͏͢Δ͔ʁ

Slide 27

Slide 27 text

Most junior engineers try to follow the rules (Perhaps, particularly in Japan) େଟ਺ͷδϡχΞΤϯδχΞ͸ ϧʔϧʹै͓͏ͱ͢Δ (΋͔ͨ͠͠Βɺಛʹ೔ຊͰ͸…)

Slide 28

Slide 28 text

This simple act to follow the rules can lead to tragic waste ϧʔϧʹै͓͏ͱ͢Δ͜ͱ͕ ൵ܶతͳແବʹͭͳ͕ΔڪΕ͕͋Δ

Slide 29

Slide 29 text

Common tragedies for beginners ॳ৺ऀ͋Δ͋Δͷ൵ܶ

Slide 30

Slide 30 text

8IZJTUIJTNFUIPE EJWJEFEMJLFUIJT *U`TSFBMMZIBSEUPSFBEGPSNF ͜ͷϝιουɺͲ͏ͯ͜͠͏͍͏;͏ʹ෼͚ͨͷʁ ͍͢͝ಡΈͮΒ͍Μ͚ͩͲ΋ʁ 3VCP$PQTDPMEFENF TP*EJWJEFEUIFNFUIPETPUIBU UIFZDPVMEQBTT 3VCP$PQʹౖΒΕͨͷͰ ௨ΔΑ͏ʹ෼͚·ͨ͠ʂ

Slide 31

Slide 31 text

%JEOUZPVEPXIBU *BEWJTFEZPVUPEP ͋Εɺॿݴͨ͠Α͏ʹ΍Βͳ͔ͬͨͷʁ 3VCP$PQEJEOU BMMPXUIFN BOEXIJMF*XBTEPJOH WBSJPVTUIJOHT *QBTTFEXJUIUIJT 3VCP$PQͰϋϚͬͯ͠·ͬͯɺ͍Ζ͍Ζ΍ͬͯ Δ͏ͪʹɺ͜ΕͰ௨ͬͨͷͰ

Slide 32

Slide 32 text

😫

Slide 33

Slide 33 text

Beginners in the development team are forced to write code under the rules that they cannot judge for themselves ։ൃνʔϜ಺ͷॳ৺ऀ͸ɺ ࣗ෼ͰΑ͋͠͠Λ൑அͰ͖ͳ͍ϧʔϧʹ ੍໿͞Εͳ͕ΒίʔυΛॻ͘͜ͱʹͳΔ

Slide 34

Slide 34 text

Ultimately, for beginners under RuboCop, RuboCop's allowed writing style == Ruby ۃ࿦͢ΔͱɺRuboCopΛ࢖͍ͬͯΔ νʔϜ಺ͷॳ৺ऀʹͱͬͯ͸ɺ RuboCopͰڐ͞Εͨॻ͖ํ == Ruby

Slide 35

Slide 35 text

The Ruby language gives programmers a lot of freedom, but that freedom doesn't always reach beginners when using Ruby via RuboCop Rubyͷ༩͑ͯ͘ΕΔେ͖ͳࣗ༝͸ RuboCopӽ͠ʹRubyΛ࢖͏ͱ͖ ඞͣ͠΋ॳ৺ऀʹ͸ಧ͔ͳ͍

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

“You can quickly write whatever you want with Ruby” ʮRubyΛ࢖͑͹ԿͰ΋ ࢥ͍௨Γʹαοͱॻ͚Δʯ

Slide 38

Slide 38 text

I think we should question “Is it still true for beginners under RuboCop?” ʮRuboCopΛ࢖ͬͯRubyΛॻ͍͍ͯΔॳ৺ऀ ʹ΋ͦ͏ࢥͬͯ΋Β͑Δ͔Ͳ͏͔ʯ ͱ͍͏໰͍͔͚Λͨ͠΄͏͕͍͍ͷͰ͸ͳ͍͔

Slide 39

Slide 39 text

Under RuboCop, unskilled people might be trapped while skilled people are enjoying Ruby freely εΩϧͷ͋Δਓ͸ RuboCopΛ࢖͍ͬͯͯ΋ RubyΛࣗ༝ʹָ͠ΊΔ͕ɺ εΩϧͷͳ͍ਓ͸RuboCopʹڧ੍͘໿͞ΕΔ

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

Even for more skilled engineers, there are some concerns ΋ͬͱεΩϧ͕͋Δ૚ʹͱͬͯ΋ɺ ͍͔ͭ͘ͷݒ೦͕͋Δ

Slide 42

Slide 42 text

It's annoying to have a rule that doesn't fi t your situation and get stuck frequently ঢ়گʹ߹Θͳ͍ϧʔϧʹ සൟʹҾ͔͔ͬΔͷ͸൥Θ͍͠

Slide 43

Slide 43 text

It slows down development ։ൃ଎౓Λ௿Լͤ͞Δ

Slide 44

Slide 44 text

Even after deciding that the rules don't fi t the situation, something needs to be done ϧʔϧ͕ঢ়گʹ߹Θͳ͍ͱ ൑அͰ͖ͨ৔߹Ͱ΋ɺ ͳʹ͔ͷରॲ͕ඞཁʹͳΔ

Slide 45

Slide 45 text

Strategies 1. Change the rule for the project
 ɹϓϩδΣΫτશମͷϧʔϧΛม͑Δ 2. Change the rule in that code
 ɹͦͷίʔυͰ͸ϧʔϧΛม͑Δ 3. Just follow the rule
 ɹͱΓ·ɺϧʔϧʹै͓ͬͯ͘

Slide 46

Slide 46 text

Few engineers can take Strategy 1 ઓུ1ΛͱΕΔΤϯδχΞ͸ গ਺ʹײ͡ΒΕΔ 1. Change the rule for the project 
 ɹϓϩδΣΫτશମͷϧʔϧΛม͑Δ

Slide 47

Slide 47 text

Dif fi culty of Strategy 1 • “I can't tell if that's the case in other situations as well.”
 ɹʮ΄͔ͷέʔεͰ΋ঢ়گʹ߹Θͳ͍͔·Ͱ͸
 ɹ൑அͰ͖ͳ͍ʯ • “It's hard to convince the whole team”
 ɹʮνʔϜશһΛઆಘ͢Δͷ͸େมͦ͏ͩʯ 1. Change the rule for the project 
 ɹϓϩδΣΫτશମͷϧʔϧΛม͑Δ

Slide 48

Slide 48 text

Taking easier strategies • This may not solve the problem conclusively
 ɹ໰୊ͷ࠷ऴղܾʹͭͳ͕Βͣɺ
 ɹ·ͨ͜ͷίετΛ෷͏ඞཁ͕ൃੜ͢Δ͔΋͠Εͳ͍ 2. Change the rule in that code
 ɹͦͷίʔυͰ͸ϧʔϧΛม͑Δ 3. Just follow the rule
 ɹͱΓ·ɺϧʔϧʹै͓ͬͯ͘

Slide 49

Slide 49 text

In short "Rules that do not fi t the situation” create disadvantages ʮঢ়گʹ߹Θͳ͍ϧʔϧʯ͸ σϝϦοτΛੜΈग़͢

Slide 50

Slide 50 text

Disadvantages • Decrease in development speed and productivity
 ɹ։ൃ଎౓ɾੜ࢈ੑͷ௿Լ • Code might get worse to avoid violation
 ɹRuboCopͷҧ൓Λආ͚ΔͨΊʹ
 ɹίʔυ͕վѱ͞ΕΔϦεΫ

Slide 51

Slide 51 text

Then what should we do? Ͱ͸Ͳ͏͢Δ͔ʁ

Slide 52

Slide 52 text

Why don't you just set it up to fi t the situation? ঢ়گʹ߹͏Α͏ʹઃఆͨ͠Β ͍͍Μ͡ΌΜʁ

Slide 53

Slide 53 text

RuboCop is fl exible (1) All rules can be disabled or customized from the default ͢΂ͯͷϧʔϧ͸ɺແޮʹͨ͠ΓɺσϑΥϧτͱ͸ҟͳΔ ํ਑ʹมߋ͢Δ͜ͱ͕Ͱ͖·͢

Slide 54

Slide 54 text

RuboCop is fl exible (2) • You can ignore certain rules in a certain code
 ಛఆͷίʔυͰಛఆͷϧʔϧΛແࢹ͢Δ͜ͱΛ
 એݴͰ͖·͢

Slide 55

Slide 55 text

RuboCop’s Philosophy “Whatever style preferences you have RuboCop is there for you. That's our promises and our guarantee.” https://docs.rubocop.org/rubocop/index.html#philosophy

Slide 56

Slide 56 text

"Style Guide" • Ruby is a dynamic language
 Ruby͸ಈతͳݴޠ • The good thing about Ruby is that you can write in the best way for your situation
 ঢ়گʹ͋Θͤͯ࠷దͳॻ͖ํ͕Ͱ͖Δͷ͕Rubyͷ͍͍ͱ͜Ζ • In my opinion, the style guide in “Ruby Way” should be dynamic
 RubyͬΆ͍ελΠϧΨΠυ͸ɺಈతͳͷͰ͸ͳ͍͔ʁ

Slide 57

Slide 57 text

Well, you have the right not to use RuboCop I want to use RuboCop because it is useful, and it is already kind of standard
 RuboCop͸ศརͳͷͰ࢖͍͍ͨ͠ɺ΋͸΍ඪ४త

Slide 58

Slide 58 text

We need to harmonize good old Ruby and RuboCop ݹ͖Α͖RubyͱRuboCopͷ ௐ࿨ΛਤΔඞཁ͕͋Δ

Slide 59

Slide 59 text

Point is • The need to use RuboCop is growing
 ɹRuboCopΛ࢖͏ඞཁੑ͸ڧ͘ͳ͍ͬͯΔ • My concern is not about “(static) style guide preferences"
 ʮͲͷ(੩తͳ) Style GuideΛ޷Ή͔ʯͰ͸ࡁ·ͳ͍࿩ͩͱࢥ͍ͬͯΔ • People may be forced to follow rules that do not fi t their situation
 ɹঢ়گʹ߹Θͳ͍ϧʔϧΛڧ੍͞ΕΔϦεΫ͕͋Δ • Con fi guration fl exibility is not enough to avoid the risk
 ɹઃఆͷॊೈ͚ͩ͞Ͱ͸ͦͷϦεΫΛճආͰ͖ͳ͍

Slide 60

Slide 60 text

Con fi guration fl exibility is not enough to avoid the risk ઃఆͷॊೈ͚ͩ͞Ͱ͸ͦͷϦεΫΛճආͰ͖ͳ͍

Slide 61

Slide 61 text

Why not enough ?

Slide 62

Slide 62 text

Technical ability

Slide 63

Slide 63 text

You need to judge the validity of the rule in order to set up ͏·͘ઃఆ͢ΔͨΊʹ͸ ϧʔϧͷଥ౰ੑΛ൑அͰ͖Δඞཁ͕͋Δ

Slide 64

Slide 64 text

You need to think about whether problems will occur in all the code written in the future, not on the correctness at fi rst glance Ұݟͯ͠ͷਖ਼͠͞Ͱ͸ͳ͘ɺ
 ະདྷʹॻ͔ΕΔίʔυ΋ؚΊͯ
 ໰୊͕ى͖ͳ͍͔ߟ͑Δඞཁ͕͋Δ

Slide 65

Slide 65 text

You need technical ability and experience to judge the validity looking to the future কདྷΛݟ௨ͯ͠ ͋Δϧʔϧ͕Ͳͷ͘Β͍ద੾͔Λ ൑அ͢Δʹ͸ٕज़ྗͱܦݧ͕ඞཁ

Slide 66

Slide 66 text

Even the RuboCop team would not be able to foresee the future needs of every project in the world RuboCopνʔϜ΋ ͋ΒΏΔνʔϜͷະདྷͷχʔζΛ ༧૝͸Ͱ͖ͳ͍

Slide 67

Slide 67 text

So what do we do? Ͱ͸ɺͲ͏͢Δʁ

Slide 68

Slide 68 text

The surest way to avoid such disadvantages is to con fi gure the rules well for your team by yourself ໰୊Λ๷͙΋ͬͱ΋࣮֬ͳํ๏͸ɺ ࣗ෼ͨͪͷͨΊͷϧʔϧΛ ࣗ෼ࣗ਎Ͱ͏·͘ઃఆ͢Δ͜ͱ

Slide 69

Slide 69 text

In my case • I’ve created a rule template of the baseline for our company
 ɹࣗࣾ޲͚ͷϕʔεϥΠϯͷϧʔϧͷ਽ܗΛ࡞ͬͨ • WIP

Slide 70

Slide 70 text

Disadvantages are gone !! ܶతϏϑΥʔΞϑλʔ !! ֨ஈʹ࢖͍΍͘͢ͳͬͨ

Slide 71

Slide 71 text

I would like to introduce the details of that work, but I don't have time today ϧʔϧͮ͘Γͷৄࡉʹ͍ͭͯ΋͓࿩͍ͨ͠ Ͱ͕͢ࠓ೔͸͕࣌ؒͳͦ͞͏

Slide 72

Slide 72 text

Just a bit ͪΐͬͱ͚ͩ

Slide 73

Slide 73 text

Main evaluation viewpoints ओͳධՁ؍఺ 1. Risk that code will get worse
 ɹίʔυ͕վѱ͞ΕΔϦεΫ 2. Avoid opposite values
 ɹਅٯͷՁ஋؍ 3. Protect freedom of expression
 ɹදݱͷࣗ༝ΛकΔ 4. Don't discourage DSL
 ɹDSLԽʹྫྷਫΛ͔͚ͳ͍ I will write the rest part in our ‘ສ༿note' ଓ͖͸ສ༿noteʹͰ΋ ॻ͍͍͖͍ͯͨͱࢥ͍·͢

Slide 74

Slide 74 text

You can get our settings here;
 https://github.com/everyleaf/el-training/tree/master/rubocop
 
 ɹઃఆྫ͸ɺສ༿ͷ
 ɹ৽ೖࣾһڭҭ༻ΧϦΩϡϥϜ͔ΒऔಘͰ͖·͢

Slide 75

Slide 75 text

A Happy End ?

Slide 76

Slide 76 text

It’s too hard !! • Imagine if there is a right reason to want to break the rule
 ɹϧʔϧʹҧ൓͍ͨ͠ਖ਼౰ͳཧ༝Λ૝૾ • Consider the frequency of that cases
 ɹҧ൓ͨ͘͠ͳΔέʔεͷස౓Λݕ౼ • Compare the advantages and disadvantages of adopting the rule
 ɹϧʔϧΛద༻͢ΔϝϦοτͱσϝϦοτΛൺֱ • Continue to make judgments as new rules coming
 ɹࠓޙ΋৽͍͠ϧʔϧ͕௥Ճ͞ΕΔͨͼʹܧଓతʹબผ࡞ۀ

Slide 77

Slide 77 text

Not everyone can do this ΈΜͳ͕͜ΕΛ ΍Δͷ͸ແཧͩͱࢥ͏

Slide 78

Slide 78 text

I really didn't want to do this ࢲ΋ຊ౰͸΍Γͨ͘ͳ͔ͬͨ ΍Βͳ͍ͰࡁΉ΄͏͕خ͍͠

Slide 79

Slide 79 text

Some teams don't have skilled people ख़࿅ऀͷ͍ͳ͍νʔϜͩͬͯ͋Δ

Slide 80

Slide 80 text

Where is this suffering coming from? ͜ͷۤ͠Έ͸ Ͳ͔͜Βདྷ͍ͯΔʁ

Slide 81

Slide 81 text

RuboCop seems to take the view that there is a concept of 'style' on the surface of the code, and it can be statically determined to be correct or not RuboCop͸ɺίʔυͷද૚ʹελΠϧͱ͍͏֓೦͕ ͋ΓɺԿ͕ྑ͍ελΠϧ͔͸ৗʹ੩తʹܾΊΒΕΔͱ ͍͏෺ͷݟํΛ͍ͯ͠ΔΑ͏ʹײ͡Δ

Slide 82

Slide 82 text

Part of this view fi ts to Ruby, and part does not ͜ͷ෺ͷݟํ͸ Rubyʹ౰ͯ͸·Δ෦෼ͱ ౰ͯ͸·Βͳ͍෦෼͕͋Δ

Slide 83

Slide 83 text

For example, how about DSLs ?

Slide 84

Slide 84 text

Poem The code expression that RuboCop treats as style is sometimes not the style but the heart RuboCop͕ελΠϧͱͯ͠ ѻ͍ͬͯΔίʔυ্ͷදݱ͸ɺ ࣌ʹɺελΠϧͰ͸ͳ͘৺Ͱ͋Δ

Slide 85

Slide 85 text

Values that RuboCop expects to be static can be changed fl exibly depending on the situation RuboCop͕੩తʹܾΊΒΕΔ ૝ఆͱ͍ͯ͠ΔʮՁ஋؍ʯ͸ɺ ঢ়گ࣍ୈͰॊೈʹมΘΔ΋ͷ

Slide 86

Slide 86 text

Each style (rule) has a different ‘ fi rmness’ ϧʔϧʢελΠϧʣͷ’ݻ͞’ͷ౓߹͍͸ͦΕͧΕҟͳΔ

Slide 87

Slide 87 text

3VMF" 3VMF# 3VMF$ 3VMF$ 3VMF# "MMQPTTJCMFTJUVBUJPOT ͋Γ͑Δ͢΂ͯͷঢ়گ 3VMF" 4JUVBUJPO$PWFSBHFT %BNBHFDBVTFECZ SVMFTUIBUEPOPU fi UUIFTJUVBUJPO ‘Firm’

Slide 88

Slide 88 text

We have a dilemma here δϨϯϚ͕͋Δ

Slide 89

Slide 89 text

The more willingly you detect points that could be improved, the more "rules that don't fi t the situation" you get վળͰ͖Δ͔΋͠Εͳ͍ϙΠϯτΛ ҙཉతʹݕग़͢Δ΄Ͳ ʮঢ়گʹ߹Θͳ͍ϧʔϧʯ͕ଟ͘ͳΔ

Slide 90

Slide 90 text

The solution of this dilemma is left to your .rubocop.yml ͜ͷδϨϯϚͷղܾ͕ ͦΕͧΕͷ .rubocop.yml ʹ ҕͶΒΕ͍ͯΔ

Slide 91

Slide 91 text

Powerful, but painful

Slide 92

Slide 92 text

Painful things 1. Hardness to tune .rubocop.yml
 ɹઃఆ͕େม 2. Suffering from the "rules that do not match the situation" without tuning
 ɹઃఆ͠ͳ͚Ε͹ʮঢ়گʹ߹Θͳ͍ϧʔϧʯ໰୊͕ൃੜ 3. Reducing damages also reduces the opportunities
 ɹڧ੍ʹΑΔμϝʔδΛ࠷খԽ͢Δͱɺ
 ɹίʔυվળͷػձ΋ݮͬͯ͠·͏

Slide 93

Slide 93 text

Is there any way to solve this?

Slide 94

Slide 94 text

My proposal

Slide 95

Slide 95 text

Let's divide the usage of RuboCop into two levels 
 RuboCopͷ࢖͍ํΛ ̎ͭͷܥ౷ʹ෼͚ͨΒྑͦ͞͏ʁ 1. Enforcement Levelɹڧ੍Ϩϕϧ 2. Information LevelɹࢀߟϨϕϧ

Slide 96

Slide 96 text

2 con fi g fi les • .rubocop-e.yml - for Enforcement Level • .rubocop-i.yml - for Information Level
 
 ※names are examples
 ɹɹ໊લ͸ҰྫͰ͢

Slide 97

Slide 97 text

.rubocop-e.yml Include rules that can be enforced in almost all situations
 
 ɹڧ੍ͯ͠΋ɺ΄΅100%ͷঢ়گͰ
 ɹ໰୊͕ͳ͍Α͏ͳϧʔϧΛೖΕΔ

Slide 98

Slide 98 text

.rubocop-i.yml Include ideal rules
 
 ɹͳΔ΂͘ଟ͘ͷվળϙΠϯτʹؾ͚ͮΔΑ͏ʹ
 ɹཧ૝తͳϧʔϧΛೖΕΔ

Slide 99

Slide 99 text

How to use Enforcement Level ڧ੍Ϩϕϧͷ࢖͍ํ Guard your code base by using pre-commit hook or CI
 ɹ
 ɹݱঢ়Ͳ͓ΓɺCIͳͲͰΨʔυ͢Δ

Slide 100

Slide 100 text

How to use Information Level ࢀߟϨϕϧͷ࢖͍ํ • Regularly run in CI etc
 ɹCIͳͲͰఆظ࣮ߦ • Informative level violations should be labeled as "informative" not “violations"
 ɹࢀߟϨϕϧͰͷҧ൓͸
 ɹʮҧ൓ʯͰ͸ͳ͘ʮࢀߟ৘ใʯͱͯ͠දࣔ͢Δ

Slide 101

Slide 101 text

Otherwise we'll fall into the trap of "rules that don't fi t the situation" ʮҧ൓ʯͱͯ͠ݟ͑Δͱ ʮঢ়گʹ߹Θͳ͍ϧʔϧʯͷ᠘ʹ ϋϚͬͯ͠·͏

Slide 102

Slide 102 text

How does this solve the problem? ͜Ε͕໰୊ΛͲ͏ղܾ͢Δͷ͔ʁ

Slide 103

Slide 103 text

Painful things 1. Hardness to tune .rubocop.yml
 ɹઃఆ͕େม 2. Suffering from the "rules that do not match the situation" without tuning
 ɹઃఆ͠ͳ͚Ε͹ʮঢ়گʹ߹Θͳ͍ϧʔϧʯ໰୊͕ൃੜ 3. Reducing damages also reduces the opportunities
 ɹڧ੍ʹΑΔμϝʔδΛ࠷খԽ͢Δͱɺ
 ɹίʔυվળͷػձ΋ݮͬͯ͠·͏

Slide 104

Slide 104 text

• The reason why it is dif fi cult to use other people's settings is that there are a wide range of options for how to compromise ideals and reality.
 ɹଞਓͷઃఆͷ׆༻͕೉͍͠ҰҼ͸ɺ
 ɹཧ૝ͱݱ࣮ͷંΓ߹͍ͷ෇͚ํ͕෯޿͍͔Β • Splitting the levels into lower and upper limits increases the chances of a match
 ɹൣғͷ্ݶɾԼݶΛ෼͚Ε͹ɺҰக͠΍͘͢ͳΔ • Easier and safer to borrow
 ɹ҆৺ͯ͠ഈआͰ͖Δ 1.Hardness to tune .rubocop.yml
 ɹઃఆ͕େม

Slide 105

Slide 105 text

Maybe we can create typical enforcing level setting examples
 for each use case
 (For Rails, for Matz, etc) ༻్ผͷڧ੍Ϩϕϧͷ ઃఆྫΛ࡞ΕΔͱࢥ͏
 ʢRails޲͚ͱ͔ɺMatz޲͚ͱ͔ʣ

Slide 106

Slide 106 text

If a good "enforcement level setting" can be obtained at a low cost, it will be solved
 
 ྑ͍ʮڧ੍Ϩϕϧͷઃఆʯ͕௿ίετͰೖखͰ͖Ε͹ɺ
 ղܾʂʂʂ 2. Suffering from the "rules that do not match the situation" without tuning
 ɹઃఆ͠ͳ͚Ε͹ʮঢ়گʹ߹Θͳ͍ϧʔϧʯ໰୊͕ൃੜ

Slide 107

Slide 107 text

It makes you feel much less guilty to think “the rule is for reference” than “the violation won't have to be fi xed” ʮͦͷϧʔϧ͸ࢀߟ༻ʹ͠Α͏ʯͷ΄͏͕
 ʮҧ൓Λ௚͞ͳ͍͍ͯ͘͜ͱʹ͠Α͏ʯΑΓ
 ͣͬͱࡑѱײ͕গͳ͍

Slide 108

Slide 108 text

This leads to creating a culture 
 that can counteract 
 the "rules that don't fi t the situation" trap ʮঢ়گʹ߹Θͳ͍ϧʔϧʯͷ᠘ʹ ର߅Ͱ͖ΔจԽΛ࡞Δ͜ͱ͕Ͱ͖Δ

Slide 109

Slide 109 text

We can have a nice information level
 code improvement suggestion system ࢀߟϨϕϧͷνΣοΫʹجͮ͘
 ૉఢͳίʔυվળఏҊγεςϜΛ
 ར༻Ͱ͖Δͱ͍͍ͳ…ʢເʣ 3. Reducing damages also reduces the opportunities
 ɹڧ੍ʹΑΔμϝʔδΛ࠷খԽ͢Δͱɺ
 ɹίʔυվળͷػձ΋ݮͬͯ͠·͏

Slide 110

Slide 110 text

There is a gradation in the validity ( fi rmness) of rules ϧʔϧͷଥ౰ੑʢݻ͞ʣʹ͸άϥσʔγϣϯ͕͋Δ Fits 100% Fits 80%
 ɹex. Not suitable if expressibility is 
 more important than consistency for you Fits 90%
 ɹex. Not suitable for DSLs Unstable Firm rules

Slide 111

Slide 111 text

Let's stop dividing the indivisible ! ෼͚ΒΕͳ͍΋ͷΛ෼͚ΔͷΛ΍ΊΑ͏ (00% #"% Our only one standard

Slide 112

Slide 112 text

Make it easier to handle areas that cannot be determined by 0/1 0/1Ͱ൑ఆͰ͖ͳ͍ྖҬΛѻ͍΍͘͢ (00% #"% .":#&(00% )VNBOTDBOBMTPSFWJFXBOEKVEHF Enforcement Information

Slide 113

Slide 113 text

Epilogue

Slide 114

Slide 114 text

One Saturday morning,
 I was working on .rubocop.yml for our company ͋Δ౔༵೔ͷேɺ
 ձࣾͷRuboCopઃఆͮ͘ΓΛ
 ͍ͯ͠·ͨ͠

Slide 115

Slide 115 text

I've been thinking about the things I talked about today, 
 and I thought about it again that morning
 
 ࠓ೔࿩ͨ͜͠ͱ͸ Ҏલ͔ΒԿճ͔ࢥ͍ͬͯ·͕ͨ͠ɺ ͜ͷ೔ͷே΋ߟ͑·ͨ͠

Slide 116

Slide 116 text

Is there anything I can doʁ

Slide 117

Slide 117 text

Then I realized that day was the CFP deadline for ͪΐ͏Ͳͦͷ೔͕ɺCFPకΊ੾Γͷ೔ͩͬͨ

Slide 118

Slide 118 text

I felt like I could talk, that’s why I am here

Slide 119

Slide 119 text

I would be happy if it helps to realize a better RuboCop World ࠓ೔ͷτʔΫ͕ ΑΓྑ͍ RuboCop World ͷ ࣮ݱʹ໾ཱͬͨΒخ͍͠Ͱ͢

Slide 120

Slide 120 text

Thank you very much !! And, special thanks to Koichiro Ohba (@koichiroo)