-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
lint against glob imports of enum variants #541
Comments
I am unsure about this – it very much depends on how often those Variants are used within a crate and how likely name clashes are IMHO. OTOH many modules already reexport enum variants, so perhaps that's the way to go. |
I think this depends on the naming of the variants, too. And how they're intended to be used. Pedantic lint okay though. Not sure about a |
I think modern Rust style is to name enum variants without any kind of prefix and assume that they will always be used with the enum name as a prefix. I can think of two exceptions:
|
Fair enough |
I'd also argue for leaving |
@birkenfeld not sure how customisable lints can be, but it might be nice to separate that out some how. I actually think this is poor style - if variants are named to take the enum name into account, then that applies equally in the module they are defined as elsewhere, and it means less chance of a name clash with other types. I can see how reasonable people can disagree about this though. |
I'm not talking about that situation, but there are situations where the enum is ubiquitous enough (or the names are obvious enough) that you don't need namespacing |
We're already too opinionated in some cases (shadowing and |
We can make it pedantic and postpone bikeshed to the RfC. clippy_pedantic has a very low bar for inclusion. |
It is usually better style to use the prefixed name of an enum variant, rather than importing variants. The glob form of this is particularly poor form.
Two possible lints:
use ...::Foo::*;
to see ifFoo
is an enum,Bonus points if the lint can suggest renamed versions of the variants in the file.
In fact, we could probably lint against all glob imports too (if there isn't a lint for this already, I couldn't find one by searching for "glob").
The text was updated successfully, but these errors were encountered: