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
役立つログに取り組もう
irof
26
8.6k
Kotlin2でdataクラスの copyメソッドを禁止する/Data class copy function to have the same visibility as constructor
eichisanden
1
130
Nuxtベースの「WXT」でChrome拡張を作成する | Vue Fes 2024 ランチセッション
moshi1121
1
510
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
230
破壊せよ!データ破壊駆動で考えるドメインモデリング / data-destroy-driven
minodriven
16
4k
CPython 인터프리터 구조 파헤치기 - PyCon Korea 24
kennethanceyer
0
240
のびしろを広げる巻き込まれ力:偶然を活かすキャリアの作り方/oso2024
takahashiikki
1
410
CSC509 Lecture 09
javiergs
PRO
0
100
Outline View in SwiftUI
1024jp
1
110
飲食業界向けマルチプロダクトを実現させる開発体制とリアルな現状
hiroya0601
1
390
推し活としてのrails new/oshikatsu_ha_iizo
sakahukamaki
3
1.7k
Android 15 でアクションバー表示時にステータスバーが白くなってしまう問題
tonionagauzzi
0
140
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
404
65k
Being A Developer After 40
akosma
86
590k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Adopting Sorbet at Scale
ufuk
73
9k
Visualization
eitanlees
144
15k
The Invisible Side of Design
smashingmag
297
50k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
22k
Embracing the Ebb and Flow
colly
84
4.4k
We Have a Design System, Now What?
morganepeng
50
7.2k
The Pragmatic Product Professional
lauravandoore
31
6.3k
Writing Fast Ruby
sferik
626
61k
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 దʹઃఆ͢Δ
• ಋೖখ͘͞গͣͭ͠ • ݸਓɺνʔϜʹ߹ΘͤͨΧελϚΠζΛ
͓͠·͍ ʕ ◔ϖ◔ʔ