Class: Spoom::Cli::Run
- Inherits:
-
Thor
- Object
- Thor
- Spoom::Cli::Run
- Includes:
- Helper
- Defined in:
- lib/spoom/cli/run.rb
Constant Summary collapse
- SORT_CODE =
"code"
- SORT_LOC =
"loc"
- SORT_ENUM =
[SORT_CODE, SORT_LOC]
- DEFAULT_FORMAT =
"%C - %F:%L: %M"
Constants included from Helper
Instance Method Summary collapse
Methods included from Helper
#blue, #color?, #colorize, #context, #context_requiring_sorbet!, #cyan, #exec_path, #gray, #green, #highlight, #red, #say, #say_error, #yellow
Methods included from Spoom::Colorize
Instance Method Details
#tc(*paths_to_select) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/spoom/cli/run.rb', line 26 def tc(*paths_to_select) context = context_requiring_sorbet! limit = [:limit] sort = [:sort] code = [:code] uniq = [:uniq] format = [:format] count = [:count] sorbet = [:sorbet] unless limit || code || sort result = T.unsafe(context).srb_tc( *[:sorbet_options].split(" "), capture_err: false, sorbet_bin: sorbet, ) say_error(result.err, status: nil, nl: false) exit(result.status) end error_url_base = Spoom::Sorbet::Errors::DEFAULT_ERROR_URL_BASE result = T.unsafe(context).srb_tc( *[:sorbet_options].split(" "), "--error-url-base=#{error_url_base}", capture_err: true, sorbet_bin: sorbet, ) if result.status say_error(result.err, status: nil, nl: false) exit(0) end unless result.exit_code == 100 # Sorbet will return exit code 100 if there are type checking errors. # If Sorbet returned something else, it means it didn't terminate normally. say_error(result.err, status: nil, nl: false) exit(1) end errors = Spoom::Sorbet::Errors::Parser.parse_string(result.err, error_url_base: error_url_base) errors_count = errors.size errors = errors.select { |e| e.code == code } if code unless paths_to_select.empty? errors.select! do |error| paths_to_select.any? { |path_to_select| error.file&.start_with?(path_to_select) } end end errors = case sort when SORT_CODE Spoom::Sorbet::Errors.sort_errors_by_code(errors) when SORT_LOC errors.sort else errors # preserve natural sort end errors = T.must(errors.slice(0, limit)) if limit lines = errors.map { |e| format_error(e, format || DEFAULT_FORMAT) } lines = lines.uniq if uniq lines.each do |line| say_error(line, status: nil) end if count if errors_count == errors.size say_error("Errors: #{errors_count}", status: nil) else say_error("Errors: #{errors.size} shown, #{errors_count} total", status: nil) end end exit(1) rescue Spoom::Sorbet::Error::Segfault => error say_error(<<~ERR, status: nil) #{red("!!! Sorbet exited with code #{error.result.exit_code} - SEGFAULT !!!")} This is most likely related to a bug in Sorbet. ERR exit(error.result.exit_code) rescue Spoom::Sorbet::Error::Killed => error say_error(<<~ERR, status: nil) #{red("!!! Sorbet exited with code #{error.result.exit_code} - KILLED !!!")} ERR exit(error.result.exit_code) end |