Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Steepで使えるコマンドを見てみよう
ikuma-t
February 03, 2022
Programming
1
230
Steepで使えるコマンドを見てみよう
omotesando.rb#71の登壇資料です
ikuma-t
February 03, 2022
Tweet
Share
More Decks by ikuma-t
See All by ikuma-t
BEYOND THE RELEASE(K-Ruby Edition)
ikumatadokoro
1
56
初心者が地方公共団体コードを扱うためのGemを作った話
ikumatadokoro
6
1k
地方公共団体コードを便利に扱うためのGemを作った
ikumatadokoro
1
240
進捗感を得るためのログ駆動開発
ikumatadokoro
2
420
PowerQuery入門
ikumatadokoro
3
930
初心者こそ!RubyMineで始めよう!
ikumatadokoro
1
3.3k
Other Decks in Programming
See All in Programming
リアルタイムボイスチェンジャーMMVCとVITSの紹介
stealthinu
0
150
NEWT.net: Frontend Technology Selection
xpromx
0
270
開発速度を5倍早くするVSCodeの拡張機能を作った
purp1eeeee
2
160
Beyond Micro Frontends: Frontend Moduliths for the Enterprise @wad2022
manfredsteyer
PRO
0
140
Cybozu GoogleI/O 2022 LT会 - Input for all screens
jaewgwon
0
380
Oracle REST Data Service: APEX Office Hours
thatjeffsmith
0
790
プロダクトのタイプ別 GraphQL クライアントの選び方
shozawa
0
5.6k
BASE BANKチームの技術選定と歴史 / how to decide technology selection for startup
budougumi0617
0
1.3k
Terraform Plan/Apply結果の自動通知
ymmy02
0
280
React Nativeアプリを DDDで開発している話
nihemak
0
160
Jetpack Compose best practices 動画紹介 @GoogleI/O LT会
takakitojo
0
390
engineer
spacemarket
0
3.9k
Featured
See All Featured
Art Directing for the Web. Five minutes with CSS Template Areas
malarkey
196
9.4k
VelocityConf: Rendering Performance Case Studies
addyosmani
316
22k
GraphQLの誤解/rethinking-graphql
sonatard
28
6.6k
The Illustrated Children's Guide to Kubernetes
chrisshort
15
36k
Three Pipe Problems
jasonvnalue
89
8.7k
How STYLIGHT went responsive
nonsquared
85
3.9k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_i
23
15k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
498
130k
The World Runs on Bad Software
bkeepers
PRO
57
5.3k
Art, The Web, and Tiny UX
lynnandtonic
280
17k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
12
920
GitHub's CSS Performance
jonrohan
1020
420k
Transcript
Steep で使えるコマンドを見てみよう! Omotesando.rb#71 @ikuma-t
Self Introduction 🗣 名前 - ikuma-t 🐤 Twitter - @ikumatdkr
😸 GitHub - IkumaTadokoro ✍️ Blog - セットプチフォッカ FJORD BOOT CAMP ってところでエンジニア目指して勉強しています 最近はじめてのGem をつくりました:jp_local_gov 趣味は作曲家めぐり・ツール漁り・アニメ鑑賞・ドット絵 自己紹介
みなさん、RBS 書いてますか? 自分はあんまり書いていない
RBS といえばSteep
型書いて、steep check して終わり
Steep には steep check 以外にも 使用できるコマンドがある
Steep には steep check 以外にも使用できるコマンドがある コマンド 概要 init Steepfile を作成する
check 静的チェックを実行する validate 型定義自体の文法チェックを実行する project Steepfile に基づいて対象プロジェクトの構造を表示する stats お型付け具合をチェックする watch リアルタイムで変更をキャッチして、静的チェックを実行できる langserver LSP を起動する annotations インラインアノテーションの一覧を表示する
Steep で使えるコマンドを見てみよう! 検証はSteep 0.47.0 で行っています
steep project Steepfile で定義されているプロジェクトを出力する 1 $ steep project 2 3
Target: 4 lib: 5 sources: 6 patterns: 7 - lib 8 ignores: 9 files: 10 - lib/jp_local_gov/base.rb 11 ... 12 signatures: 13 patterns: 14 - sig 15 files: 16 - sig/jp_local_gov/base.rbs 17 ... 18 libraries: 19 library dirs: 20 - core: ...
steep validate 型定義の文法的誤りをチェックできる ソース 1 def hoge?(word) 2 word.size ==
1 3 end RBS def hoge?: (String word) >- bool 実行結果 1 $ steep validate 2 sig/jp_local_gov.rbs:28:27: [error] sig/jp_local_gov.rbs:28:27...28:28: Syntax error: 3 │ Diagnostic ID: RBS::SyntaxError 4 │ 5 └ def hoge?: (String word) >- bool 6 ~
steep stats 型付けの統計情報を確認することができる 1 $ steep stats --format={csv | table}
で出力形式を切り替えることができる(デフォルトはSTDOUT.tty? に則る) 小規模なGem ですら100% にすることはできなかったのだ… Refs: https://github.com/soutaro/steep/pull/360 2 3 # Calculating stats: 4 5 Target File Status Typed calls Untyped calls All calls Typed % 6 -------------------------------------------------------------------------------------------------- 7 lib lib/jp_local_gov.rb success 69 5 74 93% 8 lib lib/jp_local_gov/base.rb success 4 0 4 100% 9 lib lib/jp_local_gov/local_gov.rb success 8 0 8 100% 10 lib lib/jp_local_gov/random.rb success 16 4 20 80% 11 lib lib/jp_local_gov/version.rb success 0 0 0 100% ` `
折り返し:steep check はTea が出る steep check を実行した際にエラーがなければ、Tea 「🫖」が出る 5 No
type error detected. 🫖 実は出てくるのは「🫖」だけではなくて、ほかの絵文字(全4 種)が出ることもある。 残りの絵文字はだいたい10% くらいの確率で出るので試してみては? 1 # Type checking files: 2 3 ...................................................................... 4
steep annotations インラインアノテーションの使用箇所を一覧することができる RBS 1 # @type var hoge: String
2 hoge = "hoge" steep annotations の実行 1 $ steep annotations 2 lib/jp_local_gov/random.rb:18:4:def: def sample_data 3 @type var hoge: String Refs: https://github.com/soutaro/steep/blob/master/manual/annotations.md ` `
steep watch webpack のwatch モードみたいなもの(公式談) ソースの変更時に静的チェックをリアルタイムで実行してくれる RBS 側はコマンドを実行した時点での情報を参照している模様 Refs: https://github.com/soutaro/steep/pull/77
1 # 監視対象のディレクトリを指定して起動 2 steep watch lib 3 👀 Watching directories, Ctrl-C to stop. # 監視状態になる 4 🔬 Type checking updated files... # ソース側が変更されると、自動でチェックが行われる 5 lib/jp_local_gov.rb:81:6: [error] Cannot allow method body have type `::Integer` because declared as type `::Array 6 │ ::Integer <: ::Array[::String] 7 │ ::Numeric <: ::Array[::String] 8 │ ::Object <: ::Array[::String] 9 │ ::BasicObject <: ::Array[::String] 10 │ 11 │ Diagnostic ID: Ruby::MethodBodyTypeMismatch 12 │ 13 └ def prefecture_code_list 14 ~~~~~~~~~~~~~~~~~~~~ 15 🔬 Type checking updated files...
steep langserver LSP… なんですが、ごめんなさい、RubyMine で実証できませんでした🙏 Refs: https://github.com/soutaro/steep/pull/79 一応ここのPR のコメントでRubyMine での実行方法も書いてあるけどうまくいかない…
まとめ Steep にはあんまり知られていないけど、いろんなコマンドがある! Steep をどんどん使って、Ruby での型定義を活発にしていこう!(私はAST を頑 張って勉強します… )