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

x/tools/godoc,gddo: do not swallow code after output comments if it is not in concluding lines #33276

Open
ysmood opened this issue Jul 25, 2019 · 3 comments
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ysmood
Copy link

ysmood commented Jul 25, 2019

What did you do?

Pushed example code to github:

func ExampleScanner() {
	frame := byframe.Encode([]byte("test"))
	s := byframe.NewScanner(bytes.NewReader(frame))

	for s.Scan() {
		fmt.Println(string(s.Frame()))
		// Output: test
	}
}

Here's the link for the project: https://github.com/ysmood/byframe/blob/7f2ce7731dfc716eb39bb99f4a93e2f43ce11fac/byframe_test.go#L32

What did you expect to see?

On the godoc website we should see

frame := byframe.Encode([]byte("test"))
s := byframe.NewScanner(bytes.NewReader(frame))

for s.Scan() {
    fmt.Println(string(s.Frame()))
}

What did you see instead?

The last } was missing:

frame := byframe.Encode([]byte("test"))
s := byframe.NewScanner(bytes.NewReader(frame))

for s.Scan() {
    fmt.Println(string(s.Frame()))

Here's the link for the godoc: https://godoc.org/github.com/ysmood/byframe#example-Scanner

@agnivade
Copy link
Contributor

I believe this is because your Output: comments are before the closing brace. As you can see here - https://golang.org/pkg/testing/#hdr-Examples, output comments are always concluding line comments.

Can you move the output comment below the closing brace and check ?

@agnivade agnivade added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jul 25, 2019
@ysmood
Copy link
Author

ysmood commented Jul 25, 2019

Thank you for your quick response, If I move it out, it will work properly.

But I still think this is a bug or something need to be optimized. If my code format is wrong the go test should fail or the godoc website should report the misuse, not silently swallow the close-brace.

@agnivade
Copy link
Contributor

Should be doable with a little bit of work. The offending code is here -
https://github.com/golang/tools/blob/2e34cfcb95cb3d24b197d58fe6d25046b8f25c86/godoc/godoc.go#L588-L591

Instead of just blindly wiping anything after the index, we need to start from bottom and stop after the first non-comment line.

Note that this is affects both godoc and godoc.org. The two have different codebases.

@agnivade agnivade changed the title godoc: close-brace is missing on example x/tools/godoc,gddo: do not swallow code after output comments if it is not in concluding lines Jul 26, 2019
@gopherbot gopherbot added this to the Unreleased milestone Jul 26, 2019
@agnivade agnivade added NeedsFix The path to resolution is known, but the work has not been done. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jul 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants