lib/spoom/cli/run.rb in spoom-1.1.11 vs lib/spoom/cli/run.rb in spoom-1.1.12
- old
+ new
@@ -20,11 +20,12 @@
option :sort, type: :string, aliases: :s, desc: "Sort errors", enum: SORT_ENUM, default: SORT_LOC
option :format, type: :string, aliases: :f, desc: "Format line output"
option :uniq, type: :boolean, aliases: :u, desc: "Remove duplicated lines"
option :count, type: :boolean, default: true, desc: "Show errors count"
option :sorbet, type: :string, desc: "Path to custom Sorbet bin"
- def tc(*arg)
+ option :sorbet_options, type: :string, default: "", desc: "Pass options to Sorbet"
+ def tc(*paths_to_select)
in_sorbet_project!
path = exec_path
limit = options[:limit]
sort = options[:sort]
@@ -34,23 +35,25 @@
count = options[:count]
sorbet = options[:sorbet]
unless limit || code || sort
result = T.unsafe(Spoom::Sorbet).srb_tc(
- *arg,
+ *options[:sorbet_options].split(" "),
path: path,
capture_err: false,
sorbet_bin: sorbet
)
check_sorbet_segfault(result.code)
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(Spoom::Sorbet).srb_tc(
- *arg,
+ *options[:sorbet_options].split(" "),
+ "--error-url-base=#{error_url_base}",
path: path,
capture_err: true,
sorbet_bin: sorbet
)
@@ -59,23 +62,30 @@
if result.status
say_error(result.err, status: nil, nl: false)
exit(0)
end
- errors = Spoom::Sorbet::Errors::Parser.parse_string(result.err)
+ 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 = errors.select { |e| e.code == code } if code
errors = T.must(errors.slice(0, limit)) if limit
lines = errors.map { |e| format_error(e, format || DEFAULT_FORMAT) }
lines = lines.uniq if uniq
@@ -108,10 +118,10 @@
return message unless color?
cyan = T.let(false, T::Boolean)
word = StringIO.new
message.chars.each do |c|
- if c == '`'
+ if c == "`"
cyan = !cyan
next
end
word << (cyan ? cyan(c) : red(c))
end