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

Inherits:
Object
  • Object
show all
Defined in:
lib/spoom/sorbet/errors.rb

Overview

Parse errors from Sorbet output

Defined Under Namespace

Classes: ParseError

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.",
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error_url_base: DEFAULT_ERROR_URL_BASE) ⇒ Parser

: (?error_url_base: String) -> void



67
68
69
70
71
# File 'lib/spoom/sorbet/errors.rb', line 67

def initialize(error_url_base: DEFAULT_ERROR_URL_BASE)
  @errors = [] #: Array[Error]
  @error_line_match_regex = error_line_match_regexp(error_url_base) #: Regexp
  @current_error = nil #: Error?
end

Class Method Details

.parse_string(output, error_url_base: DEFAULT_ERROR_URL_BASE) ⇒ Object

: (String output, ?error_url_base: String) -> Array



60
61
62
63
# File 'lib/spoom/sorbet/errors.rb', line 60

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

Instance Method Details

#parse(output) ⇒ Object

: (String output) -> Array



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/spoom/sorbet/errors.rb', line 74

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