@@ -12,6 +12,8 @@ tapioca = "sorbet/tapioca"
1212examples = "examples"
1313ignore_file = ".ignore"
1414
15+ FILES_ENV = "FORMAT_FILE"
16+
1517CLEAN . push ( *%w[ .idea/ .ruby-lsp/ .yardoc/ doc/ ] , *FileList [ "*.gem" ] , ignore_file )
1618
1719CLOBBER . push ( *%w[ sorbet/rbi/annotations/ sorbet/rbi/gems/ ] , tapioca )
5557desc ( "Format `*.rb`" )
5658multitask ( :"format:rb" ) do
5759 # while `syntax_tree` is much faster than `rubocop`, `rubocop` is the only formatter with full syntax support
58- find = %w[ find ./lib ./test ./examples -type f -and -name *.rb -print0 ]
60+ files = ENV . key? ( FILES_ENV ) ? %w[ sed -E -n -e /\.rb$/p -- ] << ENV . fetch ( FILES_ENV ) : %w[ find ./lib ./test ./examples -type f -and -name *.rb -print0 ]
5961 fmt = xargs + %w[ rubocop --fail-level F --autocorrect --format simple -- ]
60- sh ( "#{ find . shelljoin } | #{ fmt . shelljoin } " )
62+ sh ( "#{ files . shelljoin } | #{ fmt . shelljoin } " )
6163end
6264
6365desc ( "Format `*.rbi`" )
6466multitask ( :"format:rbi" ) do
65- find = %w[ find ./rbi -type f -and -name *.rbi -print0 ]
67+ files = ENV . key? ( FILES_ENV ) ? %w[ sed -E -n -e /\.rbi$/p -- ] << ENV . fetch ( FILES_ENV ) : %w[ find ./rbi -type f -and -name *.rbi -print0 ]
6668 fmt = xargs + %w[ stree write -- ]
67- sh ( ruby_opt , "#{ find . shelljoin } | #{ fmt . shelljoin } " )
69+ sh ( ruby_opt , "#{ files . shelljoin } | #{ fmt . shelljoin } " )
6870end
6971
7072desc ( "Format `*.rbs`" )
7173multitask ( :"format:rbs" ) do
72- find = %w[ find ./sig -type f -name *.rbs -print0 ]
74+ files = ENV . key? ( FILES_ENV ) ? %w[ sed -E -n -e /\.rbs$/p -- ] << ENV . fetch ( FILES_ENV ) : %w[ find ./sig -type f -name *.rbs -print0 ]
7375 inplace = /darwin|bsd/ =~ RUBY_PLATFORM ? [ "-i" , "" ] : %w[ -i ]
7476 uuid = SecureRandom . uuid
7577
@@ -98,13 +100,13 @@ multitask(:"format:rbs") do
98100 success = false
99101
100102 # transform class aliases to type aliases, which syntax tree has no trouble with
101- sh ( "#{ find . shelljoin } | #{ pre . shelljoin } " )
103+ sh ( "#{ files . shelljoin } | #{ pre . shelljoin } " )
102104 # run syntax tree to format `*.rbs` files
103- sh ( ruby_opt , "#{ find . shelljoin } | #{ fmt . shelljoin } " ) do
105+ sh ( ruby_opt , "#{ files . shelljoin } | #{ fmt . shelljoin } " ) do
104106 success = _1
105107 end
106108 # transform type aliases back to class aliases
107- sh ( "#{ find . shelljoin } | #{ pst . shelljoin } " )
109+ sh ( "#{ files . shelljoin } | #{ pst . shelljoin } " )
108110
109111 # always run post-processing to remove comment marker
110112 fail unless success
0 commit comments