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
290
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
9.9k
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
4.9k
Introduction gRPC
daikurosawa
1
240
Go Cloud を触ってみる / gopher-dojo-lt
daikurosawa
2
2.1k
Other Decks in Programming
See All in Programming
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
920
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
330
CSC509 Lecture 12
javiergs
PRO
0
160
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
Better Code Design in PHP
afilina
PRO
0
120
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
subpath importsで始めるモック生活
10tera
0
300
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Fireside Chat
paigeccino
34
3k
A Philosophy of Restraint
colly
203
16k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Automating Front-end Workflow
addyosmani
1366
200k
Designing the Hi-DPI Web
ddemaree
280
34k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
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 దʹઃఆ͢Δ
• ಋೖখ͘͞গͣͭ͠ • ݸਓɺνʔϜʹ߹ΘͤͨΧελϚΠζΛ
͓͠·͍ ʕ ◔ϖ◔ʔ