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
自動で //nolint を挿入する取り組み / Gopher's Gathering
Search
utagawa kiki
January 18, 2025
Programming
1
610
自動で //nolint を挿入する取り組み / Gopher's Gathering
https://connpass.com/event/329963/
utagawa kiki
January 18, 2025
Tweet
Share
More Decks by utagawa kiki
See All by utagawa kiki
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
1.8k
君たちはどうコードをレビューする (される) か / 大吉祥寺.pm
utgwkk
21
14k
Dive into gomock / Go Conference 2024
utgwkk
14
6.9k
Goでリフレクションする、その前に / Kansai.go #1
utgwkk
4
3.1k
Go製Webアプリケーションのエラーとの向き合い方大全、あるいはやっぱりスタックトレース欲しいやん / Kyoto.go #50
utgwkk
7
4.1k
ありがとう、create-react-app
utgwkk
4
11k
mockgenによるモック生成を高速化するツール bulkmockgenのご紹介 / Kyoto.go #43
utgwkk
2
2.3k
SPAでもデータをURLでシェアしたい / Kyoto.js 19
utgwkk
2
1.9k
prototype大全 / YAPC::Kyoto 2023
utgwkk
1
4.5k
Other Decks in Programming
See All in Programming
GitHub Copilot for Azureを使い倒したい
ymd65536
1
300
Laravel × Clean Architecture
bumptakayuki
PRO
0
130
Orleans + Sekiban + SignalR でリアルタイムWeb作ってみた
tomohisa
0
220
カオスに立ち向かう小規模チームの装備の選択〜フルスタックTSという装備の強み _ 弱み〜/Choosing equipment for a small team facing chaos ~ Strengths and weaknesses of full-stack TS~
bitkey
1
130
「理解」を重視したAI活用開発
fast_doctor
0
270
Dissecting and Reconstructing Ruby Syntactic Structures
ydah
3
1.9k
AIコーディングの理想と現実
tomohisa
35
37k
UMAPをざっくりと理解 / Overview of UMAP
kaityo256
PRO
3
1.4k
監視 やばい
syossan27
12
10k
Cursor/Devin全社導入の理想と現実
saitoryc
28
21k
Ruby on Railroad: The Power of Visualizing CFG
ydah
0
290
The Evolution of the CRuby Build System
kateinoigakukun
1
760
Featured
See All Featured
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
34
2.2k
The Straight Up "How To Draw Better" Workshop
denniskardys
233
140k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.4k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
KATA
mclloyd
29
14k
Building Applications with DynamoDB
mza
94
6.4k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
32
5.5k
Navigating Team Friction
lara
185
15k
Side Projects
sachag
453
42k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
52
2.4k
Transcript
自動で //nolint を 挿入する取り組み id:utgwkk / @utgwkk (うたがわきき) 2025/1/18 Gopher's
Gathering 1
自己紹介 (1) • うたがわきき (@utgwkk) ◦ 京都在住 ◦ 実は福岡出身 •
株式会社はてな ◦ Webアプリケーションエンジニア 2
自己紹介 (2) • 好きなパッケージ ◦ reflect ◦ go/ast 3
推しグルメ (1) 元祖 長浜屋 4
推しグルメ (1) 元祖 長浜屋 5
推しグルメ (2) ビアキチ 6
アジェンダ • golangci-lintの //nolint directiveを自動で 挿入するCLIツール autonolint を作った - 私
が歌川です • https://github.com/utgwkk/autonolint 7
golangci-lintについて • https://golangci-lint.run/ • Goのlinterをまとめて実行するrunner • アンケート: golangci-lintを使っている? 8
あらすじ • ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56 9
立ち位置 10 enable-allして disableする disable-allして enableする
立ち位置 11 enable-allして disableする disable-allして enableする ゆるやかに enableする
モチベーション • golangci-lintで有効にするlinterをあとから 増やしたい • 既存のコードが警告されまくる!!! • たすけて〜〜 12
//nolint:xxx • 指定した行 (ブロック) でだけlinterの警告を 抑制するためのコメント (directive) • これを自動で入れていけば勝てる 13
Q. exclude-rulesじゃダメなの • 同じファイル内でも新しく書くコードでは linterを有効にしたい • あとから直すきっかけを作りやすくする ◦ コメントがoutdatedなら解決できるはず ◦
コロケーション的な思想 14
DEMO VSCode開いてください 15
実装 (1) • golangci-lintの実行結果をパース ◦ 実はJSON形式で出力できる ▪ --out-format=json ◦ 入力を加工する機能を丸投げ
16
実装 (2) • //nolint を挿入すべき行を特定 • 行ごとに書き出しつつ //nolint を挿入 ◦
bufio.NewScanner 便利 17
実装 (3) • テストではgolangci-lintを実際に走らせる • autonolintを適用した後のコードで警告が出 ないことを確かめる • E2Eテストみたいな感じですね 18
今後の課題 • うまく動かないパターンもあるかも ◦ 既に別の //nolint が書いてある行とか ◦ 気づいたときに直します 19
関連研究 • https://github.com/mizdra/eslint-intera ctive ◦ eslint-disable-next-lineするかどうかなどを インタラクティブに指定できる ◦ 丁寧 20
まとめ • golangci-lintの //nolint directiveを自動で 挿入するCLIツール autonolint を作った - 私
が歌川です • https://github.com/utgwkk/autonolint 21