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

20170605_make_and_learn_minimum_golint.pdf

Masayuki Morita
June 05, 2017
43

 20170605_make_and_learn_minimum_golint.pdf

Masayuki Morita

June 05, 2017
Tweet

Transcript

  1. ࡞ֶͬͯͿ
    ϛχϚϜgolint
    @minamijoyo
    2017/06/05

    View full-size slide

  2. ࣗݾ঺հ
    • ৿ా ਅ೭ (Masayuki Morita)
    • Twitter/GitHub: @minamijoyo
    • CrowdWorks Inc.
    • Πϯϑϥ୲౰
    • ͍͍ͩͨAWS/Terraform/Dockerͱ͔͍ͬͯ͡Δ

    View full-size slide

  3. Πϯϑϥ୲౰͕ࠓ͙͢
    GoΛֶͿ΂͖3ͭͷཧ༝
    1. Go੡ϛυϧ΢ΣΞ΍CLIπʔϧ͕૿͖͑ͯͨɻ
    2. bashεΫϦϓτͭΒ͍ɻGo͸ॻָ͍͍ͯͯ͠ɻ
    3. Gopher͘Μ͕͔Θ͍͍ɻ
    The Go gopher was designed by Renée French.

    View full-size slide

  4. ࠓ೔ͷςʔϚ:
    ࠷ۙɺgolintͰ༡ΜͰΈͨ࿩

    View full-size slide

  5. golintͯ͠·͔͢ʁ

    View full-size slide

  6. golint
    • ެࣜͷLinter
    • GoͬΆ͘ͳ͍ίʔσΟϯάελΠϧΛࢦఠ
    $ go get -u github.com/golang/lint/golint

    View full-size slide

  7. $ golint main.go
    main.go:6:2: var instanceId should be instanceID

    View full-size slide

  8. Ͳ͏΍ͬͯ൑ఆͯ͠Δͷ͔ʁ

    View full-size slide

  9. ͨͩͷࣙॻͩͬͨ
    (※࣮ࡍʹ͸୯ޠͷ్தͷ΋ͷ΋ݕग़͍ͯ͠ΔͷͰগ͠ෳࡶʣ
    https://github.com/golang/lint/blob/master/lint.go

    View full-size slide

  10. ͔͠͠
    golintͷίʔυΛͨͩோΊͯͯ΋
    ੩తղੳ͕
    ॳ৺ऀʹΑ͘Θ͔ΒΜͷͰ͢

    View full-size slide

  11. ͦ͏ͩ
    golint࡞Ζ͏

    View full-size slide

  12. ϓϩάϥϛϯάֶशͷجຊ:
    ·ͶΔ

    View full-size slide

  13. ࡞ֶͬͯͿ golint

    View full-size slide

  14. ϛχϚϜͳཁ݅
    • ػೳɿಛఆͷม਺໊Λ୳͢
    • ೖྗɿ1ϑΝΠϧͷΈҾ਺ͰϑΝΠϧ໊Λ౉͢
    • ग़ྗɿϚονͨ͠ϑΝΠϧ໊:ߦ਺:ΧϥϜΛදࣔ

    View full-size slide

  15. 80ߦ͙Β͍Ͱॻ͚ͨ

    View full-size slide

  16. ←ඪ४ͷgoύοέʔδΛ࢖͏
    ↓Ҿ਺ͰೖྗϑΝΠϧ໊Λ΋Β͏

    View full-size slide

  17. ↓ϑΝΠϧΛύʔεͯ͠ASTΛऔಘ

    View full-size slide

  18. ↑ࠨลͷࣝผࢠΛऔΓग़ͯ͠νΣοΫ
    ↑ASTΛ࠶ؼతʹ୳ࡧ
    ←ม਺୅ೖࣜΛ୳͢visitor

    View full-size slide

  19. ↑ม਺໊ʹϚονͨ͠ΒҐஔΛग़ྗ
    ←୳͢ม਺໊ͷఆٛ

    View full-size slide

  20. ม਺wallyΛ୳ͤ

    View full-size slide

  21. wally + golint = wallint

    View full-size slide

  22. $ wallint data/wally.go
    data/wally.go:6:2: wally was found

    View full-size slide

  23. ͔ͤͬ͘ͳͷͰ
    ΤσΟλʹ૊ΈࠐΜͰΈͨ

    View full-size slide

  24. ม਺wallyΛ୳ͤ

    View full-size slide

  25. ҰॠͰӅΕͨม਺wallyΛݕग़

    View full-size slide

  26. ·ͱΊ
    • ϓϩάϥϛϯάͷجຊ͸·ͶΔ͜ͱ
    • ࡞ֶͬͯͿͱཧղ͕ਂ·Δ
    • આ໌ʹ࢖ͬͨίʔυˣ
    • https://github.com/minamijoyo/wallint

    View full-size slide