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

F4d37a67ce86b2f962c79d73a9127d3c?s=47 fortkle
November 03, 2016

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

F4d37a67ce86b2f962c79d73a9127d3c?s=128

fortkle

November 03, 2016
Tweet

Transcript

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

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

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

  4. ։ൃऀϒϩάͰެ։

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

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

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

  8. ͜͏͍͏ίʔυɺͲ͏ࢥ͍·͔͢ʁ <?php class Hoge{ public function fuga() { echo 'fuga!';

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

    } public function piyo($isPiyo = true) { if($isPiyo){ echo 'piyo!'; }else{ echo 'fuga!'; } } }
  10. w ׅހͷด͡ํʹنଇੑ͕ͳ͍ w JGͷ͋ͱͷׅހͷલʹTQBDF͕ͳ͍ w Πϯσϯτ͕จࣈͣΕ͍ͯΔ ෆ౷ҰͳίʔσΟϯάελΠϧͷؾ࣋ͪѱ͞ ͜͏͍͏ίʔυɺͲ͏ࢥ͍·͔͢ʁ

  11. ͜͏͍͏ίʔυɺͲ͏ࢥ͍·͔͢ʁ <?php class Hoge{ public function fuga() { echo 'fuga!';

    } public function piyo($isPiyo = true) { if($isPiyo){ echo 'piyo!'; }else{ echo 'fuga!'; } } }
  12. <?php class Hoge{ public function fuga() { echo 'fuga!'; }

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

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

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

  17. ݸ௒͑ͷΤϥʔɾɾɾ 1)1@$PEF4OJ⒎FSΛద༻ $ phpcs --standard=PSR2 ./app ---------------------------------------------------------------- A TOTAL OF

    1364 ERRORS AND 290 WARNINGS WERE FOUND IN 80 FILES ----------------------------------------------------------------
  18. ݸ௒͑ͷΤϥʔɾɾɾ 1)1@$PEF4OJ⒎FSΛద༻

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

    Ώ͑ʹ౰વϞϨ͸͋Δʜ ঢ়گ 1)1@$PEF4OJ⒎FSΛద༻
  20. w ΤίγεςϜͷԸܙΛड͚ΔͨΊʹ΋143Λ࠾༻͍ͨ͠ w ͔͠͠ɺ͍͖ͳΓ143ʹ׬શʹ४ڌ͢Δͷ͸ෛ୲͕େ͖͍ w υΩϡϝϯτ੔උ͚ͨͩ͠Ͱ͸ਁಁ͠ͳ͍ͷͰࣗಈతʹ
 νΣοΫ͞ΕΔ࢓૊Έʹ͍ͨ͠ w ։ൃதʹ΋νΣοΫͰ͖ΔΑ͏ʹ͍ͨ͠ w

    4JEF$*΍)PVOEΛ࢖͏ͷ΋͍͍͕ίετ͸཈͑ΒΕΔͷʹ
 ӽͨ͜͠ͱ͸ͳ͍ ໨ࢦ͢ΰʔϧ 1)1@$PEF4OJ⒎FSΛద༻
  21. ͦ͜Ͱʮ΍͘͞͠ʯಋೖ͢Δ ʮ΍͘͞͠ʯಋೖ͢Δ

  22. ΤσΟλ΍*%&ͰQIQDTΛ ࣮ߦͰ͖ΔΑ͏ʹ͚ͨ͠Ͳ
 ͨ͘͞ΜΤϥʔ͕ग़ͯ
 ͭΒ͍ʙ ΍͘͞͠͠·͠ΐʙ ʮ΍͘͞͠ʯಋೖ͢Δ

  23.  143Λܧঝͨ͠ΧελϜن໿QIQDTYNMΛ࡞Δ ΍͍͞͠ن໿Λ࡞Δ // phpcs.xml <?xml version="1.0"?> <ruleset name="Custom_PSR2"> <description>Custom

    standard Based on PSR2</description> <rule ref="PSR2" /> </ruleset> ʮ΍͘͞͠ʯಋೖ͢Δ
  24.  1)1@$PEF4OJ⒎FS QIQDT ͷग़ྗΦϓγϣϯΛม͑ͯ
 ҧ൓ͨ͠ن໿໊Λ͢΂ͯදࣔͤ͞Δ ΍͍͞͠ن໿Λ࡞Δ $ phpcs -s --report=source

    --standard=./phpcs.xml ./app ʮ΍͘͞͠ʯಋೖ͢Δ
  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 ---------------------------------------------------------------------- ʮ΍͘͞͠ʯಋೖ͢Δ Τϥʔͱͯ͠ݕग़͞Εͨن໿ͱΤϥʔ݅਺͕
 ιʔτ͞Εͯදࣔ͞ΕΔ
  26.  ͜͜Ͱ͓΋ΉΖʹΤϥʔʹͳͬͨن໿Λશͯআ֎͢Δ
 ۩ମతʹ͸QIQDTYNMʹFYDMVEFͱͯ͠௥ه ΍͍͞͠ن໿Λ࡞Δ <?xml version="1.0"?> <ruleset name="Custom_PSR2"> <description>Custom standard

    Based on PSR2</description> <rule ref="PSR2"> <exclude name="Generic.WhiteSpace.DisallowTabIndent.TabsUsed"/> <!-- 145 --> <exclude name="Squiz.WhiteSpace.SuperfluousWhitespace.EndLine"/> <!-- 21 --> <exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine"/> <!-- 18 --> <exclude name="Generic.Files.LineLength.TooLong"/> <!-- 17 --> <exclude name="PSR2.Classes.ClassDeclaration.CloseBraceAfterBody"/> <!-- 16 --> <exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword"/> <!-- 9 --> <exclude name="Squiz.Functions.MultiLineFunctionDeclaration"/> <!-- 1 --> <exclude name="Generic.WhiteSpace.ScopeIndent.Incorrect"/> <!-- 1 --> </rule> </ruleset> ʮ΍͘͞͠ʯಋೖ͢Δ
  27.  ࠶౓QIQDTΛ࣮ߦ͢ΔͱΤϥʔ͕ग़ͳ͘ͳΔɻ
 ʮ΍͍͞͠ن໿ʯͷ׬੒ʂ ΍͍͞͠ن໿Λ࡞Δ $ phpcs -s --report=source --standard=./phpcs.xml ./app

    $ // Τϥʔ͕ͳ͍ͷͰ࣮ߦͯ͠΋Կ΋දࣔ͞Εͳ͍ ʮ΍͘͞͠ʯಋೖ͢Δ
  28.  ࡉ͔͘ϑΣʔζΛ෼͚ͯͭͭআ֎ϧʔϧΛফ͍ͯ͘͠
 ͍ܰෛ୲Ͱ͍͔ͭࣗવͱ໨ඪͷن໿ʹͳΔʂ ঃʑʹআ֎ن໿Λগͳ͍ͯ͘͘͠ <?xml version="1.0"?> <ruleset name="Custom_PSR2"> <description>Custom standard

    Based on PSR2</description> <rule ref="PSR2"> <!-- Կ΋ͳ͘ͳΔͱPSR-2ͱಉ༷ͷϧʔϧͱͳΔʂ --> </rule> </ruleset> ʮ΍͘͞͠ʯಋೖ͢Δ
  29. खಈͰνΣοΫ͢Δͷ͕ ໘౗ʹײ͡ΔΑʙ ΍͘͞͠͠·͠ΐʙ ʮ΍͘͞͠ʯಋೖ͢Δ

  30. ʮ΍͘͞͠ʯಋೖ͢Δ w IBZBCVTBSFWJFXEPH w MJOUΤϥʔΛࣗಈͰ13ʹίϝϯτͨ͠ΓɺHJUEJ⒎ͷ݁Ռ͔Β
 ฤूߦͷΤϥʔ͚ͩදࣔ͢ΔΑ͏ʹϑΟϧλϦϯάͰ͖Δπʔϧ w 1)1Ͱ͸ͳ͘(P੡ ͦ͜ͰSFWJFXEPH

  31.  ྫͱͯ͠5SBWJT$*Ͱࣗಈ࣮ߦ͢Δɻ
 ίϝϯτΛࣗಈ౤ߘ͢ΔͨΊʹ(JUIVC5PLFO͕ඞཁͳͷͰ
 औಘ͠ɺUSBWJTͷػߏΛ࢖ͬͯ҉߸Խͯ͠؀ڥม਺ͱͯ͠ઃఆɻ मਖ਼Օॴ͚ͩͷࢦఠͱ$*ʹΑΔࣗಈ࣮ߦ // travisίϚϯυΛ࢖͑ΔΑ͏ʹ͢Δ $ gem install

    travis // ؀ڥม਺ͱͯ͠ઃఆ $ travis encrypt REVIEWDOG_GITHUB_API_TOKEN=<your token> --add env.global ʮ΍͘͞͠ʯಋೖ͢Δ
  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 ʮ΍͘͞͠ʯಋೖ͢Δ
  33.  ΤϥʔΛमਖ਼Օॴ͚ͩʹϑΟϧλϦϯά͠ɺ13ͷ֘౰ߦʹ
 ίϝϯτΛ౤ߘͤ͞Δ मਖ਼Օॴ͚ͩͷࢦఠͱ$*ʹΑΔࣗಈ࣮ߦ ʮ΍͘͞͠ʯಋೖ͢Δ

  34. ͜͏ͨ͠޻෉΍QIQDCGʹΑΔ
 ࣗಈमਖ਼Λߦͬͯ Ո଒ͷຖ೔Λ΋ͬͱসإʹɻ

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

  36. w  ݅͋ͬͨΤϥʔ͸݅ʹʂ w Τϥʔ͸ফ͕͑ͨϫʔχϯά 8BSOJOH ͕·ͩͭ͋Δ w l(FOFSJD'JMFT-JOF-FOHUIzߦࣈ·Ͱ w

    Զୡͷઓ͍͸͜Ε͔Βͩʂ ͦͷޙͲ͏ͳ͔ͬͨ ͦͷޙ
  37. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ Ո଒ͷຖ೔Λ΋ͬͱসإʹɻ