Skip to content
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

frontend: refactor lint rule check printing functionality #5238

Merged
merged 1 commit into from
Aug 15, 2024

Conversation

daghack
Copy link
Collaborator

@daghack daghack commented Aug 12, 2024

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 of LintResults), you currently have to no choice but to unmarshall the JSON twice, once implicitly in PrintLintViolations and the second in order to access the LintResults.

This PR moves this functionality to (results *LintResults) PrintWarningsToWriter(w io.Writer) error, and leaves PrintLintViolations in place as a function that simply unmarshals the bytes and calls the PrintWarningsToWriter 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 to PrintWarningsToWriter.

@daghack daghack marked this pull request as draft August 12, 2024 05:25
@daghack daghack self-assigned this Aug 12, 2024
@daghack daghack marked this pull request as ready for review August 12, 2024 13:41
@daghack daghack changed the title refactor lint rule check printing functionality frontend: refactor lint rule check printing functionality Aug 12, 2024
frontend/subrequests/lint/lint.go Outdated Show resolved Hide resolved
frontend/subrequests/lint/lint.go Outdated Show resolved Hide resolved
frontend/subrequests/lint/lint.go Outdated Show resolved Hide resolved
Signed-off-by: Talon Bowler <talon.bowler@docker.com>
@daghack daghack force-pushed the print-lint-violations-refactor branch from 80adb9f to 41d3195 Compare August 14, 2024 21:15
@daghack daghack requested a review from tonistiigi August 14, 2024 21:30
@tonistiigi tonistiigi merged commit bff1d81 into moby:master Aug 15, 2024
91 checks passed
@tonistiigi
Copy link
Member

@daghack You can vendor this to buildx to make sure the callers there are updated as well.

billywr pushed a commit to billywr/buildkit that referenced this pull request Aug 15, 2024
frontend: refactor lint rule check printing functionality
Signed-off-by: Billy Owire <billyowire@microsoft.com>
@daghack daghack deleted the print-lint-violations-refactor branch August 15, 2024 15:48
billywr pushed a commit to billywr/buildkit that referenced this pull request Aug 19, 2024
frontend: refactor lint rule check printing functionality
Signed-off-by: Billy Owire <billyowire@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants