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: Consider adding "ban" to go.mod #32780
Comments
Edit (per #32780 (comment)): I should have used On one project I worked on, we deprecated a repository in favor of another. While refactoring, it was easy to accidentally reintroduce a dependency on the deprecated project, so I added a But that is a total hack, and it gives you a not-very-informative message when you mistakenly import that package:
First-class support for blacklisting specific packages/modules is something I would have used in the past, had it been available. |
@smoyer64 what are you using for an editor or IDE, and are you using Are you looking for functionality similar to From https://godoc.org/golang.org/x/tools/cmd/goimports:
CC @stamblerre @heschik |
@thepudds We're using a variety of editors but the most prevalent is VSCode with gopls under the hood followed closely by vim with vim-go. In both cases we could use |
Regarding the specific proposal: Regarding Ultimately this sounds like an editor feature to me. As a point of reference, Eclipse has the concepts of "favorite imports" and "type filters", which in combination sound very close to what you're asking for here. |
It does seem a bit strange to ban the Following the thoughts related to |
I don't understand the focus on not adding the thing you don't want. Wouldn't it be better for goimports or the editor to add the thing you do want, i.e. |
Well ... if everything always worked in the way you imagine, you wouldn't need to to focus on the negatives (which would be more pleasant as is general in life). I've been using Maven for Java dependency management for many years and there are still occasions where you need to force dependency versions (as you can in Go modules) or exclude dependencies as I'm suggesting here. If a very mature and IMHO stream-lined dependency management system still has this problem, is it realistic for Go modules to solve the problem in its first year? Pardon my incorrect terminology above ... I guess what I was trying to say is that if a repository can be implicitly considered a module for A couple more good ideas for alternate words for |
@mark-rushakoff, you can already use an |
@smoyer64, as @thepudds and @heschik note, this feature is not a good fit for the
|
@bcmills From the discussion above, I agree that's the correct solution to my problem. I'll submit the bug over there but wanted to thank you all for indulging me and for the productive discussion. |
I prefer
|
Our organization has fully embraced the Go module dependency management
introduced in Go 1.11 but we have a recurring frustration that the tool could easily handle. This problem isn't limited to a a single package but I'll outline the most common occurrence below. I should also point out that the word
ban
could be replaced byveto
,reject
or any other word that is a better antonym forrequire
.We pretty consistently use the following import statement in our code:
If you use
log.Error(err)
before adding the import, many IDEs will be helpful and import the standard library'slog
package for you. There are three or four packages that we consistently have to expel from our code. What I'm proposing is thatmod.go
provide a section that allows us to specify packages that we don't want imported.This behavior further strengthens Go's dependency management by making sure libraries that aren't intended to be used in a project are rejected. A pleasant side effect is that IDEs will continue to highlight the error as a missing package so you can properly add the required import statement.
The text was updated successfully, but these errors were encountered: