Commit ea92f42c authored by Rob Pike's avatar Rob Pike

cmd/doc: do not show unexported constants

The go/doc package doesn't remove unexported entries from const
and var blocks, so we must trim them ourselves.

Fixes #11008

Change-Id: Ibd60d87e09333964e2588340a2ca2b8804bbaa28
Reviewed-on: https://go-review.googlesource.com/10643Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent a7d2d483
......@@ -332,6 +332,25 @@ func (pkg *Package) symbolDoc(symbol string) {
values := pkg.findValues(symbol, pkg.doc.Consts)
values = append(values, pkg.findValues(symbol, pkg.doc.Vars)...)
for _, value := range values {
// Print each spec only if there is at least one exported symbol in it.
// (See issue 11008.)
// TODO: Should we elide unexported symbols from a single spec?
// It's an unlikely scenario, probably not worth the trouble.
// TODO: Would be nice if go/doc did this for us.
specs := make([]ast.Spec, 0, len(value.Decl.Specs))
for _, spec := range value.Decl.Specs {
vspec := spec.(*ast.ValueSpec)
for _, ident := range vspec.Names {
if isExported(ident.Name) {
specs = append(specs, vspec)
break
}
}
}
if len(specs) == 0 {
continue
}
value.Decl.Specs = specs
if !found {
pkg.packageClause(true)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment