Upgrade to PRO for Only $50/YearâLimited-Time Offer! ð¥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
linter for your team rule
Search
mizkei
November 09, 2018
Programming
3
2.3k
linter for your team rule
mizkei
November 09, 2018
Tweet
Share
More Decks by mizkei
See All by mizkei
About: Go Module Proxy: Life of a query
mizkei
0
180
Goã§ã²ãŒã ãµãŒããŒãå®è£ ããŠèããããš / game server in go
mizkei
1
6.8k
Other Decks in Programming
See All in Programming
14 Years of iOS: Lessons and Key Points
seyfoyun
0
490
Remix on Hono on Cloudflare Workers
yusukebe
2
390
Thoughts and experiences on Rust and TypeScript
unvalley
2
210
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
230
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
140
WebAssembly Unleashed: Powering Server-Side Applications
chrisft25
0
2.1k
.NET ã®ããã®éä¿¡ãã¬ãŒã ã¯ãŒã¯ MagicOnion å ¥é / Introduction to MagicOnion
mayuki
1
3.3k
.NET 9ã¢ããªãCGIãšã㊠ã¬ã³ã¿ã«ãµãŒããŒã§åãã
mayuki
1
750
Cursorã§ã¢ããªã±ãŒã·ã§ã³ã®è¿œå éçºãä¿å®ãã©ããŸã§ã§ãããè©ŠãããåŸããã®ãå€ãã£ã話
drumnistnakano
0
260
MoQãšãå匷äŒ#2 çºè¡šè³æ
yuki_uchida
2
150
Develop iOS apps with Neovim / vimconf_2024
uhooi
1
280
ãã¹ãèªåå倱æããåææŠãããŒã ã«ãªãŒããŒã·ããããå§è²ãã話/STAC2024 macho
ma_cho29
0
220
Featured
See All Featured
Six Lessons from altMBA
skipperchong
27
3.5k
BBQ
matthewcrist
85
9.3k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Docker and Python
trallard
40
3.1k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Side Projects
sachag
452
42k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
480
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.2k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
A designer walks into a libraryâŠ
pauljervisheath
204
24k
Transcript
ãããžã§ã¯ãã®ã«ãŒã«ã ãã§ãã¯ããããã®lint mercari.go#4
ç®æ¬¡ ⢠èªå·±çŽ¹ä» ⢠golint ⢠ããŒã ã§åãå ¥ãããã«ãŒã« ⢠ãã¹ãã®ããã«åãå ¥ãããã«ãŒã« â¢
ããã±ãŒãžã®åœ¹å²ãåããããã«åãå ¥ãããã«ãŒã« ⢠ã«ãŒã«ãããŒã ã§å ±æããæ¹æ³ ⢠ã«ãŒã«è¡šçŸã®ããã«äœæããããŒã«ãself-lintã ⢠ãŸãšã
èªå·±çŽ¹ä» ⢠åå ⊠氎é æ¬å€ª ⢠github ⊠mizkei
⢠twitter ⊠@mizkei11 ⢠ä»äº ⊠Backend/ãã€ã¯ããµãŒãã¹éçº
golint
golintã«ããã³ãŒãã£ã³ã°ã¹ã¿ã€ã«ã®ææ ⢠Effective Go ã Go Code Review Comments ã«åºã¥ããææ
⊠äžèŠãªelse ⊠ã³ã¡ã³ãã®ãã©ãŒããã ⊠context.WithValueã®keyã®å ⊠å€æ°ã»ããã±ãŒãžå ⊠import Dot ⊠main以å€ã§ã®blank import ⊠...
golintã«ããã³ãŒãã£ã³ã°ã¹ã¿ã€ã«ã®ææ ⢠ãããžã§ã¯ãã«ãããã³ãŒãã®æžãæ¹ãããçšåºŠçµ±äžããã ⢠ãšãã£ã¿ã®èšå®ãããã°ãç·šéããªãã確èªå¯èœ ⢠reviewdog ã«ãã°ãé£ã¹ãŠãããã°ãgithubäžã§ãææããã 綺éºãªGoã®ã³ãŒããæžãããã®ã«ãŒã«ãšããŠã¯éåžžã«æçšã ãã ããŒã ã®ããŒã«ã«ã«ãŒã«ã欲ããå Žåããã
ããŒã ã§åãå ¥ãããã«ãŒã«
ç¹å®ããã±ãŒãžã®importå¶é ⢠Assertãªã©ãæäŸããå€éšããã±ãŒãž ⊠Why does Go not have assertions?
⢠ãããžã§ã¯ãã«ããããã¹ãçšããã±ãŒãž ⊠e.g. githoge.com/project/root/test ⊠ãã¹ãçšã®ããŒã¿ãçšæããããã®äŸ¿å©ã¡ãœãã矀 ⪠è€æ°ããã±ãŒãžã®ãã¹ãã§åç §ãããããã«äžã€ã®ããã±ãŒãžãšããŠäœæ
ãããžã§ã¯ãã«ããããã¹ãçšããã±ãŒãž ⢠ãã¹ãçšã®mock ⊠ãã¹ãã§ã¯ãªãããã±ãŒãžã«å«ããããªã ⪠package modelãimportããŠããŸãã°èª°ã§ã䜿ããŠããŸããã ⢠ãã¹ãããŒã¿äœæ䟿å©ã¡ãœãã
⊠*intãªã©ãåããã±ãŒãžã®ãã¹ãã§æžããŠãããšæéãããã
ãããžã§ã¯ãã«ããããã¹ãçšããã±ãŒãž
ãã¹ãã®ããã«åãå ¥ãããã«ãŒã«
ç¹å®ã¡ãœããã»å€æ°ãžã®åç §å¶é ⢠ãã¹ãã®ããã®æéåæ¢çšã¡ãœãããªã© ⊠ã¡ãœãããšããŠçšæããªãæ¹æ³ããããããã¹ããäžæéå¢ãã ⊠æéããããªãããã«æ¥œããããšãã«ã§ããŠããŸãå¯ç£ç©ã ãã¹ã以å€ã§ã¯å©çšã§ããªãããã«ããã
ãã¹ãçšã«æéãåæ¢ããã¡ãœãã ⢠çŸåšæå»ã«ããåäœã®å·®ç°ãããå Žåããã¹ãããæã®æ¹æ³ ⊠Now() time.Timeãå®è£ ããã€ã³ã¿ãŒãã§ãŒã¹ãæž¡ããããã«ãã ⪠ãã¹ãçšã«åçš®ããã±ãŒãžã«ã€ã³ã¿ãŒãã§ãŒã¹ãæž¡ãã®ãæé ⊠ã°ããŒãã«ã«time.Nowãžã®åç §ãæã£ãããã±ãŒãžãäœæããŠã
çŸåšæå»ååŸã¯ãã®ã¡ãœããããè¡ãããã¹ãæã«å·®ãæ¿ãã ⪠ãã¹ãæã«å·®ãæ¿ããçšã®ã¡ãœãã㯠`*_test.go` ããåç §ã§ããå¿ èŠããããã Publicãªã¡ãœããã«ããªããã°ãªããªã
çŸåšæå»ãå·®ãæ¿ãã(interfaceç) ⢠interfaceãæž¡ãã¹ãæ§é äœãè€æ°ããå Žåãªã©ããã¹ãã§ã®ç®¡çãé¢å
çŸåšæå»ãå·®ãæ¿ãã(globalæžãæãç) ⢠build tagsãèšè¿°ãããã¡ã€ã«ã®ã¿ã«ã¡ãœãããå®çŸ©ããå Žåã ãšãã£ã¿ã®lintèšå®ãå€æŽããªããã°ãªããªã ⢠ã¿ã°ããªããã°ãå·®ãæ¿ããã¡ãœããã¯æ©èœããªãããå·®ãæ¿ããã¡ãœããã TestGoFiles, XTestGofiles以å€ã§åç §ããããšãããã£ãŠã»ããã¯ãªã
ããã±ãŒãžã®åœ¹å²ãåããããã«å ãå ¥ãããã«ãŒã«
ç¹å®builtinæ©èœã®å¶é ⢠panicæžãæ©äŒã¯ã»ãŒãªãããçŠæ¢ããŠããŸããã ⊠web applicationæžããŠãããšããªã© ⢠ããŒã¿ã®æ§é ã«ã€ããŠã®ã¿èšè¿°ããããã®ããã±ãŒãžã§æ¡ä»¶åå²ãªã©äžèŠ ⊠e.g.
githoge.com/project/root/data ⊠æ§é äœã®å®çŸ©ã ãèšè¿°ãããŠãããã å€ãè©°ã蟌ãã ãã®ã¡ãœããããååšããŠã»ãããªã
ã«ãŒã«ã®å ±ææ¹æ³
ããŒã ã§ã®ã«ãŒã«ã®å ±ææ¹æ³ ⢠Wikiã«ãŸãšãã ⊠æŽæ°ããç¶ããä¿èšŒã¯ãªã ⊠èªãŸãªãã§æžããŠãã人ãããã ⊠ã¬ãã¥ãŒã§ææãããšããŠãããŒã ã«å ¥ã£ãŠããã®æŽãæµ ããš èŠéããŠããŸãå¯èœæ§ããã
人ããã§ãã¯ãããšèŠéãå¯èœæ§ãæé€ããããšã¯ã§ããªãã®ã§ã ããŒã ã«ãŒã«ãèªåçã«ãã§ãã¯ããããã®ããŒã«ã欲ãã
ãself-lintã
self-lint ⢠https://github.com/mizkei/self-lint ⢠ããŒã ã§ã®çŠæ¢äºé (ããŒã«ã«ã«ãŒã«)ããã§ãã¯ããããã®ããŒã« ⊠ç¹å®importã®ãã§ã㯠⊠ç¹å®packageã®ã¡ãœãããå€æ°ãžã®åç § âŠ
panicãªã©ã®builtin functionã®äœ¿çš ⢠CIãå©çšããèªåãã§ã㯠⊠golintãšåãåºå圢åŒã§ãããããreviewdogãé£ã¹ãŠããã
self-lintã®èšå® ⢠target ⊠察象ã®ããã±ãŒãž ⪠globalã¯å šãŠã®ããã±ãŒãž ⢠import âŠ
çŠæ¢ãããããã±ãŒãžãæžã ⢠ref ⊠çŠæ¢ãããããã±ãŒãžã®å€ãæžã ⢠write ⊠çŠæ¢ãããbuiltin functionãæžã ⪠panic, if, switch, or for
ç¹å®importã®ãã§ã㯠⢠ãã¹ããã¡ã€ã«ä»¥å€ã§testããã±ãŒãžã¯importããŠã¯ãããªã
ç¹å®ããã±ãŒãžã®å€ãžã®åç § ⢠ãã¹ãçšã«äœæãããã¡ãœããã ãã¹ããã¡ã€ã«ä»¥å€ã§åç §ããŠã»ãããªã
ç¹å®ã®builtinãstatementsã®å©çš ⢠ããŒã¿ãå®çŸ©ããŠããã ãã®ããã±ãŒãžã§panicããŠã»ãããªã
ãŸãšã ⢠lintã«å ããŠãããŒã ã§ã®éçºã«ãããŠãæŽã«å¶éã欲ãããªãå Žåã« ã€ããŠè¿°ã¹ã ⢠ããŒã ãšããŠèšå®ããå¶éãèªåãã§ãã¯ããããã« self-lintãšããããŒã«ãäœæãã