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
400
Steepで使えるコマンドを見てみよう
omotesando.rb#71の登壇資料です
ikuma-t
February 03, 2022
Tweet
Share
More Decks by ikuma-t
See All by ikuma-t
自分だけの小さなSelenium「Olenium」を作って始める、ブラウザ自動化技術の理論と実践
ikumatadokoro
22
8.1k
初めてカンファレンスにCFPを出してみた話
ikumatadokoro
0
60
みんながよろこぶやさしいせかいへ〜Google Apps Scriptでチームの目標通知を自動化した話〜
ikumatadokoro
1
130
「困りごと」から始める個人開発
ikumatadokoro
5
460
BEYOND THE RELEASE(K-Ruby Edition)
ikumatadokoro
1
120
初心者が地方公共団体コードを扱うためのGemを作った話
ikumatadokoro
6
1.2k
地方公共団体コードを便利に扱うためのGemを作った
ikumatadokoro
1
340
進捗感を得るためのログ駆動開発
ikumatadokoro
2
530
PowerQuery入門
ikumatadokoro
3
1.1k
Other Decks in Programming
See All in Programming
Enumを自動で網羅的にテストしてみた
estie
0
1.2k
Swift Concurrency in GoodNotes
inamiy
4
1.3k
Makuakeの認証基盤とRe-Architectureチーム
bmf_san
0
360
Remix + Cloudflare Pages + D1 で ポケモン SV のレンタルチームを検索できるアプリを作ってみた
kuroppe1819
4
1.3k
Most Valuable Bug(?) ~インシデント未遂から得た学び~
tatsumiakahori
0
140
Writing Greener Java Applications
hollycummins
0
330
Refactor with using `available` and `deprecated`
417_72ki
3
380
TokyoR#103_DataProcessing
kilometer
0
520
はてなリモートインターンシップ2022 インフラ 講義資料
hatena
4
2.1k
(新米)エンジニアリングマネージャーのしごと #RSGT2023
murabayashi
9
5.5k
コンピュータビジョンセミナー2 / computer_vision_seminar_libSGM
fixstars
0
310
和暦を正しく扱うための暦の話
nagise
10
4.8k
Featured
See All Featured
Web development in the modern age
philhawksworth
197
9.6k
Building Adaptive Systems
keathley
27
1.3k
Optimizing for Happiness
mojombo
365
64k
How GitHub Uses GitHub to Build GitHub
holman
465
280k
The Cult of Friendly URLs
andyhume
68
5.1k
Designing Experiences People Love
moore
130
22k
Practical Orchestrator
shlominoach
178
8.9k
Why Our Code Smells
bkeepers
PRO
326
55k
Gamification - CAS2011
davidbonilla
75
4.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
217
21k
Build The Right Thing And Hit Your Dates
maggiecrowley
22
1.4k
Clear Off the Table
cherdarchuk
79
290k
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 を頑 張って勉強します… )