Class: Spoom::Sorbet::Errors::Parser

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/spoom/sorbet/errors.rb

Overview

Parse errors from Sorbet output

Constant Summary collapse

HEADER =
[
  "👋 Hey there! Heads up that this is not a release build of sorbet.",
  "Release builds are faster and more well-supported by the Sorbet team.",
  "Check out the README to learn how to build Sorbet in release mode.",
  "To forcibly silence this error, either pass --silence-dev-message,",
  "or set SORBET_SILENCE_DEV_MESSAGE=1 in your shell environment.",
]
ERROR_LINE_MATCH_REGEX =
%r{
  ^         # match beginning of line
  (\S[^:]*) # capture filename as something that starts with a non-space character
            # followed by anything that is not a colon character
  :         # match the filename - line number seperator
  (\d+)     # capture the line number
  :\s       # match the line number - error message separator
  (.*)      # capture the error message
  \shttps://srb.help/ # match the error code url prefix
  (\d+)     # capture the error code
  $         # match end of line
}x.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



41
42
43
44
# File 'lib/spoom/sorbet/errors.rb', line 41

def initialize
  @errors = []
  @current_error = nil
end

Class Method Details

.parse_string(output) ⇒ Object



35
36
37
38
# File 'lib/spoom/sorbet/errors.rb', line 35

def self.parse_string(output)
  parser = Spoom::Sorbet::Errors::Parser.new
  parser.parse(output)
end

Instance Method Details

#parse(output) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/spoom/sorbet/errors.rb', line 47

def parse(output)
  output.each_line do |line|
    break if /^No errors! Great job\./.match?(line)
    break if /^Errors: /.match?(line)
    next if HEADER.include?(line.strip)

    next if line == "\n"

    if (error = match_error_line(line))
      close_error if @current_error
      open_error(error)
      next
    end

    append_error(line) if @current_error
  end
  close_error if @current_error
  @errors
end