class Spoom::Sorbet::Errors::Parser
Parse errors from Sorbet
output
Constants
- ERROR_LINE_MATCH_REGEX
- HEADER
Public Class Methods
new()
click to toggle source
# File lib/spoom/sorbet/errors.rb, line 41 def initialize @errors = [] @current_error = nil end
parse_string(output)
click to toggle source
# File lib/spoom/sorbet/errors.rb, line 35 def self.parse_string(output) parser = Spoom::Sorbet::Errors::Parser.new parser.parse(output) end
Public Instance Methods
parse(output)
click to toggle source
# 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
Private Instance Methods
append_error(line)
click to toggle source
# File lib/spoom/sorbet/errors.rb, line 92 def append_error(line) raise "Error: Not already parsing an error!" unless @current_error @current_error.more << line end
close_error()
click to toggle source
# File lib/spoom/sorbet/errors.rb, line 85 def close_error raise "Error: Not already parsing an error!" unless @current_error @errors << @current_error @current_error = nil end
match_error_line(line)
click to toggle source
# File lib/spoom/sorbet/errors.rb, line 70 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
open_error(error)
click to toggle source
# File lib/spoom/sorbet/errors.rb, line 79 def open_error(error) raise "Error: Already parsing an error!" if @current_error @current_error = error end