class Spoom::Sorbet::Errors::Parser
Parse errors from Sorbet output
def self.parse_string(output)
def self.parse_string(output) parser = Spoom::Sorbet::Errors::Parser.new parser.parse(output) end
def append_error(line)
def append_error(line) raise "Error: Not already parsing an error!" unless @current_error @current_error.more << line end
def close_error
def close_error raise "Error: Not already parsing an error!" unless @current_error @errors << @current_error @current_error = nil end
def initialize
def initialize @errors = [] @current_error = nil end
def match_error_line(line)
def match_error_line(line) match = line.match(ERROR_LINE_MATCH_REGEX) return unless match file, line, message, code = match.captures Error.new(file, line&.to_i, message, code&.to_i) end
def open_error(error)
def open_error(error) raise "Error: Already parsing an error!" if @current_error @current_error = error end
def parse(output)
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