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

fix: supply proper location for GitHub Action format #1081

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jsocol
Copy link

@jsocol jsocol commented Feb 6, 2023

This fixes the issue in #1071 with the GitHub Action output using the wrong location values. It's in two commits. The first exposes lint.FileLocationFromPBLocation as a public method, and adds tests for it. The second uses that method to remove the conversion logic from the GitHub Action formatter and fixes the tests that had the file locations specified.

@jsocol jsocol requested a review from a team as a code owner February 6, 2023 21:02
@google-cla
Copy link

google-cla bot commented Feb 6, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@noahdietz noahdietz changed the title Fix/GitHub actions formatter fix: supply proper location for GitHUb Action format Feb 6, 2023
@noahdietz
Copy link
Collaborator

cc @achew22 author of the original change for github_actions format

@jsocol
Copy link
Author

jsocol commented Feb 6, 2023

CLA signed and check re-run.

Definitely open to whatever feedback here. Like I mentioned on #1071, there's a more-focused path that only fixes the Span-reading logic in the github formatter, though it seems like centralizing that logic is a more future-proof solution. There are certainly other ways to do that.

@noahdietz noahdietz changed the title fix: supply proper location for GitHUb Action format fix: supply proper location for GitHub Action format Feb 6, 2023
Copy link
Collaborator

@noahdietz noahdietz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm generally happy to take this change. I don't personally use this format though, which is why I'd like to see if @achew22 has any thoughts.

Thanks for opening this PR (and the issue that I never responded too 😅)

@jsocol
Copy link
Author

jsocol commented Feb 7, 2023

Thanks for opening this PR (and the issue that I never responded too 😅)

As a fellow OSS maintainer, I share your 😅 . Thanks for this tool, it's hugely helpful!

fmt.Fprintf(&buf, ",line=%d", problem.Location.Span[0])
}
location := lint.FileLocationFromPBLocation(problem.Location)
fmt.Fprintf(&buf, ",line=%d,col=%d,endLine=%d,endColumn=%d", location.Start.Line, location.Start.Column, location.End.Line, location.End.Column)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we believe that all findings contain line and column numbers? Sorry if that's obvious from other changes in the project but this caused it to nil pointer exception for me before I made the change you're removing here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely depends on the logic in lint/problem.go being correct, but according to the code comment on line 128 the underlying Span should be guaranteed to have either 3 (line,startCol,endCol) or 4 (startLine,startCol,endLine,endCol) values.

I'd be curious if you have a case to reproduce that, and if it also causes problems for the YAML and JSON output? I think those should panic on main if a span is ever too short

lint/problem.go Outdated
// protocol buffer SourceCodeInfo_Location
func fileLocationFromPBLocation(l *dpb.SourceCodeInfo_Location) fileLocation {
func FileLocationFromPBLocation(l *dpb.SourceCodeInfo_Location) FileLocation {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize now that this is more or less directly reversing a deliberate decision in #195 to not have two types of "location." If that's still desirable then maybe the other path of fixing the math directly in the github formatter, or possibly a third option of trying to centralize the "formatter" concept somewhere they could share utilities like this

James Socol added 2 commits June 14, 2023 10:14
Make the internal method lint.FileLocationFromPBLocation public so that
formatters beyond the YAML and JSON marshal methods can rely on the same
logic to translate protobuf Spans into useable file locations.
Use the lint.FileLocationFromPBLocation method to get the correct
problem locations for the GitHub Actions formatter, rather than
re-implementing the conversion from PB location to file location.
@jsocol jsocol force-pushed the fix/github-actions-formatter branch from b018fd9 to 5a64cb4 Compare June 14, 2023 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants