(mostly Rails) user since 2006 • One of founders of Everyleaf Corporation (גࣜձࣾສ༿) in Japan • Recently came back to software development works • A RuboCop user
? ɹ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ʣΛ࡞ΓࠐΜͩ͜ͱͷ͋Δํ✋
committed by pre-commit hook ɹpre-commitͰΒͤͯɺ ɹҧ͕͋Είϛοτ͞Εͳ͍Α͏ʹ͢Δ • Prevent bad code from being merged by running RuboCop in CI ɹCIͰΒͤͯɺ ɹҧ͕͋ΕϚʔδ͞Εͳ͍Α͏ʹ͢Δ
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 !!
the code with a single command ɹίϚϯυҰൃͰमਖ਼Ͱ͖Δ͜ͱ͕ଟ͍ • Teammates are freed from reviewing trivial mistakes ɹࠣࡉͳελΠϧҧʹ͍ͭͯͷϨϏϡʔ͔Βͷղ์ • Only clean code goes into the main branch ɹ͖Ε͍ͳίʔυ͚͕ͩmainϒϥϯνʹೖΔ҆৺ײ
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
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 ɹϓϩδΣΫτશମͷϧʔϧΛม͑Δ
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ͬΆ͍ελΠϧΨΠυɺಈతͳͷͰͳ͍͔ʁ
ɹ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 ɹઃఆͷॊೈ͚ͩ͞ͰͦͷϦεΫΛճආͰ͖ͳ͍
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ʹͰ ॻ͍͍͖͍ͯͨͱࢥ͍·͢
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 ɹࠓޙ৽͍͠ϧʔϧ͕Ճ͞ΕΔͨͼʹܧଓతʹબผ࡞ۀ
concept of 'style' on the surface of the code, and it can be statically determined to be correct or not RuboCopɺίʔυͷදʹελΠϧͱ͍͏֓೦͕ ͋ΓɺԿ͕ྑ͍ελΠϧ͔ৗʹ੩తʹܾΊΒΕΔͱ ͍͏ͷݟํΛ͍ͯ͠ΔΑ͏ʹײ͡Δ
from the "rules that do not match the situation" without tuning ɹઃఆ͠ͳ͚Εʮঢ়گʹ߹Θͳ͍ϧʔϧʯ͕ൃੜ 3. Reducing damages also reduces the opportunities ɹڧ੍ʹΑΔμϝʔδΛ࠷খԽ͢Δͱɺ ɹίʔυվળͷػձݮͬͯ͠·͏
from the "rules that do not match the situation" without tuning ɹઃఆ͠ͳ͚Εʮঢ়گʹ߹Θͳ͍ϧʔϧʯ͕ൃੜ 3. Reducing damages also reduces the opportunities ɹڧ੍ʹΑΔμϝʔδΛ࠷খԽ͢Δͱɺ ɹίʔυվળͷػձݮͬͯ͠·͏
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 ɹઃఆ͕େม
a low cost, it will be solved ྑ͍ʮڧ੍Ϩϕϧͷઃఆʯ͕ίετͰೖखͰ͖Εɺ ղܾʂʂʂ 2. Suffering from the "rules that do not match the situation" without tuning ɹઃఆ͠ͳ͚Εʮঢ়گʹ߹Θͳ͍ϧʔϧʯ͕ൃੜ
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