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

GolangCI を使ってコードの品質を保ちながら快適な Golang 生活を送る話 #go...

d-kuro
January 31, 2019

GolangCI を使ってコードの品質を保ちながら快適な Golang 生活を送る話 #gounco / GolangCI

Go(Un)Conference(Goあんこ)LT大会 5kg で発表した資料です
https://gounconference.connpass.com/event/112942/

d-kuro

January 31, 2019
Tweet

More Decks by d-kuro

Other Decks in Programming

Transcript

  1. GolangCI ͱ͸ • GitHub ͷ Pull Request ͷ໰୊Λݕ஌ͯ͠ίϝϯτͯ͘͠ΕΔ Golang ༻

    ͷ CI αʔϏε • ͍ΖΜͳ Linter Λ࣮ߦͯ͘͠ΕΔ • OSS ͳΒແྉͰ࢖͑Δ • Private Repo ͸1Ϣʔβ $20/mo • GolangCI ࣗମ΋ OSS ͳͷͰιʔε͕શ෦ެ։͞Ε͍ͯΔ • https://github.com/golangci Image From: https://golangci.com/
  2. ࣮ߦͯ͘͠ΕΔ Linter • શ 31 छྨ (19/01/31 ݱ࣌఺ ͷυΩϡϝϯτ্) •

    ΊͬͪΌ͋Δ • ࣮ࡍ͸ Linter ͕ merge ͞ΕͨΓͯ͠ΔͷͰਖ਼֬ͳछྨ਺ ͱͯ͠͸΋ͬͱগͳ͔ͬͨΓ͢Δ • جຊͷ gofmt, goimports, govet ͔Β
 errorcheck ͳͲҰൠతʹ࢖ΘΕͯͦ͏ͳ΋ͷ͸໢ཏ͞Ε ͯΔ͸ͣ
  3. Golang-CI Lint • ϩʔΧϧͰ GolangCI Ͱಈ͘ Lint Λ࣮ߦͰ͖Δ • CircleCI

    ͳͲͷ CI αʔϏεʹ૊ΈࠐΉ • VSCode ͳͲͷΤσΟλͱ౷߹Ͱ͖Δ • ࣅͨΑ͏ͳ Linter ʹ gometalinter ͕ଘࡏ͢Δ͕ͦΕΑΓ΋ߴ଎ʹಈ࡞ ͢Δͷ͕ಛ௃ • ଞʹ΋৭ʑվળ͞Ε͍ͯΔ (ޙड़) • Istio ΍ kustomize Ͱ࢖ΘΕ͍ͯͨΓ͢Δ
  4. gometalinter ͱͷൺֱ • 2 ~ 7ഒ͘Β͍଎͍ • 26%͘Β͍ϝϞϦফඅ͕গͳ͍ • ฏߦॲཧ਺ͪΌΜͱ੍ޚͰ͖Δ

    • ग़ྗϑΥʔϚοτΛΧελϚΠζͰ͖Δ • আ֎ϦετͳͲΛ࢖ͬͯҰൠతͳޡݕ஌ʹରԠ • Git ͷεςʔδϯά, τϥοΩϯά͞Εͯͳ͍ϑΝΠϧͷΈʹ࣮ߦ,
 ಛఆͷϦϏδϣϯҎ߱ͷίϛοτʹର࣮ͯ͠ߦΈ͍ͨͳઃఆ͕Ͱ͖ΔͷͰେن໛ͳίʔυ ϕʔεʹ΋ಋೖ͕Ͱ͖Δ • Linter ͷݸผͷΠϯετʔϧ͕ෆཁͰ GolangCI-Lint ͚ͩΠϯετʔϧ͢Ε͹Α͍ • YAML Ͱઃఆ͕Ͱ͖Δ From: https://github.com/golangci/golangci-lint#golangci-lint-vs-gometalinter
  5. Lint ͸ద੾ʹ࢖͏ • ݫ͗͢͠Δ Lint ͸ෛ୲ʹͳΔ • ಛʹ CI ͷϫʔΫϑϩʔʹ૊Έࠐ·Ε͍ͯΔ৔߹

    ͸ڧ੍ྗ͕͋ΔͷͰ஫ҙ͢Δ • νʔϜ։ൃͷ৔߹ͳͲ͸ແཧͳ͘औΓ૊ΊΔΑ͏ɺ খ͘͞গͣͭ͠ಋೖͯ͘͠ • ద੾ͳબ୒ɺΧελϚΠζΛ͠Α͏
  6. @ponde_m ͷීஈ • ΘΓͱ೴ࢮͯ͠Δ • ແޮʹ͍ͯ͠Δ Linter • gochecknoglobals •

    άϩʔόϧείʔϓͷม਺͕͋ͬͨΒౖΒΕΔ • gochecknoinits • init ؔ਺͕͋ͬͨΒౖΒΕΔ
  7. ϝϧΧϦ͞Μ From: Microservices implementation guide in Go at Mercari Inc


    (https://speakerdeck.com/ygnmhdtt/microservices-implementation-guide-in-go-at-mercari-inc?slide=27)
  8. golint • Effective Go ΍ CodeReviewComments ʹج͍ͮ ͯίʔσΟϯάελΠϧΛࢦఠͯ͘͠ΕΔ From: Effective

    Go
 (https://golang.org/doc/effective_go.html)
 From: CodeReviewComments
 (https://github.com/golang/go/wiki/CodeReviewComments)