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

SwiftLint実践入門

 SwiftLint実践入門

2017/10/02 俺コン Day. 1
※2017/10/03 17時頃に資料を上げ直しています。

9d1961575e45a8286cdde5f86dbba312?s=128

akatsuki174

October 02, 2017
Tweet

Transcript

  1. SwiftLint࣮ફೖ໳ @akatsuki174

  2. ࣗݾ঺հ • ਢ౻ຘ • iOSΤϯδχΞ • גࣜձࣾZaimॴଐ • Twitter, Qiita,

    SlideShare, Github, SpeakerDeck →akatsuki174
  3. None
  4. એ఻ 10/13(ۚ)ɺ10/20(ۚ)ͷ2days 19:20ʙ

  5. ͓ئ͍ iOSDCશମɺτʔΫʹର͢ΔΞϯέʔτ΁ͷ ճ౴ΛΑΖ͓͘͠ئ͍͠·͢ʂ

  6. ࠓ೔ͷτʔΫ

  7. ࠓ೔ͷτʔΫ جૅ͸লུɻ࣮຿ͰͲ͏࢖͏ͷ͕ ͍͍͔ʹ͍ͭͯ࿩͠·͢ɻ

  8. ࠓ೔ͷτʔΫ ࢀՃܕͷτʔΫʹͳΓ·͢ʂ͓खݩʹ ࣗ෼ͷ.swiftlint.ymlΛஔ͍͍͚ͯͨͩΔͱɻ

  9. ɾSwiftLintͷ࠷৽ͷ৘ใʹ͍ͭͯ঺հ ɾΈͳ͞ΜͲͷϧʔϧΛͲͷΑ͏ʹ ɹ࠾༻ͯ͠·͔͢ʁ ɾࢲ͕ߟ͑Δ࠷ڧͷ.swiftlint.yml ɾCIपΓͷ࿩ ࠓ೔ͷ֓ཁ

  10. SwiftLintͷ࠷৽৘ใ

  11. ɾϧʔϧ૯਺105 ɾ2015/05/18ʹॳϦϦʔε ɾɾҎ߱ɺ42ճͷϦϦʔεΛॏͶ͍ͯΔ ɾStar਺໿7,700 SwiftLintͷࠓ ※͜͜Ͱͷ৘ใ͸2017/10/02࣌఺Ͱͷ৘ใͰ͢

  12. SwiftLint 1.0.0͸ʁ

  13. SwiftLint0.22 ʢݱࡏͷ࠷৽verʣ

  14. ɾωετ͞Εͨconfigͷѻ͍ͷมߋ ɾɾωετ͞Εͨࢠconfig͸·Δͬͱ ɹɹ਌configͱஔ͖׵ΘΔͷͰ͸ͳ͘ɺ ɹɹ਌ͷconfigͱϚʔδ͞ΕΔ SwiftLint 0.22ͷओཁͳมߋ

  15. ɾωετ͞Εͨconfigͷѻ͍ͷมߋ ɾɾωετ͞Εͨࢠconfig͸·Δͬͱ ɹɹ਌configͱஔ͖׵ΘΔͷͰ͸ͳ͘ɺ ɹɹ਌ͷconfigͱϚʔδ͞ΕΔ SwiftLint 0.22ͷओཁͳมߋ ʁ

  16. ɾલఏ ɾɾҟͳΔ.swiftlint.ymlΛɺҟͳΔ ɹɹσΟϨΫτϦ֊૚ʹஔ͘͜ͱͰ ɹɹͦΕͧΕʹ߹ͬͨϧʔϧΛద༻͢Δ ɹɹ͜ͱ͕Ͱ͖ͨ ωετ͞Εͨconfig

  17. ɾ ᵓᴷᴷ ViewController.swift ᵓᴷᴷ .swiftlint.yml ᵋᴷᴷ Tests ᵋᴷᴷ Test.swift ᵋᴷᴷ

    .swiftlint.yml ਤղ line_length: 110 disabled_rules: - force_cast - force_try
  18. ਌σΟϨΫτϦͱࢠσΟϨΫτϦ྆ํʹ .swiftlint.yml͕͋ͬͨ৔߹ ɾࠓ·Ͱ ɾɾࢠσΟϨΫτϦ಺Ͱ͸ࢠσΟϨΫτϦͷ ɹɹ.swiftlint.yml͔͠ద༻͞Εͳ͔ͬͨ ωετ͞Εͨconfig

  19. ਤղʢैདྷʣ TestsσΟϨΫτϦ಺Ͱద༻͞ΕΔϧʔϧ͸ TestsҎԼʹॻ͔Ε͍ͯΔϧʔϧͷΈ ɾ ᵓᴷᴷ ViewController.swift ᵓᴷᴷ .swiftlint.yml ᵋᴷᴷ Tests

    ᵋᴷᴷ Test.swift ᵋᴷᴷ .swiftlint.yml line_length: 110 disabled_rules: - force_cast - force_try
  20. ɾ0.22Ҏ߱ ɾɾࢠσΟϨΫτϦͱ਌σΟϨΫτϦͷ ɹɹ.swiftlint.yml͕Ϛʔδ͞Εͨ΋ͷ͕ ɹɹࢠσΟϨΫτϦ಺Ͱద༻͞ΕΔ ωετ͞Εͨconfig

  21. ਤղʢ0.22Ҏ߱ʣ ɾ ᵓᴷᴷ ViewController.swift ᵓᴷᴷ .swiftlint.yml ᵋᴷᴷ Tests ᵋᴷᴷ Test.swift

    ᵋᴷᴷ .swiftlint.yml line_length: 110 line_length: 110 disabled_rules: - force_cast - force_try Ϛʔδʂ ࢠσΟϨΫτϦͰ͸਌σΟϨΫτϦͰ ࢦఆ͍ͯ͠Δϧʔϧ΋ద༻͞ΕΔ
  22. ɾmessageͷͳ͍XCTFail͸ڐ༰͠ͳ͍ ɾɾxctfail_message ɾ༨෼ͳdisableίϚϯυ͕ͳ͍͔νΣοΫ ɾɾsuperfluous_disable_command ɾɾʮ// swiftlint:disableʯΛ࢖ͬͯΔ͚Ͳ ɹɹҾ͔͔ͬΔίʔυ͕ͳ͍࣌ʹΤϥʔ SwiftLint 0.22ͷओཁͳมߋ

  23. SwiftLint0.21 ʢ࠷৽verͷ1ͭखલʣ

  24. ɾରԠόʔδϣϯͷมߋ ɾɾXcode 8.3Ҏ্ɺSwift 3.1Ҏ্͕ඞਢ ɾϧʔϧΛੜ੒͢ΔίϚϯυͷ௥Ճ ɾɾswiftlint generate-docs SwiftLint 0.21ͷओཁͳมߋ

  25. ɾΞΫηεम০ࢠʹؔ͢Δϧʔϧͷ௥Ճ ɾɾprivate_over_fileprivate ɾɾɾTopLevelʹ͋Δfileprivate͸private΁ ɾɾstrict_fileprivate ɾɾɾશͯͷfileprivateΛνΣοΫ ɾɾɾSwift4Ͱ໾ʹཱͭ SwiftLint 0.21ͷओཁͳมߋ

  26. ɾઃఆΦϑʹͳ͍ͬͯΔϧʔϧҰཡΛग़ྗ͢Δ ɾɾswiftlint rules - - disabled ɾ৽͍͠ܗࣜͷKVOํࣜͰॻ͍͍ͯΔ͔ ɾɾblock_based_kvo ɾɾʮWhat's New

    in Cocoa TouchʯͰ৽͍͠ ɹɹϒϩοΫϕʔεͷه๏͕঺հ͞Εͨ SwiftLint 0.21ͷओཁͳมߋ
  27. ɾconfigͰ؀ڥม਺͕࢖͑ΔΑ͏ʹ ɾɾ${ԿΒ͔ͷม਺}ͱॻ͚͹OK SwiftLint 0.21ͷओཁͳมߋ

  28. ΈΜͳͷSwiftLintࣄ৘

  29. ɾσϑΥϧτͰ༗ޮʹͳ͍ͬͯΔϧʔϧ ɾσϑΥϧτͰ͸120ӽ͑ͨΒܯࠂɺ200 ɹӽ͑ͨΒΤϥʔ ٞ୊̍ɿline_length

  30. AppDelegateͷ༷͝ࢠ ٞ୊̍ɿline_length

  31. ίϝϯτ௕͗ͯ͢Τϥʔൃੜ ٞ୊̍ɿline_length Έͳ͞ΜͲ͏ͯ͠·͔͢ʁ

  32. ɾͲΜͳͱ͜ΖͰҾ͔͔ͬͬͯΔʁ ɾɾσϑΥͰೖ͍ͬͯΔίϝϯτ ɾɾඪ४ͷϝιου໊ ɾͲΜͳ࣌ʹ௕͍ίʔυΛॻ͍ͯ͠·͏ʁ ɾɾifͳͲͰ৚݅Λෳ਺ฒ΂ͨ࣌ ɾɾifͱreturnΛ1ߦͰ·ͱΊͨ࣌ ٞ୊̍ɿline_length

  33. ɾࢲͷதͰͷ݁࿦ ɾɾඪ४ϝιουͰҾ͔͔ͬΔͳΒ ɹɹແཧʹकΒͳ͍͍ͯ͘ͷͰ͸ʁ ɾɾ120ӽ͑Δ͘Β͍ͷίʔυΛॻ͍ͯ ɹɹ͠·ͬͨΒࣗ෼Ͱదٓվߦ ɾɾline_length͸disableͰ͍͍ͷͰ͸ʁ ٞ୊̍ɿline_length

  34. ɾσϑΥϧτͰ༗ޮʹͳ͍ͬͯΔϧʔϧ ɾߦ຤ʹ༨ܭͳλϒɺۭനจࣈ͕ೖͬͯͨΒ ɹܯࠂ͕ग़Δ ٞ୊̎ɿtrailing_whitespace

  35. ʢXcodeͷઃఆʹ΋ΑΔ͕ʣվߦ࣌ʹࣗಈ Ͱૠೖ͞ΕΔλϒʹ͍͍͍ͭͯͪͪ ݴΘΕΔͷ͸͏͍͟ʢʈωʈ#ʣűƅŝűƅŝ ٞ୊̎ɿtrailing_whitespace Έͳ͞ΜͲ͏ͯ͠·͔͢ʁ

  36. ɾࢲͷதͰͷ݁࿦ ɾɾશۭ֯നจࣈ͸ʮInvalid charactor in ɹɹsource fileʯΤϥʔ͕ग़Δͦ͠Μͳ ɹɹࠔΔ͜ͱͳ͍ͷͰ͸ʁ ɾɾtrailing_whitespace͸disableͰ͍͍ʁ ٞ୊̎ɿtrailing_whitespace

  37. ࢲ͕ߟ͑ͨ࠷ڧͷ .swiftlint.yml

  38. ͝ΊΜͳ͍͞ ؒʹ߹ͬͯͳ͍Ͱ͢

  39. ׬શ൛͸ޙ೔QiitaͰ ΞΧ΢ϯτ͸@akatsuki174Ͱ͢

  40. ࠓ೔͸ద༻ج४ͷ ࿩͚ͩ͠·͢

  41. ɾॻ͘ਓʹΑͬͯ͹Β͖͕ͭग़ͦ͏ͳ ɹࠣࡉͳ෦෼͸ϧʔϧΛద༻ͯ͠Χόʔ ɾɾcolon, comma, empty_parameters etc. ɾ୯ͳΔೖྗϛεͬΆ͍ͱ͜ΖΛࢦఠͯ͠ ɹ͘ΕΔϧʔϧ͸ద༻ ɾɾclosing_brace, closure_spacing

    etc. ద༻ج४
  42. ɾద༻͞Εͯͳ͍ͱෆ֨޷ͳϧʔϧ͸ద༻ ɾɾclosure_end_indentation, ɹɹclosure_parameter_position etc. ɾ৔߹ʹΑΔ΋ͷ͸ෆద༻ɺ΋͘͠͸ ɹ৚݅Λ෇͚Δ ɾɾforce_cast, identifier_name etc. ద༻ج४

  43. ɾ΍Γ͗͢͡ΌͶʁͬͯࢥͬͨΒෆద༻ ɾɾline_length, ɹɹconditional_returns_on_newline etc. ద༻ج४

  44. CIपΓͷ࿩

  45. ɾPRΛग़ͨ࣌͠ʹDanger͕.swiftlint.ymlʹ ɹҾ͔͔ͬͬͯͳ͍͔νΣοΫ ɾɾҾ͔͔͍ͬͬͯͨΒ༰ࣻͳ͘ίϝϯτ ฐࣾͷ৔߹

  46. ɾSwiftLintͷREADME.mdʹfastlaneͷ ɹactionͱͯ͠࢖͑Δͱॻ͔Ε͍ͯΔ fastlane

  47. SwiftLintΛ࢖ͬͯ όϦόϦշద։ൃ͠·͠ΐ͏ʂ

  48. ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