Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
チームで運用する golangci-lint の向き合い方
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Sugar Sato
June 14, 2024
Programming
2.4k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
チームで運用する golangci-lint の向き合い方
LTで発表しきれなかったスライドが含まれています。
(20分以上いってしまうくらい、まだ喋れます....)
Sugar Sato
June 14, 2024
Transcript
55 slides
チームで運用する golangci-lint の向き合い方 golang.tokyo #35 2024.06.14
自己紹介 Sugar Sato (@satoIsSugar) • 2023年 BuySell Technologies 入社 •
基盤チーム所属 (Portal/Account) PjM • Go / Angular / Serverless ◦ Go歴: 4年くらい • 熱帯植物 ◦ ビカクシダ • 猫 ◦ Lambda (♀ 2才)
プロダクト群「バイセルリユースプラットフォーム Cosmos」の開発が進行中 リユースに必要なすべての機能を提供する 「リユースプラットフォーム Cosmos」の開発が進行中です。 Cosmosを活用して、バイセルグループ全体での業務効率改善やデータドリブン経営の深化を目指しています。 リユースプラットフォーム Cosmos 自社開発のリユース特化業務基幹システムでありサービス群の集合体 買取申込
買取・査定 在庫管理 販売 多様なチャネルで収益最大化 CRM -顧客対応- 買取種別に応じた最適なシステム構築 Visit -訪問買取 - Store -店舗買取 - Promas -商材マスタ - Appraisal -専門査定 - Stock -在庫管理 - EXS -販売管理 - Core -会員管理- Portal -データ利用- Pocket -データ基盤- 買取 専門チームによる真贋・査定と連携 査定 申込 効率的な顧客対応 在庫 在庫管理の最適・効率化 販売 データ 各事業プロセスにある データを一元管理 :基幹システム
None
みなさんは golangci-lint 導入してますか?
YES!!
どんなルールで運用してますか? なんとなく雰囲気で使っていませんか?
僕はそうでした😅 なので立ち返って運用ルールや チームでの向き合い方を考えてみました!
アジェンダ golangci-lint とは 01 実際の取り組み 02 まとめ 03
golangci-lint とは
• 高速リンターランナー ◦ 最初に解析したパスのディレクトリからルートまでの全てのディレ クトリにある設定ファイルを探す ◦ 使い方 ▪ ルールを追加する •
.golangci.(yml|yaml|json|toml) ▪ コマンド実行 • $ golangci-lint -v run ./... golangci-lint
• 5つの設定 ◦ run (解析時の設定) ◦ output (解析結果の出力設定) ◦ linters
(lintの設定) ▪ linters-settings ◦ issues (除外設定) ◦ severity (issue 重大度設定) 設定ファイル( .golangci.yml )について
run configuration • go • concurrency • timeout • issues-exit-code
• tests • build-tags • etc…
output configuration • sort-results • sort-order • formats • print-issued-lines
• print-issued-name • etc…
linters configuration • disable-all • enable • enable-all • disable
• presets • fast
issues configuration • exclude-rules • exclude-files • exclude-dirs • exclude
• exclude-use-default • exclude-generated • etc…
severity configuration • default-severity • case-sensitive • rules ◦ linters
◦ severity
golangci-lint コントリビュータ • sanposhiho さん • sivchari さん • karamaru-alpha
さん ◦ Goconf 2024 で copyloopvar 等について登壇! ▪ めっちゃ良かった....(小並) • etc…
実際の取り組み
• 必要最低限の設定 ◦ run ◦ linters ▪ linters-settings ◦ issues
自分たちの .golangci.yml
• 必要最低限の設定 ◦ run ◦ linters ▪ linters-settings ◦ issues
自分たちの .golangci.yml
• 必要最低限の設定 ◦ run ◦ linters ▪ linters-settings ◦ issues
自分たちの .golangci.yml
• 基本的に disable-all で運用 ◦ 保守的な運用 ◦ デフォルトのルールは全て適用す る ◦
メリット ▪ 気軽に golangci-lint のバー ジョン挙げられる ◦ デメリット ▪ 考慮漏れが発生するかも linters の運用方法
• enable の中でも Must と Should に分 けてルールを適用している ◦ Must
▪ golangci-lint のデフォルト true のオプション ◦ Should ▪ 自分たちとしてコード品質を保 つためのオプション linters の運用方法
• 「課題が出たタイミング」 ◦ 最近はルール追加することは少ない ▪ 運用が安定してきた証拠? ▪ (最新の追加されたルールを追えてないだけ...??) ルール追加の基準
• チームメンバーと制約について目線合わせする • “納得感”あるルール作りをしていく ◦ 自分本位なルールではないか ◦ 本当に必要なルールか ▪ 実際に導入してみたら却って「開発効率」を下げていないか
▪ もしチームにフィットしなくてメリットがなければ思い切って削 除する ルール追加にあたって気をつけていること
チームの運用方法については、わかった じゃあ、どんなルールを採用しているの?
• lll • gocyclo • goconst • nestif • tagliatelle
enable に採用しているルール
• lll • gocyclo • goconst • nestif • tagliatelle
enable に採用しているルール
• 一行あたりの文字数制限 (long line linter) • Go は1行のあたりの文字数を明確に決めていない ◦ https://go.dev/doc/effective_go#formatting
• PHP ◦ PSR-12: 80文字 or 120文字 • Java ◦ Oracle: 80文字 ◦ Google: 100文字 lll
• 自分のチームでは ◦ line-length: 140文字 ▪ 公式の推奨に合わせている ▪ デフォルト120文字 ◦
tab-width: 2 • ignore 設定はテストでも適用しない ◦ 可読性を担保する ◦ コードレビューの負担を減らす lll
• lll • gocyclo • goconst • nestif • tagliatelle
enable に採用しているルール
• 循環複雑度 (cyclomatic) ◦ 関数のソースコードを通る直 線的に独立したパスの数を数 値にしたもの ◦ 詳しい仕様については下記 ▪
https://github.com/fzipp/ gocyclo/tree/main gocyclo
enable に採用しているルール • lll • gocyclo • goconst • nestif
• tagliatelle
• 定数で置き換え可能な繰り返し文字列を指摘 ◦ デフォルト 3回繰り返しまで許可する ◦ 割とお気に入りのルール ▪ 気がつかないうちに全く同じ変数を書いて いたりするため
▪ ignore ルール設定も網羅している goconst
goconst
enable に採用しているルール • lll • gocyclo • goconst • nestif
• tagliatelle
• if のネスト回数制御 ◦ デフォルト 5回以上のネストを許可しない ◦ とりあえずいれておくだけで OK! ▪
不要なレビューが減る nestif
nestif
enable に採用しているルール • lll • gocyclo • goconst • nestif
• tagliatelle
• 読み方:タリアテッレ • タグ名の制御 ◦ field 名と一致させている ◦ json から
envconfig まで対応して いる ▪ https://golangci-lint.run/usa ge/linters/#tagliatelle tagliatelle
• タグの記述間違いに気が付き やすく、お気に入り • ただし、独自の命名ケースなど には対応していない tagliatelle
以上が linters に適用しているルール
• 必要最低限の設定 ◦ run ◦ linters ▪ linters-settings ◦ issues
自分たちの .golangci.yml
• 基本的に ignore ルールを適用しない方針 ◦ テストコードもプロダクションコード同様に扱い品質を保ちたい ◦ どうしても ignore ルールを追加したい時はチームで相談する
◦ lint 対象ファイルに勝手に ignore ルールを追加しない issues
• ファイル単位で ignore ルールを追 加しない ◦ 部分的に // nolint:ルール名 を
追加して適用する ◦ チーム相談の上で記述 issues
以上が issues の運用方法
• レビューの工数を ”少し” でも減らせる ◦ PR で「わざわざコメントするほどではないか」をなくせる ▪ 心理的負担を減らせる ◦
記述が統一されやすくなり可読性向上がみこめる ◦ Go を初めて書くメンバーも「記述が、ぶれにくくて良い」との声も 上がる golangci-lint のメリット
• gofmt とあわせて lint ルールから自動で修正してもらえるといいなぁ (願望) • 参画してくるメンバーへ lint ルール浸透が必要
◦ より改善できるチャンス! 今後の展望や課題
まとめ
• チームでの運用においては、最小限の設定で効果的に利用する ◦ 各設定の適用ルールや除外ルールを柔軟に調整することが重 要だと感じている • 課題感や改善できる箇所も存在している ◦ tagliatelle などに独自ルール追加ができないので自作できたら
いいな ◦ disable-all を使っているので、本来自分たちにピッタリなルール があるかもしれないが見逃している可能性がある まとめ
• golangci-lintの導入により、コード品質の向上やレビュー負担の軽減 といったメリットも享受できている ◦ これにより、開発プロセスがスムーズになり、新しいメンバーも記 述のぶれが少なくて済むと感じている まとめ
• 導入していなかった人は、ぜひ導入を! • 導入している人は ◦ おすすめの運用方法や、これ適用してないの?など会話した い! みなさんの .golangci.yml はどうですか?
THANK YOU
• https://github.com/golangci/golangci-lint • https://github.com/golangci/golangci-lint/blob/master/assets/go.png • https://www.docswell.com/s/takanakahiko/ZQ864X-2024-05-11-022041#p11 • https://golangci-lint.run/usage/linters/#tagliatelle • https://go.dev/doc/effective_go#formatting
• https://www.php-fig.org/psr/psr-12/#23-lines • https://google.github.io/styleguide/javaguide.html#s3.2-package-statement 引用
More Decks by Sugar Sato
See All by Sugar Sato
AIと共に生きる技術選定 2026
sgash708
0
370
Bref でサービスを運用している話
sgash708
0
370
tool ディレクティブを導入してみた感想
sgash708
1
320
DeepWiki で Go をもっと好きになろう
sgash708
0
1.1k
環境変数ライブラリ選手権
sgash708
0
360
はじめての Go * WASM * OCR
sgash708
1
470
もう僕は OpenAPI を書きたくない
sgash708
6
2.8k
【懺悔】1年目 EM の失敗から学ぼう
sgash708
0
290
testcontainers のススメ
sgash708
1
580
Other Decks in Programming
See All in Programming
疎結合とは何か?ソフトウェア設計における結合バランスについて考える #phpcon_niigata
kajitack
1
200
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
330
Beyond Chatbots: Agentic UI with Open Standards @W-JAX 2026, München
manfredsteyer
PRO
0
100
作れるエンジニアから、価値を届けるエンジニアへ
ryunakayama
1
290
Scalaの型でマルチテナントの認可を守る
nextbeatdev
0
150
手の動かし方がわからなかった私が個人開発者になるまで
usagi0920_pochi
0
100
TS 7.0 で baseUrl が使えなくなった今、パスエイリアスをどうするか
bicstone
2
670
AI時代のIaC入門 〜なぜインフラをコードで管理したいのか?〜 / Introduction to IaC in the AI Era
akihisaikeda
6
1.5k
Kotlin Fest 2026: Kotlin コンパイラに Contribute してみよう! - Kotlin/Wasm で深い再帰を書けるようにした話
ternbusty
1
200
Getting Started with Vibe Coding
miccheng
0
230
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
180
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
140
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
50
15k
Practical Orchestrator
shlominoach
192
12k
Deep Space Network (abreviated)
tonyrice
0
420
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
320
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
1
240
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
400
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
610
It's Worth the Effort
3n
188
29k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
540
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1.1k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k