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
CSC509 Lecture 09
javiergs
PRO
0
140
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Amazon Qを使ってIaCを触ろう!
maruto
0
410
Ethereum_.pdf
nekomatu
0
460
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.7k
CSC509 Lecture 13
javiergs
PRO
0
110
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
230
C++でシェーダを書く
fadis
6
4.1k
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Quine, Polyglot, 良いコード
qnighy
4
650
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
RailsConf 2023
tenderlove
29
900
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Into the Great Unknown - MozCon
thekraken
32
1.5k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Building Applications with DynamoDB
mza
90
6.1k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Building Adaptive Systems
keathley
38
2.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
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 దʹઃఆ͢Δ
• ಋೖখ͘͞গͣͭ͠ • ݸਓɺνʔϜʹ߹ΘͤͨΧελϚΠζΛ
͓͠·͍ ʕ ◔ϖ◔ʔ