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
filter comments outside of interface declaration (#50) #51
Conversation
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.
Thanks.
Yes, this ought to be fixed upstream. See golang/go#21755. Feel free to pursue that instead of you'd prefer.
If you want to fix in impl, rather than reconstructing the comment groups here, it seems like it'd be easier to adjust flattenCommentMap (remove the panic, do the position checks inline).
This PR could also use a test.
It seems like there's some semi-recent activity on fixing this in go/ast. While that's definitely the desired approach, it's a bigger challenge than I'm able to take on at the moment. I'd definitely like to add a fix/workaround to impl, as I don't think that will take a huge amount of work. In some more comprehensive testing, this PR isn't sufficient for all cases (it specifically fails with the Given the following file: package pkg
// before Interface
// Interface doc
type Interface interface {
// before Func
// Func doc
Func() // end Func
// after Func
// Func2 doc
Func2() // end Func2
// after Func2
} // end Interface
// after Interface
// before Func
// Func doc
// end Func
func (t T) Func() {
panic("not implemented") // TODO: Implement
}
// after Func2
// after Interface
// after Func
// Func2 doc
// end Func2
func (t T) Func2() {
panic("not implemented") // TODO: Implement
} I would assert that the output should be: // Func doc
// end Func
func (t T) Func() {
panic("not implemented") // TODO: Implement
}
// Func2 doc
// end Func2
func (t T) Func2() {
panic("not implemented") // TODO: Implement
} For reference, package pkg // import "test"
TYPES
type Interface interface {
// Func doc
Func() // end Func
// Func2 doc
Func2() // end Func2
} // end Interface
Interface doc In other words, only comments directly before (separated by exactly one newline) or after (separated by no newlines) a function should be output. Do you agree with that? |
I'd be happy to mimic |
Or maybe we should just remove the panic. End-of-stuff comments are rare, and easy to delete if unwanted. |
028b1fd
to
848c16d
Compare
I've taken some time to dig into this issue further, particularly into how It seems there's no good reason to mess with an I've changed this PR to change If desired, the trailing comment (e.g. the |
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.
Very nice. Thank you.
This is a fix for Issue #50. It works by filtering comments outside of the interface declaration.
Arguably, this could be fixed in the ast package itself, as it's the ast package that assigns a comment at the end of the file to the last parsed node, but maybe that's expected behavior?