Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
GolangCI を使ってコードの品質を保ちながら快適な Golang 生活を送る話 #go...
Search
d-kuro
January 31, 2019
Programming
4
5.8k
GolangCI を使ってコードの品質を保ちながら快適な Golang 生活を送る話 #gounco / GolangCI
Go(Un)Conference(Goあんこ)LT大会 5kg で発表した資料です
https://gounconference.connpass.com/event/112942/
d-kuro
January 31, 2019
Tweet
Share
More Decks by d-kuro
See All by d-kuro
kube-state-metrics Sharding
daikurosawa
0
310
Helm Chart を Unit Test する / Unit Testing Helm Chart
daikurosawa
0
2k
Understanding CPU throttling in Kubernetes to improve application performance #k8sjp
daikurosawa
12
15k
Leader Election in Kubernetes #k8sjp
daikurosawa
5
10k
Argo CD 実践ガイド #k8sjp / Argo CD Practice Guide
daikurosawa
13
8.3k
図で理解する Descheduler #k8sjp #ymju / Introduction to Descheduler
daikurosawa
12
23k
Kubernetes のソースコードとの付き合い方 #gounco / Kubernetes source code reading
daikurosawa
24
5k
Introduction gRPC
daikurosawa
1
250
Go Cloud を触ってみる / gopher-dojo-lt
daikurosawa
2
2.1k
Other Decks in Programming
See All in Programming
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
250
たのしいparse.y
ydah
3
120
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
300
Refactor your code - refactor yourself
xosofox
1
260
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
Criando Commits Incríveis no Git
marcelgsantos
2
170
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
690
Full stack testing :: basic to basic
up1
1
930
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Automating Front-end Workflow
addyosmani
1366
200k
Embracing the Ebb and Flow
colly
84
4.5k
Docker and Python
trallard
42
3.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Optimizing for Happiness
mojombo
376
70k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Transcript
GolangCI Λͬͯ ίʔυͷ࣭Λอͪͳ͕Β շదͳ Golang ੜ׆ΛૹΔ 19/01/31 Go(Un)ConferenceʢGo͋Μ͜ʣLTେձ 5kg Dai
Kurosawa / @ponde_m
Introduce
Έͳ͞ΜɺLint ͬͯ·͔͢
ઌͷ golang.tokyo #21 Ͱ͜Μͳ͓͕͋Γ·ͨ͠
՝ͷϑΟʔυόοΫ From: 34ਓͷGoͷ՝ΛϨϏϡʔͯ͠ײͨ͜͡ͱ (https://docs.google.com/presentation/d/1TAwxT9mRmiEjQOZurz-TbXc8SQf0mlEJDS8tL49Q-M4)
՝ͷϑΟʔυόοΫ From: 34ਓͷGoͷ՝ΛϨϏϡʔͯ͠ײͨ͜͡ͱ (https://docs.google.com/presentation/d/1TAwxT9mRmiEjQOZurz-TbXc8SQf0mlEJDS8tL49Q-M4)
πʔϧ͍͖ͬͯ·͠ΐ͏ʂ
ࠓ͍ͭ͜ͷͰ͢
GolangCI ? ʕ ◔ϖ◔ʔ
GolangCI ͱ • GitHub ͷ Pull Request ͷΛݕͯ͠ίϝϯτͯ͘͠ΕΔ Golang ༻
ͷ CI αʔϏε • ͍ΖΜͳ Linter Λ࣮ߦͯ͘͠ΕΔ • OSS ͳΒແྉͰ͑Δ • Private Repo 1Ϣʔβ $20/mo • GolangCI ࣗମ OSS ͳͷͰιʔε͕શ෦ެ։͞Ε͍ͯΔ • https://github.com/golangci Image From: https://golangci.com/
࣮ߦͯ͘͠ΕΔ Linter • શ 31 छྨ (19/01/31 ݱ࣌ ͷυΩϡϝϯτ্) •
ΊͬͪΌ͋Δ • ࣮ࡍ Linter ͕ merge ͞ΕͨΓͯ͠ΔͷͰਖ਼֬ͳछྨ ͱͯͬ͠ͱগͳ͔ͬͨΓ͢Δ • جຊͷ gofmt, goimports, govet ͔Β errorcheck ͳͲҰൠతʹΘΕͯͦ͏ͳͷཏ͞Ε ͯΔͣ
࣮ߦΠϝʔδ
͍ํ • https://golangci.com/ ʹߦͬͯ GitHub ೝূͯ͠ϦϙδτϦબ ͢Δ͚ͩ • 30 ඵͰऴΘΔͷͰΈΜͳΖ͏ʂ
ద༻͢Δ Linter ͷΧελϚΠζ • .golangci.yml ʹ৭ʑॻ͍ͯ͋͛Δ • σϑΥϧτͩͱແޮʹͳ͍ͬͯΔ Linter ͕݁ߏଟ͍ͷͰҙ
• https://github.com/golangci/golangci- lint#enabled-by-default-linters
Ͱ Linter CI ͚ͩͰͳ͘ ϩʔΧϧͰಈ͔͍ͨ͠ (push ͠ͳ͍ͱ݁ՌݟΕͳ͍ͷͩΔ͍)
GolangCI-Lint
Golang-CI Lint • ϩʔΧϧͰ GolangCI Ͱಈ͘ Lint Λ࣮ߦͰ͖Δ • CircleCI
ͳͲͷ CI αʔϏεʹΈࠐΉ • VSCode ͳͲͷΤσΟλͱ౷߹Ͱ͖Δ • ࣅͨΑ͏ͳ Linter ʹ gometalinter ͕ଘࡏ͢Δ͕ͦΕΑΓߴʹಈ࡞ ͢Δͷ͕ಛ • ଞʹ৭ʑվળ͞Ε͍ͯΔ (ޙड़) • Istio kustomize ͰΘΕ͍ͯͨΓ͢Δ
gometalinter ͱͷൺֱ From: https://github.com/golangci/golangci-lint#golangci-lint-vs-gometalinter
gometalinter ͱͷൺֱ • 2 ~ 7ഒ͘Β͍͍ • 26%͘Β͍ϝϞϦফඅ͕গͳ͍ • ฏߦॲཧͪΌΜͱ੍ޚͰ͖Δ
• ग़ྗϑΥʔϚοτΛΧελϚΠζͰ͖Δ • আ֎ϦετͳͲΛͬͯҰൠతͳޡݕʹରԠ • Git ͷεςʔδϯά, τϥοΩϯά͞Εͯͳ͍ϑΝΠϧͷΈʹ࣮ߦ, ಛఆͷϦϏδϣϯҎ߱ͷίϛοτʹର࣮ͯ͠ߦΈ͍ͨͳઃఆ͕Ͱ͖ΔͷͰେنͳίʔυ ϕʔεʹಋೖ͕Ͱ͖Δ • Linter ͷݸผͷΠϯετʔϧ͕ෆཁͰ GolangCI-Lint ͚ͩΠϯετʔϧ͢ΕΑ͍ • YAML Ͱઃఆ͕Ͱ͖Δ From: https://github.com/golangci/golangci-lint#golangci-lint-vs-gometalinter
gometalinter ͱͷൺֱ From: https://github.com/golangci/golangci-lint#comparison-with-gometalinter
ΊͬͪΌൺֱͯ͠Δ
Φεεϝͷ͍ํ (?) • ࢮͰ enable-all • શ෦ͷ Linter ͕ಈ͘
ͱݴ͍͍ͨͱ͜Ζ͚ͩͲ ྲྀੴʹͭΒ͍
ͭΒ͍ྫ • gochecknoinits • init ͕ؔ͋ΔͱౖΒΕΔ From: https://github.com/leighmcculloch/gochecknoinits
Lint దʹ͏ • ݫ͗͢͠Δ Lint ෛ୲ʹͳΔ • ಛʹ CI ͷϫʔΫϑϩʔʹΈࠐ·Ε͍ͯΔ߹
ڧ੍ྗ͕͋ΔͷͰҙ͢Δ • νʔϜ։ൃͷ߹ͳͲແཧͳ͘औΓΊΔΑ͏ɺ খ͘͞গͣͭ͠ಋೖͯ͘͠ • దͳબɺΧελϚΠζΛ͠Α͏
Ͳͷ Linter Λ͏
@ponde_m ͷීஈ • ΘΓͱࢮͯ͠Δ • ແޮʹ͍ͯ͠Δ Linter • gochecknoglobals •
άϩʔόϧείʔϓͷม͕͋ͬͨΒౖΒΕΔ • gochecknoinits • init ͕ؔ͋ͬͨΒౖΒΕΔ
͜ͷ··ͩͱ ͋·ΓࢀߟʹͳΒͳ͍ͷͰ
͍ͬͯΔ Linter Λ ެ։͍ͯ͠Δձࣾ͞Μͷհ
ϝϧΧϦ͞Μ From: Microservices implementation guide in Go at Mercari Inc
(https://speakerdeck.com/ygnmhdtt/microservices-implementation-guide-in-go-at-mercari-inc?slide=27)
αΠϘζ͞Μ From: Neco ϓϩδΣΫτͷεΩϧνΣοΫγʔτ (https://gist.github.com/ymmt2005/bd92296166e52d1beba9df8ac516a9db)
͔͜͜Β ࠓग़͖ͯͨ Linter + ͓͢͢Ί Linter ͷ հίʔφʔ
gofmt • ίʔυܗ • جຊ
gofmt -s • -s ΦϓγϣϯΛ͚ͭΔͱίʔυΛγϯϓϧʹͯ͘͠ΕΔ
goimports • gofmt + import ͷमਖ਼Λͯ͘͠ΕΔ • جຊ
golint • Effective Go CodeReviewComments ʹج͍ͮ ͯίʔσΟϯάελΠϧΛࢦఠͯ͘͠ΕΔ From: Effective
Go (https://golang.org/doc/effective_go.html) From: CodeReviewComments (https://github.com/golang/go/wiki/CodeReviewComments)
govet • ίϯύΠϥ͕ݕग़ͯ͘͠Εͳ͍ΤϥʔΛࢦఠͯ͘͠ΕΔ
errcheck • error ͷϋϯυϦϯάͯ͠ͳ͍ͱౖΒΕΔ
staticcheck • αʔυύʔςΟ͚ͩͲ৭ʑͳΛݕͯ͘͠ΕΔ • govet ͬΆ͍ͭ • νΣοΫͯ͘͠ΕΔͷຊʹ৭ʑ͋ΔͷͰυΩϡϝϯτࢀর • https://staticcheck.io/docs/checks
misspell • ίϝϯτͷεϖϧϛεΛݟ͚ͭͯ͘ΕΔ
interfacer • ͜͜ͷҾΠϯλϑΣʔεʹͰ͖ΔΑΈ͍ͨͳͷΛڭ͑ͯ͘ΕΔ
prealloc • ࣄલʹׂΓͯՄೳͳεϥΠεΛݟ͚ͭͯ͘ΕΔ
lll • 1ߦ͗͢Λڭ͑ͯ͘ΕΔ
·ͱΊ
·ͱΊ • GolangCI-Lint ୯ମͰ·ͱΊͯ Linter Λ࣮ߦ Ͱ͖ΔΠέͯΔπʔϧ • Linter దʹઃఆ͢Δ
• ಋೖখ͘͞গͣͭ͠ • ݸਓɺνʔϜʹ߹ΘͤͨΧελϚΠζΛ
͓͠·͍ ʕ ◔ϖ◔ʔ