RuboCop on RBS
rubocopをRBSファイルにも効かせたい - スペクトラム ã§ä½ã£ã¦ããã®ã大ä½ã§ãã¦ãã¦ãrbs v3.5ããªãªã¼ã¹ãããã®ã§å ¬éã§ããããã«ãªãã¾ããã
ããã§RuboCopãRBSãã¡ã¤ã«ã«ã使ç¨ã§ããããã«ãªãã¾ããã
ä¾ãã°
class Foo def foo: () -> void end
ã¨ããRBSãã¬ãã¥ã¼ããæãã¤ã³ãã³ãå ¥ãã¦ããã¨ææããããªãã¾ããããRubyãã¡ã¤ã«ãªãrubocopã§ã§ããã®ã«ãRBSãã¡ã¤ã«ã§ã¯rubocopã§ææã§ããªãã¨ããåé¡ãããã¾ããããããã§ãããã£ã¨ãã¨ããããã§ãã§ããããã«ãã¾ããã
ã¨ããããåæãã¼ã¸ã§ã³ã§ã¯20以ä¸ã®ã«ã¼ã«ãç¨æãã¦ãã¾ãã
autocorrect(èªåä¿®æ£)ã«ã対å¿ãã¦ããã®ã§ããã¤ãã®ããã«rubocop -a
ãã¦ãããã°
class Foo def foo: () -> void end
ã¨rubocopãä¿®æ£ãã¦ããã¾ãã
CLIã§å®è¡ããããããCIã«è¨å®ããããããã¨ãã£ã¿ä¸ã§LSPã¨ãã¦ä½¿ç¨ãããããã¨ãRBSã®è¨è¿°ã¸ã®ãã¼ãã«ãä¸ãããã¨ãç®æãã¦ãã¾ãã
RuboCop on RBS
ã¡ããããã¼ãã³ã°ã§ããã¯ã±ãããã¾ããrubocop-rbsã®ååã¯ä½¿ããªãã£ãã®ã§ããããã ãã§ãã
rubocop-de-rbsã¨ã¡ãã£ã¨è¿·ãã¾ããã
ã¤ãããã
使ãæ¹ã¯ãrubocop-railsçãµã¤ãã®rubocopæ¡å¼µã¨åãã§ãã.rubocop.yml
ã®require
ã«è¿½å ããã®ããªã¹ã¹ã¡ã§ãã
Departments
20以ä¸ã®æ©è½ãããã.rubocop.yml
ã§è¨å®ãåãæ¿ãããã¾ãã
æ©è½è¿½å ã®ãªã¯ã¨ã¹ãå¾
ã£ã¦ãã¾ãã
RBS/Layout/*
ã¤ã³ãã³ããã¹ãã¼ã¹ã®ææãããã³autocorrectã«ããèªåä¿®æ£ãã§ãã¾ãã rbsãªãã¸ããªã«è¨è¼ããã¦ããã¹ãã¼ã¹ãã¤ã³ãã³ããæ£ãããã®ã¨ãã¦ãã¾ãã
å ¨ã¦ã®ãã¼ã¯ã³éã§å¤ãããã¹ãã¼ã¹ãææãããã¨ãã§ãã¾ãã ãã®ããã«RBSã«ãã¼ã¯ã³å¥ã«ãã¼ã¹ããæ©è½ãå ¥ãã¦ãããã¾ããã Implement token list API by ksss · Pull Request #1829 · ruby/rbs · GitHub
- ã³ã¡ã³ãã®ã¤ã³ãã³ããããã¦ãã¨ææ
- overloadéã®ç©ºæ¹è¡ãããã¨ææ
- class/module/interfaceã¨endã®ã¤ã³ãã³ããåã£ã¦ãªãã¨ææ
- ã¹ãã¼ã¹ãç¡é§ã«å¤ãããã¨ææ
- class/module/interfaceããããã³ã«ã¤ã³ãã³ããã¹ãã¼ã¹2ã¤åæ·±ããªã£ã¦ãªãã¨ææ
- overloadã®
:
ã¨|
ã®ç¸¦ãæã£ã¦ãªãã¨ææ ->
ã®åå¾ã¯1ã¹ãã¼ã¹ãããªãã¨ææ- ãããã¯ã表ã
{}
ã®åå¾ã¯1ã¹ãã¼ã¹ãããªãã¨ææ def foo:
ã®:
ã®åã¯ã¹ãã¼ã¹ããªããããææ:
ã|
ã®ãã¨ã¯1ã¹ãã¼ã¹ã«ãªãããææ- è¡æ«ã®ä½åãªã¹ãã¼ã¹ãææ
RBS/Lint/*
RBSã®ã·ã³ã¿ãã¯ã¹ã¨ã©ã¼ããrbs validate
ã§ã¯ã¼ãã³ã°ãã¨ã©ã¼ã«ãªãæ§æãææãã¦ããã¾ãã
- ã·ã³ã¿ãã¯ã¹ã¨ã©ã¼
- åå¼æ°ãå ¨ã使ã£ã¦ããªãã¨è¦å
Array
çãåå¼æ°ãæå®ããªããã°ãããªãåãªã®ã«ãåå¼æ°ãã¤ãã¦ããªãã£ããå¤ãã£ãããããè¦å- ã¡ã½ããå¼æ°ã«
void
ã使ç¨ãããè¦å
rbs validate
ãå®è¡ããªãã¦ãRuboCopã§ææãã¦ãããã®ã§ããã«åé¡ã«æ°ã¥ãã¾ãã
è¥å¹²Steepã®LSPæ©è½ã¨è¢«ã£ã¦ããå ´åãããã¾ãããRuboCop on RBSã§ã¯è»½éã«åãããã®ããSteepã§ã¯åå解決ãå¿ è¦ãªéããã®ãè¦ããã°ããã®ããªã¨æã£ã¦ãã¾ãã
RBS/Style/*
ãã®æ¸ãæ¹ããããã£ã¡ã®æ¹ãããã§ããç³»ã 主ã«åã®æ¸ãæ¹ã§ç¡æå³ãªéè¤ããã£ããããã¨æãã¦ããã¾ãã èªåä¿®æ£ã«ã対å¿ãã¦ããã®ã§ä¾¿å©ã
- ãããã¯ã®è¿ãå¤ã«
bool
ã使ã£ã¦ããæã¯ææ TrueClass
,FalseClass
,NilClass
ã使ã£ã¦ããã¨ææInteger | Integer
ã®ãããªéè¤ãããã¨ææ- initializeã®è¿ãå¤ã¯
void
ã§ãªãã¨ææ untyped | String
ã¯çµå±untyped
ãªã®ã§æænil?
ã®ãããªéè¤ããå®ç¾©ãæætrue | false
ã使ç¨ããå ´åãbool
ã«ç´ãããææ
ã©ããã£ã¦ãã£ã¦ãã®ï¼
rubocopã¯ãRubyã¨ãã¦ãã¼ã¹ããã·ã³ã¿ãã¯ã¹ã¨ã©ã¼ãçºçãããon_other_file
ãå¼ã³åºãã¾ãã¨ããæåã«ãªã£ã¦ãã¾ãã
ãã®on_other_file
ã§RBSã¨ãã¦ãã¼ã¹ãã¦ããã¾ãã¾ãªCopã«å©ç¨ãã¦ãã¾ããRBS::Parser.parse_signature
ã§ãã¼ã¹ããASTã«ã¯ä½ç½®æ
å ±ãå«ã¾ãã¦ããã®ã§ãããå©ç¨ãã¦ãã¾ãã
ã¾ããRBS::Parser.lex
ã¨ããAPIãå¢ããã®ã§ãããã§å
¨ã¦ã®ãã¼ã¯ã³ã®ä½ç½®æ
å ±ãç´°ããåå¾ã§ãã¾ãããããã¬ãããªä½¿ã£ã¦ãã¾ãããªã®ã§rubocop-on-rbsã¯rbs v3.5ãã使ããã¨ãã§ãã¾ãã
VSCode対å¿
VSCode対å¿ãã§ãã¦ãã¾ãã
ã§ãã https://github.com/rubocop/vscode-rubocop/pull/28 ã§ææ¡ä¸ãªã®ã§èªåã§extensionãbuildãããã~/.vscode/extensions/
ãç´æ¥æ¸ããããå¿
è¦ãããã¾ãã(æ¹æ³ã¯rubocop-on-rbsã®README.mdã«æ¸ãã¾ããã)
ã¨ãã£ã¿ã§ãªã¢ã«ã¿ã¤ã ãã£ã¼ãããã¯ãããã¨æ¬¡å ã®éãéçºä½é¨ãã§ããã®ã§ããã²å®ç¾ããããæ©è½ã§ãã
å°æ¥çã«
ruby/rbsãruby/gem_rbs_collectionã«å°å ¥ãã¦ãPRããããCIã§æ©æ¢°çã«ææã§ããããããªã¨æã£ã¦ãã¾ãã
ãã¡ããããªãã®ãªãã¸ããªã«ã使ã£ã¦ããã ããã¨å¤§å¤å¬ããã§ãã