gomarkdoc icon indicating copy to clipboard operation
gomarkdoc copied to clipboard

Update examples to better match godoc/pkg.go.dev

Open ThatsMrTalbot opened this issue 3 years ago • 2 comments

The current implementation was stripping out all comments inside the example function, this fixes that behaviour.

It also strips out the leading and trailing braces to better match how godoc and pkg.go.dev render examples (for example https://pkg.go.dev/k8s.io/[email protected]/tools/clientcmd)

This implementation takes inspiration from https://github.com/golang/gddo/blob/20d68f94ee1f7547de2b1c68627253df20c8d45e/doc/code.go#L314-L329

ThatsMrTalbot avatar Jun 01 '22 00:06 ThatsMrTalbot

Thanks for the PR @ThatsMrTalbot!

I played around some with your code and wasn't able to find any cases where it's different from the existing behavior. Can you point me to a package where this code generates a different output than the current code for the tool?

princjef avatar Jul 07 '22 07:07 princjef

I have created a test case that shows what I am seeing:

https://gist.github.com/ThatsMrTalbot/fa0ade54937d1251220ac61c0e631ef1

If you run that in an empty directory it will print out the output from the master branch, and from my branch based off a simple example function.

In the comments I have put the output, as you can see the output is missing comments without the changes, and has additional wrapping braces.

{

	fmt.Println(i)

	Foo()
}

vs

// Lots
// Of
// Comments
// Here

fmt.Println(i)

// Call Bar
Foo()

ThatsMrTalbot avatar Jul 07 '22 09:07 ThatsMrTalbot

Thanks for the detailed repro @ThatsMrTalbot! I've updated your change with a test that demonstrates the difference and fixed a linting error. Things otherwise look good 💯

princjef avatar Jun 11 '23 22:06 princjef

Codecov Report

Merging #69 (f172b91) into master (88639c6) will decrease coverage by 0.36%. The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master      #69      +/-   ##
==========================================
- Coverage   58.62%   58.26%   -0.36%     
==========================================
  Files          20       20              
  Lines        1815     1826      +11     
==========================================
  Hits         1064     1064              
- Misses        666      677      +11     
  Partials       85       85              
Impacted Files Coverage Δ
lang/example.go 8.88% <0.00%> (-2.88%) :arrow_down:

codecov-commenter avatar Jun 11 '23 22:06 codecov-commenter