Upgrade to Pro — share decks privately, control downloads, hide ads and more …

やさしいコーディング規約の導入〜その後〜 / yasashii-sonogo

fortkle
November 03, 2016

やさしいコーディング規約の導入〜その後〜 / yasashii-sonogo

fortkle

November 03, 2016
Tweet

More Decks by fortkle

Other Decks in Technology

Transcript

  1. ΍͍͞͠1)1ίʔσΟϯάن໿ͷಋೖ
    ʙͦͷޙʙ
    1)1ΧϯϑΝϨϯε
    ίωώτגࣜձࣾ!GPSULMF
    Ո଒ͷຖ೔Λ΋ͬͱসإʹɻ

    View full-size slide

  2. ͸͡Ί·ͯ͠ʂ
    w αʔόʔαΠυΤϯδχΞ
    w ίωώτגࣜձࣾ
    w ʮϚϚϦʯʮϚϚϦ2ʯͷ։ൃ
    ߴ໺෱ߊ !GPSULMF

    View full-size slide

  3. ໿൒೥લɾɾɾ
    Ո଒ͷຖ೔Λ΋ͬͱসإʹɻ

    View full-size slide

  4. ։ൃऀϒϩάͰެ։

    View full-size slide

  5. ͯ͞ɺࠓ೔͸ϒϩάͷ಺༰Λ
    Ո଒ͷຖ೔Λ΋ͬͱসإʹɻ

    View full-size slide

  6. ؆୯ʹৼΓฦΓͭͭ
    Ո଒ͷຖ೔Λ΋ͬͱসإʹɻ

    View full-size slide

  7. ͦͷޙͷ࿩Λ͠·͢ʂ
    Ո଒ͷຖ೔Λ΋ͬͱসإʹɻ

    View full-size slide

  8. ͜͏͍͏ίʔυɺͲ͏ࢥ͍·͔͢ʁ
    class Hoge{
    public function fuga()
    {
    echo 'fuga!';
    }
    public function piyo($isPiyo = true) {
    if($isPiyo){
    echo 'piyo!';
    }else{
    echo 'fuga!';
    }
    }
    }

    View full-size slide

  9. ͜͏͍͏ίʔυɺͲ͏ࢥ͍·͔͢ʁ
    class Hoge{
    public function fuga()
    {
    echo 'fuga!';
    }
    public function piyo($isPiyo = true) {
    if($isPiyo){
    echo 'piyo!';
    }else{
    echo 'fuga!';
    }
    }
    }

    View full-size slide

  10. w ׅހͷด͡ํʹنଇੑ͕ͳ͍
    w JGͷ͋ͱͷׅހͷલʹTQBDF͕ͳ͍
    w Πϯσϯτ͕จࣈͣΕ͍ͯΔ
    ෆ౷ҰͳίʔσΟϯάελΠϧͷؾ࣋ͪѱ͞
    ͜͏͍͏ίʔυɺͲ͏ࢥ͍·͔͢ʁ

    View full-size slide

  11. ͜͏͍͏ίʔυɺͲ͏ࢥ͍·͔͢ʁ
    class Hoge{
    public function fuga()
    {
    echo 'fuga!';
    }
    public function piyo($isPiyo = true) {
    if($isPiyo){
    echo 'piyo!';
    }else{
    echo 'fuga!';
    }
    }
    }

    View full-size slide

  12. class Hoge{
    public function fuga()
    {
    echo 'fuga!';
    }
    public function piyo($isPiyo = true) {
    if($isPiyo){
    echo 'piyo!';
    }else{
    echo 'fuga!';
    }
    }
    }
    ˞͜͜ͷߦ͚ͩΠϯσϯτ͕λϒͰ͢
    ͜͏͍͏ίʔυɺͲ͏ࢥ͍·͔͢ʁ

    View full-size slide

  13. ͜͏͍͏ίʔυɺͲ͏ࢥ͍·͔͢ʁ

    View full-size slide

  14. ͜͏ͳΔલʹ
    ίʔσΟϯάελΠϧΛ
    ౷Ұ͠Α͏ʂ
    Ո଒ͷຖ೔Λ΋ͬͱসإʹɻ

    View full-size slide

  15. w TRVJ[MBCT1)1@$PEF4OJ⒎FS
    w ίʔσΟϯάن໿ΛνΣοΫ͢Δπʔϧ
    w W͔Β͸QIQDCGίϚϯυͰमਖ਼΋Մೳ
    w ద༻͢Δن໿͸ඪ४Ͱ1&"3 143ɾ ;FOEͳͲαϙʔτ
    w YNMܗࣜͰ؆୯ʹΧελϜن໿Λ࡞Δ͜ͱ΋Մೳ
    w MJOUͷ݁ՌΛ༷ʑͳܗࣜͰग़ྗͰ͖Δ
    w DIFDLTUZMF YNM TVNNBSZͳͲ
    ͦ͜Ͱ1)1@$PEF4OJ⒎FS
    ͦ͜Ͱ1)1@$PEF4OJ⒎FS

    View full-size slide

  16. ͬͦ͘͞طଘϓϩδΣΫτʹ
    ಋೖͯ͠ΈΔͱɾɾɾ
    Ո଒ͷຖ೔Λ΋ͬͱসإʹɻ

    View full-size slide

  17. ݸ௒͑ͷΤϥʔɾɾɾ
    1)1@$PEF4OJ⒎FSΛద༻
    $ phpcs --standard=PSR2 ./app
    ----------------------------------------------------------------
    A TOTAL OF 1364 ERRORS AND 290 WARNINGS WERE FOUND IN 80 FILES
    ----------------------------------------------------------------

    View full-size slide

  18. ݸ௒͑ͷΤϥʔɾɾɾ
    1)1@$PEF4OJ⒎FSΛద༻

    View full-size slide

  19. w ͔ͳΓ੒ख़ͨ͠ϓϩμΫτ
    w ίʔσΟϯάن໿͸͋Δ͕ΦϨΦϨن໿
    w 143ʹ͸४ڌ͍ͯ͠ͳ͍
    w ίʔυϨϏϡʔ࣌ʹػցͰ͸ͳ͘ਓ͕ؒ

    ໨ࢹͰҧ൓͍ͯ͠ͳ͍͔νΣοΫ
    w Ώ͑ʹ౰વϞϨ͸͋Δʜ
    ঢ়گ
    1)1@$PEF4OJ⒎FSΛద༻

    View full-size slide

  20. w ΤίγεςϜͷԸܙΛड͚ΔͨΊʹ΋143Λ࠾༻͍ͨ͠
    w ͔͠͠ɺ͍͖ͳΓ143ʹ׬શʹ४ڌ͢Δͷ͸ෛ୲͕େ͖͍
    w υΩϡϝϯτ੔උ͚ͨͩ͠Ͱ͸ਁಁ͠ͳ͍ͷͰࣗಈతʹ

    νΣοΫ͞ΕΔ࢓૊Έʹ͍ͨ͠
    w ։ൃதʹ΋νΣοΫͰ͖ΔΑ͏ʹ͍ͨ͠
    w 4JEF$*΍)PVOEΛ࢖͏ͷ΋͍͍͕ίετ͸཈͑ΒΕΔͷʹ

    ӽͨ͜͠ͱ͸ͳ͍
    ໨ࢦ͢ΰʔϧ
    1)1@$PEF4OJ⒎FSΛద༻

    View full-size slide

  21. ͦ͜Ͱʮ΍͘͞͠ʯಋೖ͢Δ
    ʮ΍͘͞͠ʯಋೖ͢Δ

    View full-size slide

  22. ΤσΟλ΍*%&ͰQIQDTΛ
    ࣮ߦͰ͖ΔΑ͏ʹ͚ͨ͠Ͳ

    ͨ͘͞ΜΤϥʔ͕ग़ͯ

    ͭΒ͍ʙ
    ΍͘͞͠͠·͠ΐʙ
    ʮ΍͘͞͠ʯಋೖ͢Δ

    View full-size slide

  23. 143Λܧঝͨ͠ΧελϜن໿QIQDTYNMΛ࡞Δ
    ΍͍͞͠ن໿Λ࡞Δ
    // phpcs.xml


    Custom standard Based on PSR2


    ʮ΍͘͞͠ʯಋೖ͢Δ

    View full-size slide

  24. 1)1@$PEF4OJ⒎FS QIQDT
    ͷग़ྗΦϓγϣϯΛม͑ͯ

    ҧ൓ͨ͠ن໿໊Λ͢΂ͯදࣔͤ͞Δ
    ΍͍͞͠ن໿Λ࡞Δ
    $ phpcs -s --report=source --standard=./phpcs.xml ./app
    ʮ΍͘͞͠ʯಋೖ͢Δ

    View full-size slide

  25. ΍͍͞͠ن໿Λ࡞Δ
    ----------------------------------------------------------------------
    SOURCE COUNT
    ----------------------------------------------------------------------
    [x] Generic.WhiteSpace.DisallowTabIndent.TabsUsed 629
    [x] Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLin 342
    ʙུʙ
    [x] PSR2.Files.EndFileNewline.NoneFound 1
    [ ] Squiz.Functions.FunctionDeclaration 1
    ----------------------------------------------------------------------
    A TOTAL OF 1654 SNIFF VIOLATIONS WERE FOUND IN 40 SOURCES
    ----------------------------------------------------------------------
    ʮ΍͘͞͠ʯಋೖ͢Δ
    Τϥʔͱͯ͠ݕग़͞Εͨن໿ͱΤϥʔ݅਺͕

    ιʔτ͞Εͯදࣔ͞ΕΔ

    View full-size slide

  26. ͜͜Ͱ͓΋ΉΖʹΤϥʔʹͳͬͨن໿Λશͯআ֎͢Δ

    ۩ମతʹ͸QIQDTYNMʹFYDMVEFͱͯ͠௥ه

    ΍͍͞͠ن໿Λ࡞Δ


    Custom standard Based on PSR2











    ʮ΍͘͞͠ʯಋೖ͢Δ

    View full-size slide

  27. ࠶౓QIQDTΛ࣮ߦ͢ΔͱΤϥʔ͕ग़ͳ͘ͳΔɻ

    ʮ΍͍͞͠ن໿ʯͷ׬੒ʂ
    ΍͍͞͠ن໿Λ࡞Δ
    $ phpcs -s --report=source --standard=./phpcs.xml ./app
    $ // Τϥʔ͕ͳ͍ͷͰ࣮ߦͯ͠΋Կ΋දࣔ͞Εͳ͍
    ʮ΍͘͞͠ʯಋೖ͢Δ

    View full-size slide

  28. ࡉ͔͘ϑΣʔζΛ෼͚ͯͭͭআ֎ϧʔϧΛফ͍ͯ͘͠

    ͍ܰෛ୲Ͱ͍͔ͭࣗવͱ໨ඪͷن໿ʹͳΔʂ
    ঃʑʹআ֎ن໿Λগͳ͍ͯ͘͘͠


    Custom standard Based on PSR2




    ʮ΍͘͞͠ʯಋೖ͢Δ

    View full-size slide

  29. खಈͰνΣοΫ͢Δͷ͕
    ໘౗ʹײ͡ΔΑʙ
    ΍͘͞͠͠·͠ΐʙ
    ʮ΍͘͞͠ʯಋೖ͢Δ

    View full-size slide

  30. ʮ΍͘͞͠ʯಋೖ͢Δ
    w IBZBCVTBSFWJFXEPH
    w MJOUΤϥʔΛࣗಈͰ13ʹίϝϯτͨ͠ΓɺHJUEJ⒎ͷ݁Ռ͔Β

    ฤूߦͷΤϥʔ͚ͩදࣔ͢ΔΑ͏ʹϑΟϧλϦϯάͰ͖Δπʔϧ
    w 1)1Ͱ͸ͳ͘(P੡
    ͦ͜ͰSFWJFXEPH

    View full-size slide

  31. ྫͱͯ͠5SBWJT$*Ͱࣗಈ࣮ߦ͢Δɻ

    ίϝϯτΛࣗಈ౤ߘ͢ΔͨΊʹ(JUIVC5PLFO͕ඞཁͳͷͰ

    औಘ͠ɺUSBWJTͷػߏΛ࢖ͬͯ҉߸Խͯ͠؀ڥม਺ͱͯ͠ઃఆɻ
    मਖ਼Օॴ͚ͩͷࢦఠͱ$*ʹΑΔࣗಈ࣮ߦ
    // travisίϚϯυΛ࢖͑ΔΑ͏ʹ͢Δ
    $ gem install travis
    // ؀ڥม਺ͱͯ͠ઃఆ
    $ travis encrypt REVIEWDOG_GITHUB_API_TOKEN=
    --add env.global
    ʮ΍͘͞͠ʯಋೖ͢Δ

    View full-size slide

  32. 5SBWJT্ͰQIQDTΛ࣮ߦ͠ɺͦͷ݁ՌΛSFWJFXEPHʹ౉͢
    मਖ਼Օॴ͚ͩͷࢦఠͱ$*ʹΑΔࣗಈ࣮ߦ
    env:
    global:
    secure: xxxxxxxxxxxxx
    install:
    - curl -fSL https://github.com/haya14busa/reviewdog/releases/download/
    0.9.2/reviewdog_linux_amd64 -o reviewdog && chmod +x ./reviewdog
    script:
    - >-
    phpcs --report=emacs --standard=./phpcs.xml ./app | reviewdog 

    -f=checkstyle -diff="git diff master” -ci=travis
    ʮ΍͘͞͠ʯಋೖ͢Δ

    View full-size slide

  33. ΤϥʔΛमਖ਼Օॴ͚ͩʹϑΟϧλϦϯά͠ɺ13ͷ֘౰ߦʹ

    ίϝϯτΛ౤ߘͤ͞Δ
    मਖ਼Օॴ͚ͩͷࢦఠͱ$*ʹΑΔࣗಈ࣮ߦ
    ʮ΍͘͞͠ʯಋೖ͢Δ

    View full-size slide

  34. ͜͏ͨ͠޻෉΍QIQDCGʹΑΔ

    ࣗಈमਖ਼Λߦͬͯ
    Ո଒ͷຖ೔Λ΋ͬͱসإʹɻ

    View full-size slide

  35. ໿൒೥ܦͬͯͦͷޙͲ͏ͳ͔ͬͨ
    Ո଒ͷຖ೔Λ΋ͬͱসإʹɻ

    View full-size slide

  36. w ݅͋ͬͨΤϥʔ͸݅ʹʂ
    w Τϥʔ͸ফ͕͑ͨϫʔχϯά 8BSOJOH
    ͕·ͩͭ͋Δ
    w l(FOFSJD'JMFT-JOF-FOHUIzߦࣈ·Ͱ
    w Զୡͷઓ͍͸͜Ε͔Βͩʂ
    ͦͷޙͲ͏ͳ͔ͬͨ
    ͦͷޙ

    View full-size slide

  37. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ
    Ո଒ͷຖ೔Λ΋ͬͱসإʹɻ

    View full-size slide