-
Notifications
You must be signed in to change notification settings - Fork 28
Preserve Sorbet warnings in formatted srb output #971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,22 +56,35 @@ class ParseError < Spoom::Error; end | |
| ] #: Array[String] | ||
|
|
||
| class << self | ||
| # Used when only Sorbet errors are needed and leading stderr warnings can be ignored. | ||
| #: (String output, ?error_url_base: String) -> Array[Error] | ||
| def parse_string(output, error_url_base: DEFAULT_ERROR_URL_BASE) | ||
| parse_result(output, error_url_base: error_url_base).errors | ||
| end | ||
|
|
||
| # Used when callers need both parsed Sorbet errors and leading stderr warnings. | ||
| #: (String output, ?error_url_base: String) -> ParseResult | ||
| def parse_result(output, error_url_base: DEFAULT_ERROR_URL_BASE) | ||
| parser = Spoom::Sorbet::Errors::Parser.new(error_url_base: error_url_base) | ||
| parser.parse(output) | ||
| parser.parse_result(output) | ||
| end | ||
| end | ||
|
|
||
| #: (?error_url_base: String) -> void | ||
| def initialize(error_url_base: DEFAULT_ERROR_URL_BASE) | ||
| @errors = [] #: Array[Error] | ||
| @warnings = [] #: Array[String] | ||
| @error_line_match_regex = error_line_match_regexp(error_url_base) #: Regexp | ||
| @current_error = nil #: Error? | ||
| end | ||
|
|
||
| #: (String output) -> Array[Error] | ||
| def parse(output) | ||
| parse_result(output).errors | ||
| end | ||
|
|
||
|
Comment on lines
81
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, let's just return a ParseResult directly?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could although it's public API and would break callers if there are any |
||
| #: (String output) -> ParseResult | ||
| def parse_result(output) | ||
| output.each_line do |line| | ||
| break if /^No errors! Great job\./.match?(line) | ||
| break if /^Errors: /.match?(line) | ||
|
|
@@ -85,10 +98,14 @@ def parse(output) | |
| next | ||
| end | ||
|
|
||
| append_error(line) if @current_error | ||
| if @current_error | ||
| append_error(line) | ||
| else | ||
| append_warning(line) | ||
| end | ||
| end | ||
| close_error if @current_error | ||
| @errors | ||
| ParseResult.new(@errors, @warnings) | ||
| end | ||
|
|
||
| private | ||
|
|
@@ -144,6 +161,11 @@ def append_error(line) | |
| end | ||
| @current_error.more << line | ||
| end | ||
|
|
||
| #: (String warning) -> void | ||
| def append_warning(warning) | ||
| @warnings << warning | ||
| end | ||
| end | ||
|
|
||
| class Error | ||
|
|
@@ -214,6 +236,20 @@ def to_junit_xml_element | |
| testcase_element | ||
| end | ||
| end | ||
|
|
||
| class ParseResult | ||
| #: Array[Error] | ||
| attr_reader :errors | ||
|
|
||
| #: Array[String] | ||
| attr_reader :warnings | ||
|
|
||
| #: (Array[Error] errors, Array[String] warnings) -> void | ||
| def initialize(errors, warnings) | ||
| @errors = errors | ||
| @warnings = warnings | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we just change this one to return a
ParseResult?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I had initially but Tapioca uses
parse_stringin here. Which I had to execute during https://github.com/Shopify/spoom/blob/main/bin/export-rbi. So I went with a new function instead to be backwards compatible and ship this easier.