@@ -56,22 +56,35 @@ class ParseError < Spoom::Error; end
5656 ] #: Array[String]
5757
5858 class << self
59+ # Used when only Sorbet errors are needed and leading stderr warnings can be ignored.
5960 #: (String output, ?error_url_base: String) -> Array[Error]
6061 def parse_string ( output , error_url_base : DEFAULT_ERROR_URL_BASE )
62+ parse_result ( output , error_url_base : error_url_base ) . errors
63+ end
64+
65+ # Used when callers need both parsed Sorbet errors and leading stderr warnings.
66+ #: (String output, ?error_url_base: String) -> ParseResult
67+ def parse_result ( output , error_url_base : DEFAULT_ERROR_URL_BASE )
6168 parser = Spoom ::Sorbet ::Errors ::Parser . new ( error_url_base : error_url_base )
62- parser . parse ( output )
69+ parser . parse_result ( output )
6370 end
6471 end
6572
6673 #: (?error_url_base: String) -> void
6774 def initialize ( error_url_base : DEFAULT_ERROR_URL_BASE )
6875 @errors = [ ] #: Array[Error]
76+ @warnings = [ ] #: Array[String]
6977 @error_line_match_regex = error_line_match_regexp ( error_url_base ) #: Regexp
7078 @current_error = nil #: Error?
7179 end
7280
7381 #: (String output) -> Array[Error]
7482 def parse ( output )
83+ parse_result ( output ) . errors
84+ end
85+
86+ #: (String output) -> ParseResult
87+ def parse_result ( output )
7588 output . each_line do |line |
7689 break if /^No errors! Great job\. / . match? ( line )
7790 break if /^Errors: / . match? ( line )
@@ -85,10 +98,14 @@ def parse(output)
8598 next
8699 end
87100
88- append_error ( line ) if @current_error
101+ if @current_error
102+ append_error ( line )
103+ else
104+ append_warning ( line )
105+ end
89106 end
90107 close_error if @current_error
91- @errors
108+ ParseResult . new ( @errors , @warnings )
92109 end
93110
94111 private
@@ -144,6 +161,11 @@ def append_error(line)
144161 end
145162 @current_error . more << line
146163 end
164+
165+ #: (String warning) -> void
166+ def append_warning ( warning )
167+ @warnings << warning
168+ end
147169 end
148170
149171 class Error
@@ -214,6 +236,20 @@ def to_junit_xml_element
214236 testcase_element
215237 end
216238 end
239+
240+ class ParseResult
241+ #: Array[Error]
242+ attr_reader :errors
243+
244+ #: Array[String]
245+ attr_reader :warnings
246+
247+ #: (Array[Error] errors, Array[String] warnings) -> void
248+ def initialize ( errors , warnings )
249+ @errors = errors
250+ @warnings = warnings
251+ end
252+ end
217253 end
218254 end
219255end
0 commit comments