-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
proposal: cmd/vet: should warn about broken doc links #57963
Comments
To make such a check feasible given the current state of vet, what it can check will probably need to be restricted to checking symbols from packages that are directly imported. Another this to clarify is whether cmd/vet should consider it a bug to be version inconsistent. If there is a doc link that refers to code that is only available for a newer go version, is that a bug? A similar question about the standard library versions. Is it any standard library version? Or the one being used to compile? |
I am slightly leaning towards this needs to be a proposal. |
That restriction would be fine with me. In my use case, I'd almost always be referencing packages that I already import in my project. Vet could still check packages which are in the module dependency graph, but not directly imported by the current package, but I'm not too fussed about that distinction. I'd still like for the check to warn me about
Again a valid question. I think "name exists in any version of the referenced package" is probably better, although I'm not sure if pkg.go.dev would actually render links properly if a name doesn't exist in the imported or Thinking about your two points (potentially having to look up extra modules/packages, and potentially having to be aware of many versions at once), what occurs to me is that perhaps it should be pkgsite the one to check against broken doc links. pkg.go.dev already contains practically all open source Go modules and their known versions, so it would be able to perform better checks. One downside of having the check in pkg.go.dev and not in cc @golang/pkgsite
Perhaps you're right, though at this point I'm 50/50 on whether this should be a proposal for cmd/vet or x/pkgsite :) |
Perhaps another reason for pkgsite to warn about broken doc links is that it already does the work to render the links, so it might already be aware of which are broken. |
Yet another idea: if broken doc links were to somehow be included as part of a "quality report" produced by pkg.go.dev, it would be nice as a module author to fetch that from time to time and fix any errors. For example, |
If the package mentioned in the doc comment is provided by some module in the module graph, I would expect the doc link to in general refer to that version of the package. In that case, I think it would be reasonable for On the other hand, if the package is not present at all in the build graph — maybe it is talking about a deprecated alternative, or a package that interferes destructively — then the potential for false-positives is much higher. |
I think we would all like it to be easier to preview pkgsite's rendering of your locally edited packages, and it's something we're considering doing, perhaps integrated into gopls. If we did that, it could be made to visually flag broken links. That would make it easier for someone actively reviewing their doc comments to detect problems, though of course it still wouldn't enforce invariants like a vet check would. |
It seems like gopls is getting some awareness of godoc/comment links via #64648, so perhaps it might also be able to start flagging cases where it knows for sure that a link is wrong. |
See also #63929, which proposes a more general checker for go doc problems. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Wrote some godoc to include a doc link referencing a missing name, as well as an example referencing a missing name.
What did you expect to see?
go vet
should warn about both.What did you see instead?
go vet
only warns about the unknown name in the example name, but not in the doc link:I write this bug because I'm improving godocs in a project of mine to use doc links. It's hard to tell if I'm making any mistakes when referencing packages or exported names, because vet isn't helping me at all. I will likely look at the rendered godoc after pushing to a branch, but it's going to be very tricky to verify every link renders and works properly by hand.
I think vet should warn about all forms of broken links, even
[Name1]
or[pkg.Name1]
. I realise that we want to be careful with backwards compatibility; old godocs may contain text which happens to be a broken link. In those cases, I'd want to be warned as well, because I want to either fix the link, or change the godoc so that it's not a link - by using a block quote for example.The text was updated successfully, but these errors were encountered: