Slide 1

Slide 1 text

'SJ Improve Ruby coding style rules and Lint ,PJDIJ*50FTN 3VCZ,BJHJ 4FOEBJ*OUFSOBUJPOBM$FOUFS)BHJ How do you join social coding?

Slide 2

Slide 2 text

!LPJD

Slide 3

Slide 3 text

QPTJUJPOUBML

Slide 4

Slide 4 text

:PVNBZLOPX BGBNPVTMBSHF 044DPNNVOJUZ

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

*U`TNF

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

w*NQSPWFUFTUDPWFSBHFGPS0SBDMF FOIBODFEBEBQUFS w*OUSPEVDF'SP[FO4USJOH-JUFSBMT w4VQQSFTTXBSOJOHTXJUI&EHF3VCZ w*NQPSUFYQPSU3VCP$PQ DPOpHVSBUJPOT w/JUQJDLTBOETPPO .ZXPSLTJO3BJMT

Slide 10

Slide 10 text

3BJMTDPNNVOJUZ JTPOFPGIPNF JONZIFBSU

Slide 11

Slide 11 text

*PGUFOIBWFBDUJWJUJFT JO3VCP$PQSFDFOUMZ

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

w'JYCVHT w$SFBUFOFXDPQT w*NQSPWFEPDVNFOUT w*NQSPWFJOUFSOBMBGGBJST w.BJOUFOBODF$*DPOEJUJPOT .ZXPSLTJO3VCP$PQ

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

FTN

Slide 17

Slide 17 text

w%JSFDUJPOPGB3BJMTBQQQSPKFDU w6QHSBEJOH3VCZ3BJMTGPSBQQT BOETVSSPVOEJOHHFNT w0SHBOJ[F3BJMT044QBUDI NFFUVQTJOFTN w3FDSVJUJOHJOUFSWJFXFS .ZXPSLTJOFTN

Slide 18

Slide 18 text

"TUPSZBGUFSZFBST GSPNBNFNPSJBM QSFTFOUBUJPOJO 5PEBZ`TUBML

Slide 19

Slide 19 text

8IBUIBQQFOFE JO

Slide 20

Slide 20 text

IUUQKQSVCZJTUOFU3VCZ,BJHJ DQMVHJOQMVHJOBUUBDI@EPXOMPBEQ1SPHSBNpMF@OBNFUIF@JTMBOE@PG@SVCZ@KQEG 3VCZ,BJHJ %BWF5IPNBT

Slide 21

Slide 21 text

w7BSJPVTDPNQBOJFTVTJOH3VCZ 3BJMTGPSEFWFMPQNFOUBQQFBSFE w(JU)VCIBTBQQFBSFE BOE JOEJWJEVBMBDUJWJUJFTBSFESBXJOH BUUFOUJPO w3VCZJTUTBOE3VCZJTIDPNQBOJFT NBLFWBSJPVT3VCZDPEJOHTUZMFT .PEFSOUJNFT

Slide 22

Slide 22 text

5IFSFBSFWBSJPVT 3VCZDPEJOHTUZMFT %JWFSTJUZ

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

"3VCZDPEF def badName if something test end end

Slide 25

Slide 25 text

3VOXJUIUIFEFGBVMU 3VCP$PQTFUUJOH

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

%FQBSU/BNF$PQ/BNF%FTDSJQUJPO

Slide 28

Slide 28 text

3VCP$PQIBTTFWFSBM EFQBSUNFOUT

Slide 29

Slide 29 text

0GpDJBMNBOVBM

Slide 30

Slide 30 text

)FSF

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

-BZPVU%FQBSUNFOU "MJHO"SSBZ .FUBQIFS "MJHO)BTI &MTF"MJHONFOU &NQUZ-JOFT &OE"MJHONFOU &YUSB4QBDJOH *OEFOU"SSBZ -JOU%FQBSUNFOU %VQMJDBUF.FUIPET %VQMJDBUFE,FZ &MTF"MJHONFOU 4DSJQU1FSNJTTJPO 6OJpFE*OUFHFS 6OSFBDIBCMF$PEF 6OMFTT"TTJHONFOU .FUSJDT%FQBSUNFOU "CD4J[F #MPDL-FOHUI #MPDL/FTUJOH $MBTT-FOHUI -JOF-FOHUI .FUIPE-FOHUI 1BSBNFUFS-JTUT ʜ

Slide 33

Slide 33 text

%FQBSU/BNF$PQ/BNF%FTDSJQUJPO

Slide 34

Slide 34 text

3VCP$PQIBTNBOZlCVJMUJODPQTz BOElDVTUPNDPQTzZPVDBOBEECZVTJOH QMVHHBCMFNFDIBOJTN

Slide 35

Slide 35 text

/FXDPQ NBEFCZNF

Slide 36

Slide 36 text

$SFBUJPODPQDPVOU QXE 6TFSTLPJDTSDHJUIVCDPNSVCPDPQIRSVCPDPQ DBU$)"/(&-0(NEcHSFQLPJDcHSFQJBEEOFXcXDM

Slide 37

Slide 37 text

$SFBUJPODPQDPVOU QXE 6TFSTLPJDTSDHJUIVCDPNSVCPDPQIRSVCPDPQ DBU$)"/(&-0(NEcHSFQLPJDcHSFQJBEEOFXcXDM

Slide 38

Slide 38 text

