frontend: refactor lint rule check printing functionality #5238
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.
Currently, the way we print out warnings in the rule checks is with the
PrintLintViolations(dt []byte, w io.Writer) error
function. One of the problems with this is that if you want to use this function to print the lint violations, but would also like to inspect other properties of the underlying data (type ofLintResults
), you currently have to no choice but to unmarshall the JSON twice, once implicitly inPrintLintViolations
and the second in order to access theLintResults
.This PR moves this functionality to
(results *LintResults) PrintWarningsToWriter(w io.Writer) error
, and leavesPrintLintViolations
in place as a function that simply unmarshals the bytes and calls thePrintWarningsToWriter
method, which removes the redundant unmarshaling.While I was at this, I also added a method to
LintResults
,PrintErrorToWriter
which will, if there is an error present in the results, print said error in a format consistent toPrintWarningsToWriter
.