Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Extractor: give the go.mod comment groups a source location #232

Merged
merged 2 commits into from Jun 30, 2020

Conversation

smowton
Copy link
Contributor

@smowton smowton commented Jun 26, 2020

The comment group is now omitted entirely if empty, and otherwise delimits the range of the comments ascribed to this group.

Pre-emptive reviewer response: yes, really, Go's math package only provides Min and Max for float types, so you either have to cast back and forth, take a dependency such as github.com/pkg/math or write your own IntMin and IntMax.

@smowton smowton requested a review from a team June 26, 2020 15:28
owen-mc
owen-mc previously approved these changes Jun 27, 2020
Copy link
Collaborator

@max-schaefer max-schaefer left a comment

Choose a reason for hiding this comment

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

Looks sensible overall, some minor comments.

import go

from CommentGroup cg
select cg.getLocation()
Copy link
Collaborator

Choose a reason for hiding this comment

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

The test runner automatically includes the location in the test output, so in general you shouldn't need to explicitly select locations in tests.

extractGoModComment(tw, comment, grouplbl, idx)
idx++
commentEndCol := comment.Start.LineRune + len(comment.Token)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Our end positions are generally inclusive, so I think this should be

Suggested change
commentEndCol := comment.Start.LineRune + len(comment.Token)
commentEndCol := comment.Start.LineRune + len(comment.Token) - 1

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, do I interpret the test failures on Windows correctly to mean that comment.Token includes a \r if the line ending is \r\n? If so, we'll probably want to chop it off.

@smowton smowton force-pushed the smowton/fix/go-mod-comment-blocks branch 2 times, most recently from 8cd41b5 to 90b06c2 Compare June 29, 2020 11:25
The comment group is now omitted entirely if empty, and otherwise delimits the range of the comments ascribed to this group.
@smowton smowton force-pushed the smowton/fix/go-mod-comment-blocks branch from 90b06c2 to ce417aa Compare June 29, 2020 12:49
@smowton
Copy link
Contributor Author

smowton commented Jun 30, 2020

The \r thing is confirmed as a bug by the Golang team btw: golang/go#39913

Copy link
Collaborator

@max-schaefer max-schaefer left a comment

Choose a reason for hiding this comment

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

One minor suggestion, otherwise LGTM. (And well done for reporting the bug!)

}
}

func stripTrailingCR(input string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This means the source locations and lengths for comments will be the same on Windows and Unix-like platforms.

Note this works around golang/go#39913
@smowton smowton force-pushed the smowton/fix/go-mod-comment-blocks branch from ce417aa to 0252c72 Compare June 30, 2020 13:08
@smowton
Copy link
Contributor Author

smowton commented Jun 30, 2020

@max-schaefer done

@max-schaefer max-schaefer merged commit 595866a into github:master Jun 30, 2020
ceh pushed a commit to ceh-forks/codeql-go that referenced this pull request Jul 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants