$30 off During Our Annual Pro Sale. View Details »
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
300
Helm Chart を Unit Test する / Unit Testing Helm Chart
daikurosawa
0
1.9k
Understanding CPU throttling in Kubernetes to improve application performance #k8sjp
daikurosawa
12
14k
Leader Election in Kubernetes #k8sjp
daikurosawa
5
10k
Argo CD 実践ガイド #k8sjp / Argo CD Practice Guide
daikurosawa
13
8.2k
図で理解する 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
第5回日本眼科AI学会総会_AIコンテスト_3位解法
neilsaw
0
120
Thoughts and experiences on Rust and TypeScript
unvalley
2
200
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
0
160
Arm移行タイムアタック
qnighy
0
400
社内活動の取り組み紹介 ~ スリーシェイクでこんな取り組みしてます ~
bells17
0
380
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
150
eBPF Deep Dive: Architecture and Safety Mechanisms
takehaya
12
1.2k
The rollercoaster of releasing an Android, iOS, and macOS app with Kotlin Multiplatform | droidcon Italy
prof18
0
120
我々のデザインシステムは Chakra v3 にアップデートします
shunya078
2
2.6k
WebAssembly Unleashed: Powering Server-Side Applications
chrisft25
0
2.1k
TypeScript でバックもやるって実際どう? 実運用で困ったこと3選
yuichiro_serita
17
7.5k
Remix on Hono on Cloudflare Workers
yusukebe
1
390
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
How GitHub (no longer) Works
holman
310
140k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Building Applications with DynamoDB
mza
90
6.1k
Being A Developer After 40
akosma
87
590k
GitHub's CSS Performance
jonrohan
1030
460k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
For a Future-Friendly Web
brad_frost
175
9.4k
A Modern Web Designer's Workflow
chriscoyier
693
190k
BBQ
matthewcrist
85
9.3k
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 దʹઃఆ͢Δ
• ಋೖখ͘͞গͣͭ͠ • ݸਓɺνʔϜʹ߹ΘͤͨΧελϚΠζΛ
͓͠·͍ ʕ ◔ϖ◔ʔ