$SFBUJPODPQDPVOU QXE 6TFSTLPJDTSDHJUIVCDPNSVCPDPQIRSVCPDPQ DBU$)"/(&-0(NEcHSFQLPJDcHSFQJBEEOFXcXDM DBU$)"/(&-0(NEcHSFQQPDLFcHSFQJBEEOFXcXDM

Slide 39

Slide 39 text

$SFBUJPODPQDPVOU QXE 6TFSTLPJDTSDHJUIVCDPNSVCPDPQIRSVCPDPQ DBU$)"/(&-0(NEcHSFQLPJDcHSFQJBEEOFXcXDM DBU$)"/(&-0(NEcHSFQQPDLFcHSFQJBEEOFXcXDM DBU$)"/(&-0(NEcHSFQESFONJcHSFQJBEEOFXcXDM

Slide 40

Slide 40 text

$SFBUJPODPQDPVOU QXE 6TFSTLPJDTSDHJUIVCDPNSVCPDPQIRSVCPDPQ DBU$)"/(&-0(NEcHSFQLPJDcHSFQJBEEOFXcXDM DBU$)"/(&-0(NEcHSFQQPDLFcHSFQJBEEOFXcXDM DBU$)"/(&-0(NEcHSFQESFONJcHSFQJBEEOFXcXDM DBU$)"/(&-0(NEcHSFQCCBUTPWcHSFQJBEEOFXcXDM

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

-JTUPGDPQT*DSFBUFE DBU$)"/(&-0(NEcHSFQLPJDcHSFQJBEEOFX <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQQVMM "EE OFXA3BJMT3FGVUF.FUIPETADPQ <> <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQQVMM "EE OFXA-JOU&SC/FX"SHVNFOUTADPQ <> <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQQVMM "EE OFXA-JOU#JH%FDJNBM/FXADPQ <> <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQJTTVFT "EEOFXA-BZPVU&NQUZ$PNNFOUADPQ <> <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQJTTVFT "EEOFXA-JOU0SEFSFE.BHJD$PNNFOUTADPQ <> <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQJTTVFT "EEOFXA4UZMF&YQBOE1BUI"SHVNFOUTADPQ <>

Slide 43

Slide 43 text

-JTUPGDPQT*DSFBUFE <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQQVMM "EE OFXA(FNTQFD3FRVJSFE3VCZ7FSTJPOADPQ <> <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQQVMM "EE OFXA(FNTQFD3FEVOEBOU"TTJHONFOUADPQ <> <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQQVMM "EE OFXA3BJMT3FEVOEBOU3FDFJWFS*O8JUI0QUJPOTADPQ <> <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQJTTVFT "EEOFXA-JOU6OOFFEFE3FRVJSF4UBUFNFOUADPQ <> <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQQVMM "EE OFXA4UZMF4UEFSS1VUTADPQ <> <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQQVMM "EE OFXA-JOU3FEVOEBOU8JUI0CKFDUADPQ <>

Slide 44

Slide 44 text

-JTUPGDPQT*DSFBUFE <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQQVMM "EE OFXA4UZMF.JYJO6TBHFADPQ <> <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQQVMM "EE OFXA-JOU6SJ&TDBQF6OFTDBQFADPQ <> <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQQVMM "EE OFXA1FSGPSNBODF6SJ%FGBVMU1BSTFSADPQ <> <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQQVMM "EE OFXA-JOU6SJ3FHFYQADPQ <> <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQQVMM "EE OFXA#VOEMFS*OTFDVSF1SPUPDPM4PVSDFADPQ <> <> IUUQTHJUIVCDPNCCBUTPWSVCPDPQQVMM "EE OFXA-JOU3FEVOEBOU8JUI*OEFYADPQ <>

Slide 45

Slide 45 text

-JTUPGDPQT*DSFBUFE "EEOFXA1FSGPSNBODF4PSU8JUI#MPDLADPQUPVTF ATPSU@CZ GPP AJOTUFBEPGATPSU\cB CcBGPPCGPP^A <>

Slide 46

Slide 46 text

/VNCFSPG PQQPSUVOJUJFTUP NBLFDPQT ()SVCPDPQIRSVCPDPQ

Slide 47

Slide 47 text

/VNCFSPG PQQPSUVOJUJFTUP NBLFDPQT ()SVCPDPQIRSVCPDPQ 3VCZ

Slide 48

Slide 48 text

/VNCFSPG PQQPSUVOJUJFTUP NBLFDPQT ()SVCPDPQIRSVCPDPQ 3VCZ .ZQSPKFDUT

Slide 49

Slide 49 text

/VNCFSPG PQQPSUVOJUJFTUP NBLFDPQT ()SVCPDPQIRSVCPDPQ 3VCZ .ZQSPKFDUT ()SBJMTSBJMT

Slide 50

Slide 50 text

-FUTUBMLBCPVUUIFCBDLHSPVOEPG NBLJOHUIFTFDPQTBOEUIF LOPXMFEHFHBJOFEJOUIBUQSPDFTT

Slide 51

Slide 51 text

'SJ Improve Ruby coding style rules and Lint ,PJDIJ*50FTN 3VCZ,BJHJ 4FOEBJ*OUFSOBUJPOBM$FOUFS)BHJ How do you join social coding?

Slide 52

Slide 52 text

"HFOEB 0OUIFEJGGFSFODF CFUXFFODPEJOHTUZMFBOE -JOU &NVMBUF3VCZ`TXBSOJOH /FXDPQTUBSUTXJUI
 ZPVSQSPKFDU $SPTTPWFS
 044DPNNVOJUJFT 1BSU 1BSU 1BSU

Slide 53

Slide 53 text

1BSU

Slide 54

Slide 54 text

0OUIFEJGGFSFODF CFUXFFODPEJOH TUZMFBOE-JOU

Slide 55

Slide 55 text

4UZMF -JOU

Slide 56

Slide 56 text

4UZMF

Slide 57

Slide 57 text

w4UZMFJTGSPN WBSJPVTDVMUVSFT w6OJpFEXJUIJOB QSPKFDUTQFDJpD UBTUF 4UZMF

Slide 58

Slide 58 text

5IFSFT.PSF5IBO 0OF8BZ5P
 %FpOFB4UZMF

Slide 59

Slide 59 text

w.JOFSP"PLJTDPEJOHTUZMF +" wIUUQJMPWFSVCZOFUKBSVCZDPEJOHTUZMFIUNM w4IVHP.BFEBTDPEJOHTUZMF +" wIUUQTTIVHPOFUSVCZDPEFDPOW DPEFDPOWIUNM w3VCZ4UZMF(VJEF wIUUQTHJUIVCDPNSVCPDPQIRSVCZTUZMFHVJEF w"OEPUIFSTUZMFT w1FSTPOBMBOE$PNQBOZDPEJOHTUZMFT .BOZTUZMFTJOUIFSFBMXPSME

Slide 60

Slide 60 text

3VCZ4UZMF(VJEF

Slide 61

Slide 61 text

w3VCP$PQJNQMFNFOUT 3VCZ4UZMF(VJEFCZ EFGBVMU w3VCP$PQTPNFUJNFT QSPWJEFTPQUJPOT 4UZMFPG3VCP$PQ

Slide 62

Slide 62 text

&OGPSDFE4UZMFJTBOPQUJPOQBSBNFUFS IUUQSVCPDPQSFBEUIFEPDTJPFOMBUFTUDPQT@MBZPVUMBZPVUTQBDFJOTJEFCMPDLCSBDFT

Slide 63

Slide 63 text

&OGPSDFE4UZMFJTBOPQUJPOQBSBNFUFS IUUQSVCPDPQSFBEUIFEPDTJPFOMBUFTUDPQT@MBZPVUMBZPVUTQBDFJOTJEFCMPDLCSBDFT HPPE TPNF@BSSBZFBDI\cFcQVUTF^

Slide 64

Slide 64 text

&OGPSDFE4UZMFJTBOPQUJPOQBSBNFUFS IUUQSVCPDPQSFBEUIFEPDTJPFOMBUFTUDPQT@MBZPVUMBZPVUTQBDFJOTJEFCMPDLCSBDFT HPPE TPNF@BSSBZFBDI\cFcQVUTF^ HPPE TPNF@BSSBZFBDI\cFcQVUTF^

Slide 65

Slide 65 text

w*GZPVEPOPUMJLFUIFEFGBVMUTUZMF UIBUJT UIFTFUUJOHPGl3VCZ4UZMF (VJEFz ZPVDBOUBLFUIF GPMMPXJOHPQUJPOT w&EJUSVCPDPQZNMBOEVTF EJGGFSFOUPQUJPOT w&EJUSVCPDPQZNMBOEDIBOHFUIJT DPQ :PVDBODVTUPNJ[FUIFXBZ

Slide 66

Slide 66 text

$VTUPNJ[FECZSVCPDPQZNM "MM$PQT 5BSHFU3VCZ7FSTJPO -BZPVU4QBDF*OTJEF#MPDL4QBDFT &OGPSDFE4UZMFOP@TQBDF $IBOHF&OGPSDFE4UZMFGSPN TQBDF EFGBVMU UPOP@TQBDF

Slide 67

Slide 67 text

w%PO`UCFBGSBJEPGDVTUPNJ[BUJPO w1MFBTFCFDPOpEFOUJOZPVS DVMUVSF w*GFJUIFSJTPLBZUIFEFGBVMUXJMM CFpOF w"TBQFSTPOBMPQJOJPO UIFSFJT OPVOJpFE$P$JO4UZMF %FGBVMUJTOPUUIFPOMZTFUUJOH

Slide 68

Slide 68 text

w%FGBVMUDPOpHVSBUJPO CBTFEPO3VCZ4UZMF (VJEF w:PVNBZCFBCMFUP DIBOHF3VCP$PQ DPOpHVSBUJPO :PVDBODPOpHVSF3VCP$PQVTJOH SVCPDPQZNM

Slide 69

Slide 69 text

w'PSFYBNQMF UBMLCZ,FJKV *TIJ[VLBTBOBUPFEPSC w5IFEJGGFSFODFCFUXFFO `do``end`BOE`{``}` w3FQSFTFOUTUBUFNFOUBOE FYQSFTTJPOSFTQFDUJWFMZ 5IFSFNBZOPUCFPQUJPOTZPVMJLF

Slide 70

Slide 70 text

w%PFTUIFDPQEFDJEFXIFUIFSZPV BSFVTJOHSFUVSOWBMVFPSNFUIPE DIBJO w%PFTUIFDPQBMTPXPSLXIFO NVMUJQMZJOHUIFXIJUFMJTUPGNFUIPE OBNFT w3VCZCMPDLrescueJTBWBJMBCMFGPS `do``end`POMZ *UMFBETUPQBSUPGEFTJHOPG
 BOVOJNQMFNFOUFEDPQ

Slide 71

Slide 71 text

-JOU

Slide 72

Slide 72 text

w5IJOHTUIBUIBWFQPUFOUJBM CVHT w%FQSFDBUJPOXBSOJOHEVFUP GVUVSFJOUFSGBDFDIBOHF w3VCP$PQEPFTOPUQSPWJEF NBOZPQUJPOTPG-JOU -JOU

Slide 73

Slide 73 text

-JOU

Slide 74

Slide 74 text

/FX-JOUDPQ GPS3VCZ &YBNQMFT

Slide 75

Slide 75 text

*NQPSUXBSOJOHT GSPNSVCZSVCZUP 3VCP$PQ ()SVCPDPQIRSVCPDPQ VQTUSFBN 3VCZXBSOJOHT

Slide 76

Slide 76 text

SVCPDPQIRSVCPDPQ "EEOFXA-JOU&SC/FX"SHVNFOUTADPQ

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

"4UEMJCVQEBUF IUUQTHJUIVCDPNSVCZSVCZCMPCCFEDGGBGDGDB/&84TUEMJCVQEBUFTPVUTUBOEJOHPOFTPOMZ

Slide 79

Slide 79 text

&3#OFXJO3VCZ % cat example.rb require ‘erb' ERB.new('hi', nil, '-', ‘@output_buffer')

Slide 80

Slide 80 text

&3#OFXJO3VCZ % cat example.rb require ‘erb' ERB.new('hi', nil, '-', ‘@output_buffer') % ruby example.rb example.rb:3: warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments. example.rb:3: warning: Passing trim_mode with the 3rd argument of ERB.new is deprecated. Use keyword argument like ERB.new(str, trim_mode: ...) instead. example.rb:3: warning: Passing eoutvar with the 4th argument of ERB.new is deprecated. Use keyword argument like ERB.new(str, eoutvar: ...) instead.

Slide 81

Slide 81 text

&3#OFXJO3VCZ # bad # ERB.new(str, nil, '-', '@output_buffer') # good # ERB.new(str, trim_mode: '-', eoutvar:'@output_buffer')

Slide 82

Slide 82 text

3VCZ$PNQBUJCMF # https://github.com/ruby/ruby/commit/3406c5d # Ruby 2.6+ if ERB.instance_method(:initialize).parameters.assoc(:key) ERB.new(str, trim_mode: '-', eoutvar: '@output_buffer') else ERB.new(str, nil, '-', '@output_buffer') end

Slide 83

Slide 83 text

NJOJNVN@UBSHFU@SVCZ@WFSTJPO

Slide 84

Slide 84 text

&NVMBUJPOPG3VCP$PQ % rubocop example.rb --only Lint/ErbNewArguments Inspecting 1 file W Offenses: example.rb:3:15: W: Lint/ErbNewArguments: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments. ERB.new('hi', nil, '-', '@output_buffer') ^^^ example.rb:3:20: W: Lint/ErbNewArguments: Passing trim_mode with the 3rd argument of ERB.new is deprecated. Use keyword argument like ERB.new(str, trim_mode: '-') instead. ERB.new('hi', nil, '-', '@output_buffer') ^^^ example.rb:3:25: W: Lint/ErbNewArguments: Passing eoutvar with the 4th argument of ERB.new is deprecated. Use keyword argument like ERB.new(str, eoutvar: '@output_buffer') instead. ERB.new('hi', nil, '-', '@output_buffer') ^^^^^^^^^^^^^^^^

Slide 85

Slide 85 text

%JEZPVIBWFBOZQSPCMFNT

Slide 86

Slide 86 text

FSJLIVEBUIPS %FQSFDBUFTBGF@MFWFMPG&3#OFXJO3VCZ

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

5IFMPHMFOHUIIBTFYDFFEFEUIF MJNJUPG.# IUUQTHJUIVCDPNFSJLIVEBUIPSQVMMJTTVFDPNNFOU

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

wruby -w (RUBYOPT='-w')PQUJPOUSBDFT XBSOJOHTJOEFQFOEFOUMJCSBSJFT w3VCP$PQ`THSBOVMBSJUZJTSFQPTJUPSZ ZPVDBOGPDVTPOZPVS3BJMT BQQMJDBUJPODPEFBOEXBSOJOHTPO MJCSBSJFTUIBUZPVBSFNBOBHJOH w:PVDBOTVQFSJNQPTFQSFFYFDVUJPO XBSOJOHBOESVOUJNFXBSOJOH ASVCZXAPQUJPOWT3VCP$PQ

Slide 91

Slide 91 text

w.PTUMZ-JOUNBZCFFOBCMFE CFDBVTFJUJTOPUBQSFGFSFODF CVUBMBOHVBHFTQFDJpDBUJPO w*UJTCFUUFSOPUUPCFBGSBJEUP DIBOHFUIFTUZMFUIBUEPFT OPUpUUIFDVMUVSF5IFSFBSF WBSJPVTQSFGFSFODFT $PODMVTJPO

Slide 92

Slide 92 text

"HFOEB 0OUIFEJGGFSFODF CFUXFFODPEJOHTUZMFBOE -JOU &NVMBUF3VCZ`TXBSOJOH /FXDPQTUBSUTXJUI
 ZPVSQSPKFDU $SPTTPWFS
 044DPNNVOJUJFT 1BSU 1BSU 1BSU

Slide 93

Slide 93 text

1BSU

Slide 94

Slide 94 text

/FXDPQ TUBSUTXJUI ZPVSQSPKFDU

Slide 95

Slide 95 text

8FBSFDPOOFDUFECZ044 VQTUSFBN ()SVCPDPQIRSVCPDPQ .ZQSPKFDU ZPVSQSPKFDU w"TUPSZXIFSFDPEFSFWJFXT JONZQSPKFDUBSFDPEF SFWJFXTJOZPVSQSPKFDU

Slide 96

Slide 96 text

SVCPDPQIRSVCPDPQ "EEOFXA4UZMF.JYJO6TBHFADPQ

Slide 97

Slide 97 text

No content

Slide 98

Slide 98 text

"3BJMTBQQMJDBUJPO EFWFMPQNFOU

Slide 99

Slide 99 text

3FWJFXDPNNFOU *ODMVEJOHBUUIJTQPTJUJPOXJMMUBJOUUIFUPQMFWFM 3JHIU*XJMMpYJU

Slide 100

Slide 100 text

8IBUZPVQPJOUFEPVU DBOCFQPJOUFEPVUBU PUIFSPQQPSUVOJUJFT

Slide 101

Slide 101 text

044 3JEFPO044 3JEFPO044

Slide 102

Slide 102 text

"DPQ*NBEFIFMQFE FWFOJONZGSJFOET QSPKFDU

Slide 103

Slide 103 text

!POLTBZT l 4UZMF.JYJO6TBHFDPQ
 IBTXPSLFE 
 TP*TIPVMEHJWF!LPJD IUUQTUXJUUFSDPNPOLTUBUVT

Slide 104

Slide 104 text

)PXUPNBLF4UZMF.JYJO6TFHFDPQ

Slide 105

Slide 105 text

SBLFOFX@DPQ % be rake new_cop[Rails/TopLevelInclude]

Slide 106

Slide 106 text

SBLFOFX@DPQ % be rake new_cop[Rails/TopLevelInclude] Files created: - lib/rubocop/cop/rails/top_level_include.rb - spec/rubocop/cop/rails/ top_level_include_spec.rb File modified: - `require_relative 'rubocop/cop/rails/ top_level_include'` added into lib/rubocop.rb Do 3 steps: 1. Add an entry to the "New features" section in CHANGELOG.md, e.g. "Add new `TopLevel/Include` cop. ([@your_id][])" 2. Add an entry into config/enabled.yml or config/disabled.yml 3. Implement your new cop in the generated file!

Slide 107

Slide 107 text

8SJUFFYBNQMFT # TODO: when finished, run `rake generate_cops_documentation` to update the docs module RuboCop module Cop module Rails # TODO: Write cop description and example of bad / good code. # # @example # # bad # bad_method() # # # good # bad_method(args) 8SJUFDPQEFTDSJQUJPOBOE FYBNQMFPGCBEHPPE

Slide 108

Slide 108 text

8SJUFTQFDT describe RuboCop::Cop::Rails::TopLevelInclude do it 'registers an offense when using `#bad_method`' do expect_offense(<<-RUBY.strip_indent) bad_method ^^^^^^^^^^ Use `#good_method` instead of `#bad_method`. RUBY end it 'does not register an offense when using `#good_method`' do expect_no_offenses(<<-RUBY.strip_indent) good_method RUBY end end 8SJUFBCBEDBTFPOUIFAFYQFDU@P⒎FOTFA NFUIPE

Slide 109

Slide 109 text

8SJUFTQFDT describe RuboCop::Cop::Rails::TopLevelInclude do it 'registers an offense when using `#bad_method`' do expect_offense(<<-RUBY.strip_indent) bad_method ^^^^^^^^^^ Use `#good_method` instead of `#bad_method`. RUBY end it 'does not register an offense when using `#good_method`' do expect_no_offenses(<<-RUBY.strip_indent) good_method RUBY end end 8SJUFBCBEDBTFPOUIFAFYQFDU@P⒎FOTFA NFUIPE 8SJUFBHPPEDBTFPOUIFAFYQFDU@OP@P⒎FOTFTA NFUIPE

Slide 110

Slide 110 text

w8JUIexpect_offense BOE expect_no_offenses UIFUFTUDBOCF XSJUUFOSPVHIMZ 4USPOHUFTUJOH%4-

Slide 111

Slide 111 text

8SJUFTQFDT BHBJO describe RuboCop::Cop::Rails::TopLevelInclude do it 'registers an offense when using `#bad_method`' do expect_offense(<<-RUBY.strip_indent) bad_method ^^^^^^^^^^ Use `#good_method` instead of `#bad_method`. RUBY end it 'does not register an offense when using `#good_method`' do expect_no_offenses(<<-RUBY.strip_indent) good_method RUBY end end 8SJUFBCBEDBTFPOUIFAFYQFDU@P⒎FOTFA NFUIPE 8SJUFBHPPEDBTFPOUIFAFYQFDU@OP@P⒎FOTFTA NFUIPE

Slide 112

Slide 112 text

3FXSJUFTQFDT describe RuboCop::Cop::Rails::TopLevelInclude do it 'registers an offense when using outside class' do expect_offense(<<-RUBY.strip_indent) include ^^^^^^^ `include` is used at the top level. Use inside `class` or `module`. class C end RUBY end 8SJUFBCBEDBTFPOUIFAFYQFDU@P⒎FOTFA NFUIPE

Slide 113

Slide 113 text

3FXSJUFTQFDT describe RuboCop::Cop::Rails::TopLevelInclude do it 'registers an offense when using outside class' do expect_offense(<<-RUBY.strip_indent) include ^^^^^^^^^ `include` is used at the top level. Use inside `class` or `module`. class C end RUBY end it 'does not register an offense when using inside class' do expect_no_offenses(<<-RUBY.strip_indent) class C include M end RUBY 8SJUFBHPPEDBTFPOUIFAFYQFDU@OP@P⒎FOTFTA NFUIPE

Slide 114

Slide 114 text

SVCZQBSTF % ruby-parse -e 'include M’ (send nil :include (const nil :M)) % ruby-parse -e 'extend M’ (send nil :extend (const nil :M)) % ruby-parse -e 'prepend M’ (send nil :prepend (const nil :M)) (FU4FYQSFTTJPOGSPNSVCZQBSTFDPNNBOE 3VCP$PQJTEFQFOEFOUPO1BSTFSHFN

Slide 115

Slide 115 text

"CTUSBDU4ZOUBY5SFF % ruby_ast_visualizer -e 'include M’ (send nil :include (const nil :M)) Wrote a.png IUUQTHJUIVCDPNLPJDSVCZ@BTU@WJTVBMJ[FS

Slide 116

Slide 116 text

EFG@OPEF@NBUDIFS def_node_matcher :include_statement, <<-PATTERN (send nil? ${:include :extend :prepend} (const nil? _)) PATTERN 3FXSJUFBTOPEFQBUUFSOCBTFEPO4FYQSFTTJPO 'VSUIFSSFBEJOH IUUQTHJUIVCDPNSVCPDPQIRSVCPDPQCMPCNBTUFSMJCSVCPDPQOPEF@QBUUFSOSC

Slide 117

Slide 117 text

3VCP$PQ/PEF1BUUFSO (send nil? :include (const nil? _)) (send nil? :extend (const nil? _)) (send nil? :prepend (const nil? _)) (send nil? ${:include :extend :prepend} (const nil? _)) 6TFA\AA^A NBUDIFTJODMVEF FYUFOEPSQSFQFOE "OEAA BSCJUSBSZNBUDIJOHDBOCFQFSGPSNFEPOB DBQUVSF 'VSUIFSSFBEJOH IUUQTHJUIVCDPNSVCPDPQIRSVCPDPQCMPCNBTUFSMJCSVCPDPQOPEF@QBUUFSOSC

Slide 118

Slide 118 text

PO@YYYBEE@PGGFOTF MSG = '`%s` is used at the top level.' \ 'Use inside `class` or `module`.'.freeze def_node_matcher :include_statement, <<-PATTERN (send nil? ${:include :extend :prepend} (const nil? _)) PATTERN def on_send(node) return unless (statement = include_statement(node)) return unless top_level_node?(node) add_offense( node, message: format(MSG, statement: statement) ) end 8SJUFFWFOUIBOEMFSAPO@OPEF@OBNFA PSAJOWFTUJHBUFA NFUIPE

Slide 119

Slide 119 text

*NQMFNFOUBUJPO 3FE (SFFO 3FGBDUPS 5FTUDPEFJTNPSFPCWJPVTBOEFBTJFSUP VOEFSTUBOEUIBOUIFPQFSBUJPOPG"45

Slide 120

Slide 120 text

8SJUFDPOpHpMFT Rails/TopLevelInclude: Description: 'Checks that `include`, `extend` and `prepend` exists at the top level.' Enabled: true # In this PR, the following setting has been removed Rails/TopLevelInclude: Include: - app/**/*.rb "EEBOFOUSZJOUPDPOpHFOBCMFEZNM PSDPOpHEJTBCMFEZNM "EEBOFOUSZJOUPDPOpHEFGBVMUZNM *GEFGBVMUTFUUJOHJTSFRVJSFE

Slide 121

Slide 121 text

SBLFHFOFSBUF@DPQT@EPDVNFOUBUJPO % # Write the CHANGELOG.md % be rake generate_cops_documentation % be rake # be rake parallel:spec Finished in 39.07 seconds (files took 5.91 seconds to load) 17739 examples, 0 failures, 1 pending # be rake parallel:ascii_spec Finished in 37.04 seconds (files took 5.26 seconds to load) 17739 examples, 0 failures, 1 pending # be rake internal_investigation 1046 files inspected, no offenses detected 8IFOpOJTIFE SVO`rake generate_cops_documentation`UPVQEBUFUIFEPDT

Slide 122

Slide 122 text

0QFOB13

Slide 123

Slide 123 text

$POWFSTBUJPO

Slide 124

Slide 124 text

$POWFSTBUJPO

Slide 125

Slide 125 text

$POWFSTBUJPO

Slide 126

Slide 126 text

$POWFSTBUJPO

Slide 127

Slide 127 text

%JEZPVOPUJDFJU !QPDLF

Slide 128

Slide 128 text

$POWFSTBUJPO

Slide 129

Slide 129 text

SVCPDPQIRSVCPDPQ "EEOFXA4UZMF.JYJO6TBHFADPQ

Slide 130

Slide 130 text

No content

Slide 131

Slide 131 text

)FSF

Slide 132

Slide 132 text

3VCP$PQIBTOPQSFSFMFBTF

Slide 133

Slide 133 text

No content

Slide 134

Slide 134 text

Feedback

Slide 135

Slide 135 text

w'BMTFQPTJUJWFʜ(PPE DPEF CVUPGGFOTF IBQQFOT w'BMTFOFHBUJWFʜ#BE DPEF CVUPGGFOTFEPFT OPUIBQQFO 3FUSPTQFDUJWFUFSNT

Slide 136

Slide 136 text

3FUSPTQFDUJWFUFSNT QPTJUJWF OFHBUJWF 
 USVF
 *UJTEFUFDUFEDPSSFDUMZ *UJTOPUEFUFDUFEDPSSFDUMZ 
 GBMTF
 *UJTEFUFDUFEJODPSSFDUMZ *UJTOPUEFUFDUFEJODPSSFDUMZ

Slide 137

Slide 137 text

GBMTFQPTJUJWF

Slide 138

Slide 138 text

GBMTFQPTJUJWF

Slide 139

Slide 139 text

GBMTFQPTJUJWF

Slide 140

Slide 140 text

GBMTFQPTJUJWF

Slide 141

Slide 141 text

GBMTFQPTJUJWF

Slide 142

Slide 142 text

GBMTFQPTJUJWF

Slide 143

Slide 143 text

*ODMVEFNBUDIFS

Slide 144

Slide 144 text

1SPQPTFlGBMTFOFHBUJWFz

Slide 145

Slide 145 text

1SPQPTFlGBMTFOFHBUJWFz

Slide 146

Slide 146 text

1SPQPTFlGBMTFOFHBUJWFz

Slide 147

Slide 147 text

GBMTFQPTJUJWF ˣ GBMTFOFHBUJWF

Slide 148

Slide 148 text

GBMTFQPTJUJWF

Slide 149

Slide 149 text

FYQFDU@OP@PGGFOTFT

Slide 150

Slide 150 text

FYQFDU@PGGFOTF

Slide 151

Slide 151 text

3FTPMWFEDPEF

Slide 152

Slide 152 text

# In this PR, the following setting has been removed Rails/TopLevelInclude: Include: - app/**/*.rb $BVTFPGUIFQSPCMFN "EEBOFOUSZJOUPDPOpHEFGBVMUZNM *GEFGBVMUTFUUJOHJTSFRVJSFE *FYQBOEFEUIFTDPQFGSPN3BJMT UP4UZMFCVUUIFJNQMFNFOUBUJPO SFNBJOFEOBSSPX

Slide 153

Slide 153 text

$VSSFOUMZUIFSFBSFOPGBMTFQPTJUJWFT

Slide 154

Slide 154 text

w3FEVDFGBMTFQPTJUJWFTCZ SVOOJOHJO()SBJMTSBJMTSFQP w"OE3VOJOMPDBM3BJMTBQQ SFQP w*UNBZCFHPPEUPHPXJUI ()EJTDPVSTFEJTDPVSTF "DUJPOGSPN3FUSPTQFDUJWF

Slide 155

Slide 155 text

"HFOEB 0OUIFEJGGFSFODF CFUXFFODPEJOHTUZMFBOE -JOU &NVMBUF3VCZ`TXBSOJOH /FXDPQTUBSUTXJUI
 ZPVSQSPKFDU $SPTTPWFS
 044DPNNVOJUJFT 1BSU 1BSU 1BSU

Slide 156

Slide 156 text

1BSU

Slide 157

Slide 157 text

$SPTTPWFS 044 DPNNVOJUJFT

Slide 158

Slide 158 text

"TUPSZBCPVU JNQPSUDVTUPNDPQ GSPN3BJMTUP3VCP$PQ VQTUSFBN ()SVCPDPQIRSVCPDPQ ()SBJMTSBJMT

Slide 159

Slide 159 text

SBJMTSBJMT

Slide 160

Slide 160 text

SVCPDPQZNMBUSBJMTSBJMT

Slide 161

Slide 161 text

SVCPDPQZNMBUSBJMTSBJMT %JTBCMFE#Z%FGBVMUUSVF

Slide 162

Slide 162 text

SBJMTSBJMT "EEDVTUPN3VCP$PQGPSABTTFSU@OPUAPWFSASFGVUFA

Slide 163

Slide 163 text

No content

Slide 164

Slide 164 text

No content

Slide 165

Slide 165 text

3BJMTDPNNJUUFST TVHHFTUFEUPNF !ZZBHJ !LBNJQP

Slide 166

Slide 166 text

#FOFpUTPG3BJMT VQTUSFBN ()SVCPDPQIRSVCPDPQ ()SBJMTSBJMT w3FEVDFEFQFOEFODZPO3BJMT w5IJTDVTUPNDPQNBZCF VTFEFOEVTFST

Slide 167

Slide 167 text

#FOFpUTPGFOEVTFST VQTUSFBN ()SVCPDPQIRSVCPDPQ :PVSQSPKFDU ()SBJMTSBJMT w3FEVDFEFQFOEFODZPO3BJMT w5IJTDVTUPNDPQNBZCF VTFEBMTPCZFOEVTFST

Slide 168

Slide 168 text

w(FNJGZUPOFX 3VCP$PQ.5HFN wABTTFSU@OPUANFUIPEJT B"45FTU$BTFNFUIPE *UJTO`UB.5NFUIPE 8IFSFUPFYQPSU SEQBSUZHFNT

Slide 169

Slide 169 text

w(FNJGZUPOFX 3VCP$PQ.5HFN wABTTFSU@OPUANFUIPEJT B"45FTU$BTFNFUIPE *UJTO`UB.5NFUIPE 8IFSFUPFYQPSU

Slide 170

Slide 170 text

"45FTU$BTF.55FTU IUUQTHJUIVCDPNSBJMTSBJMTCMPCWBDUJWFTVQQPSUMJCBDUJWF@TVQQPSUUFTU@DBTFSC--

Slide 171

Slide 171 text

w4P &YQPSUUIJTDPQ UP3BJMTEFQBSUNFOU JO3VCP$PQ 8IFSFUPFYQPSU

Slide 172

Slide 172 text

SVCPDPQIRSVCPDPQ "EEOFXA3BJMT3FGVUF.FUIPETADPQ

Slide 173

Slide 173 text

No content

Slide 174

Slide 174 text

No content

Slide 175

Slide 175 text

SVCPDPQIRSVCPDPQ SBJMTSBJMT

Slide 176

Slide 176 text

TVQFS 3VCP$PQ$PQ $VTUPN$PQT 3FGVUF/PU PSJHJOBM DPQDMBTT 1MVHHBCMFBSDIJUFDUVSF

Slide 177

Slide 177 text

TVQFS 3VCP$PQ$PQ $VTUPN$PQT 3FGVUF/PU 3BJMT3FGVUF.FUIPET .PTUMZUIFJNQMFNFOUBUJPOXBTJOUBDU PSJHJOBM DPQDMBTT JNQPSUFE DPQDMBTT 1MVHHBCMFBSDIJUFDUVSF

Slide 178

Slide 178 text

w3BJMTDPNNVOJUZ DPOUSJCVUPSDPNFUP 3VCP$PQDPNNVOJUZ "OJOUFSFTUJOHQIFOPNFOPO

Slide 179

Slide 179 text

$PNNFOUFECZ"3BJMTDPOUSJCVUPS

Slide 180

Slide 180 text

*NQPSUFEBOPUIFSDPQGSPN3BJMT

Slide 181

Slide 181 text

3VCP$PQ JT
 SFMFBTFE 3VCP$PQ JT
 FOBCMFEXJUI$PEF$MJNBUF *OUIFGVUVSFXPSME *GUIFGPMMPXJOHDPOEJUJPOT BSFNFU 3BJMTDBOMFBWF UIFTFDPQTUP3VCP$PQ

Slide 182

Slide 182 text

#FUUFS MFBWFJUUP FYQFSUT

Slide 183

Slide 183 text

#FOFpUTPGFOEVTFSTBOE VQTUSFBN ()SVCPDPQIRSVCPDPQ :PVSQSPKFDU (SFBUSFQPT ZPVLOPX w3FEVDFEFQFOEFODZPOFYQPSUFESFQP w5IJTDVTUPNDPQNBZCFVTFEFOE VTFST w$PNNVOJUZQFPQMFBSFDPOOFDUFE

Slide 184

Slide 184 text

"HFOEB 0OUIFEJGGFSFODF CFUXFFODPEJOHTUZMFBOE -JOU &NVMBUF3VCZ`TXBSOJOH /FXDPQTUBSUTXJUI
 ZPVSQSPKFDU $SPTTPWFS
 044DPNNVOJUJFT 1BSU 1BSU 1BSU

Slide 185

Slide 185 text

Playback

Slide 186

Slide 186 text

5PEBZ`TTUPSZXBT BHSFBUQSFTFOUBUJPO BGUFSZFBSTGSPN IUUQKQSVCZJTUOFU3VCZ,BJHJ-PH4IUNM

Slide 187

Slide 187 text

w7BSJPVTDPNQBOJFTVTJOH3VCZ 3BJMTGPSEFWFMPQNFOUBQQFBSFE w(JU)VCIBTBQQFBSFE BOE JOEJWJEVBMBDUJWJUJFTBSFESBXJOH BUUFOUJPO w3VCZJTUTBOE3VCZJTIDPNQBOJFT NBLFTWBSJPVT3VCZDPEJOHTUZMFT .PEFSOUJNFT

Slide 188

Slide 188 text

.PEFSOUJNFT VQTUSFBN ()SVCPDPQIRSVCPDPQ 3VCZ :PVSQSPKFDU ()SBJMTSBJMT w3VCZVTFEJOWBSJPVTQMBDFT w7BSJPVTJNQPSUTPVSDFT

Slide 189

Slide 189 text

.PEFSOUJNFT VQTUSFBN ()SVCPDPQIRSVCPDPQ 3VCZ :PVSQSPKFDU ()SBJMTSBJMT w5IFSFJTBQPTTJCJMJUZUIBU$PQ UIBUJTVTFGVMUPPUIFSTDBOCF VTFGVMGPSPUIFST

Slide 190

Slide 190 text

.PEFSOUJNFT VQTUSFBN ()SVCPDPQIRSVCPDPQ 3VCZ :PVSQSPKFDU ()SBJMTSBJMT w%JWFSTJUZZPVDBODIBOHFBOE DVTUPNJ[FJUGPSZPVSQSPKFDU EFGBVMU PS DVTUPN

Slide 191

Slide 191 text

w'JSTUPGBMM ZPVDBOVTFJUBT EFGBVMUPSDVTUPNJ[FJU w:PVDBOPQFOB13UPVQTUSFBN BOZUJNF w5IFSFBSFWBSJPVTTUBSUJOHNFUIPET w6TFUIFPQQPSUVOJUZUPMJTUFOUP QFPQMFZPVLOPX %FGBVMUTUZMFJTO`UUIFPOMZTFUUJOH

Slide 192

Slide 192 text

IUUQBHJMFNBOJGFTUPPSH

Slide 193

Slide 193 text

IUUQBHJMFNBOJGFTUPPSH

Slide 194

Slide 194 text

4P :PVBMSFBEZ IBWF PQQPSUVOJUJFT

Slide 195

Slide 195 text

No content

Slide 196

Slide 196 text

One more thing…

Slide 197

Slide 197 text

3BJMT0441BUDINFFUVQ

Slide 198

Slide 198 text

4PDJBMDPEJOHTUBSUTXJUIZPV :PV

Slide 199

Slide 199 text

!LPJD 5IBOLT .*/"48"/

Slide 200

Slide 200 text

l "QSPCMFNJTpYFE OPUCFDBVTFUIFSFBSF QFPQMFJOUSPVCMF CVUCFDBVTFUIFSFBSF QFPQMFXIPXBOUUPpYJU ࠔ͍ͬͯΔਓ͕͍Δ໰୊͕௚ΔͷͰ͸ͳ͘ɺ ௚͢ؾͷ͋Δਓ͕͍Δ໰୊͕௚ΔCZ!LBNJQP