@@ -12,6 +12,8 @@ tapioca = "sorbet/tapioca"
12
12
examples = "examples"
13
13
ignore_file = ".ignore"
14
14
15
+ FILES_ENV = "FORMAT_FILE"
16
+
15
17
CLEAN . push ( *%w[ .idea/ .ruby-lsp/ .yardoc/ doc/ ] , *FileList [ "*.gem" ] , ignore_file )
16
18
17
19
CLOBBER . push ( *%w[ sorbet/rbi/annotations/ sorbet/rbi/gems/ ] , tapioca )
55
57
desc ( "Format `*.rb`" )
56
58
multitask ( :"format:rb" ) do
57
59
# 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 ]
59
61
fmt = xargs + %w[ rubocop --fail-level F --autocorrect --format simple -- ]
60
- sh ( "#{ find . shelljoin } | #{ fmt . shelljoin } " )
62
+ sh ( "#{ files . shelljoin } | #{ fmt . shelljoin } " )
61
63
end
62
64
63
65
desc ( "Format `*.rbi`" )
64
66
multitask ( :"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 ]
66
68
fmt = xargs + %w[ stree write -- ]
67
- sh ( ruby_opt , "#{ find . shelljoin } | #{ fmt . shelljoin } " )
69
+ sh ( ruby_opt , "#{ files . shelljoin } | #{ fmt . shelljoin } " )
68
70
end
69
71
70
72
desc ( "Format `*.rbs`" )
71
73
multitask ( :"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 ]
73
75
inplace = /darwin|bsd/ =~ RUBY_PLATFORM ? [ "-i" , "" ] : %w[ -i ]
74
76
uuid = SecureRandom . uuid
75
77
@@ -98,13 +100,13 @@ multitask(:"format:rbs") do
98
100
success = false
99
101
100
102
# 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 } " )
102
104
# 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
104
106
success = _1
105
107
end
106
108
# transform type aliases back to class aliases
107
- sh ( "#{ find . shelljoin } | #{ pst . shelljoin } " )
109
+ sh ( "#{ files . shelljoin } | #{ pst . shelljoin } " )
108
110
109
111
# always run post-processing to remove comment marker
110
112
fail unless success
0 commit comments