Skip to content

proposal: vet: go vet should allow me to exclude files #53908

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

Closed
GregOwen opened this issue Jul 15, 2022 · 3 comments
Closed

proposal: vet: go vet should allow me to exclude files #53908

GregOwen opened this issue Jul 15, 2022 · 3 comments

Comments

@GregOwen
Copy link

I've read this issue and the linked thread that decided against supporting a line-specific "ignore vet" annotation. I'm wondering if there's an appetite for allowing go vet to ignore files.

One proposal would be to extend the packages syntax to allow "exclude" directives. Two mockups of this usage:

  1. go vet ./my/package/... --exclude=./my/package/known_bad_file.go --exclude=./my/package/other/bad_file.go
  2. go vet ./my/package/... _./my/package/known_bad_file.go _./my/package/other/bad_file.go (I personally think this is less obvious than --exclude, but it rhymes with the existing "ignore files that begin with _" syntax)

The specific use case here is that we have a legacy codebase that was developed without any vet/lint rules. Most files are fine, but there are enough files that have issues that it's not practical to clean them all up before we can start enforcing go vet. In order to clean up the codebase incrementally, I'd like to be able to enforce that go vet passes for currently-valid files and all future files, ignoring the currently-broken files for now until we can clean them up one-by-one.

@gopherbot gopherbot added this to the Proposal milestone Jul 15, 2022
@robpike
Copy link
Contributor

robpike commented Jul 16, 2022

It's already pretty easy to do this using go build's -toolexec flag. You can put whatever exclusion logic you need into a wrapper for vet.

I'd prefer you do that for this case rather than adding a way to ignore vet more easily and broadly.

@seankhliao
Copy link
Member

There is already a mechanism for this: build tags.

Otherwise this can be considered a duplicate of #44957

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jul 16, 2022
@GregOwen
Copy link
Author

Perhaps I'm misinterpreting the suggestions, but neither go build -toolexec nor build tags seem to work for this use case.

go build -toolexec

When I try to run vet using -toolexec (go build -toolexec="/path/to/vet" ./my/package/...), I get an error response from vet:

go tool compile: exit status 1
vet: invoking "go tool vet" directly is unsupported; use "go vet"

Perhaps I'm using the wrong path to the vet executable?

build tags

When I add a build tag to the top of one of the files with known vet failures (//go:build ignore_vet) then run go vet ./my/package/..., vet will skip the ignored file while building, not while vetting. The problem is that other files that depend on the ignored file will now throw errors because the type and function definitions exported by the ignored file can't be found.

What I really want is a way to build all files but suppress vet output from a select set of files.

@golang golang locked and limited conversation to collaborators Jul 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants