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
880
自動で //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
2.1k
君たちはどうコードをレビューする (される) か / 大吉祥寺.pm
utgwkk
21
15k
Dive into gomock / Go Conference 2024
utgwkk
14
7.3k
Goでリフレクションする、その前に / Kansai.go #1
utgwkk
4
3.4k
Go製Webアプリケーションのエラーとの向き合い方大全、あるいはやっぱりスタックトレース欲しいやん / Kyoto.go #50
utgwkk
7
4.1k
ありがとう、create-react-app
utgwkk
4
11k
mockgenによるモック生成を高速化するツール bulkmockgenのご紹介 / Kyoto.go #43
utgwkk
2
2.4k
SPAでもデータをURLでシェアしたい / Kyoto.js 19
utgwkk
2
1.9k
prototype大全 / YAPC::Kyoto 2023
utgwkk
1
4.6k
Other Decks in Programming
See All in Programming
The Niche of CDK Grant オブジェクトって何者?/the-niche-of-cdk-what-isgrant-object
hassaku63
1
690
AI駆動のマルチエージェントによる業務フロー自動化の設計と実践
h_okkah
0
290
レトロゲームから学ぶ通信技術の歴史
kimkim0106
0
130
Hack Claude Code with Claude Code
choplin
8
2.8k
NEWT Backend Evolution
xpromx
1
150
可変変数との向き合い方 $$変数名が踊り出す$$ / php conference Variable variables
gunji
0
230
The Modern View Layer Rails Deserves: A Vision For 2025 And Beyond @ RailsConf 2025, Philadelphia, PA
marcoroth
2
790
Yes, You Can Work on Rails & any other Gem
kaspth
0
110
ソフトウェア設計とAI技術の活用
masuda220
PRO
25
6.7k
構造化・自動化・ガードレール - Vibe Coding実践記 -
tonegawa07
0
150
リッチエディターを安全に開発・運用するために
unachang113
1
240
[SRE NEXT] 複雑なシステムにおけるUser Journey SLOの導入
yakenji
0
740
Featured
See All Featured
Docker and Python
trallard
45
3.5k
Code Review Best Practice
trishagee
69
19k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
990
Building Flexible Design Systems
yeseniaperezcruz
328
39k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
Raft: Consensus for Rubyists
vanstee
140
7k
Statistics for Hackers
jakevdp
799
220k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.7k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
5.9k
Bash Introduction
62gerente
613
210k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
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