Skip to content
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

Warn when uploading a new crate with a hyphen in its name #10843

Closed
alice-i-cecile opened this issue Jul 10, 2022 · 4 comments
Closed

Warn when uploading a new crate with a hyphen in its name #10843

alice-i-cecile opened this issue Jul 10, 2022 · 4 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@alice-i-cecile
Copy link

Problem

Hyphens in crate names suck for all sorts of reasons, see hyphens considered harmful. Unfortunately, cargo will happily allow you to upload a crate with a hyphen without warning.

Changing the name of crates once published appears to be effectively impossible as well.

Proposed Solution

When users are uploading a new crate, cancel the upload and warn the user if there is a hyphen in the name.

Allow users to bypass this by providing an explicit flag.

Notes

Related to #2775.

@alice-i-cecile alice-i-cecile added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Jul 10, 2022
@ghostbutter-games
Copy link

Very much agree with this. I spent hours trying to figure out whether I should name crates with hyphens or underscore and there not being an official consensus on this is pretty weird (basically everything else has a convention). Since hyphens get converted to underscores under the hood anyways, this would be a good way to guide people towards more consistent naming of crates.

@epage
Copy link
Contributor

epage commented Jul 11, 2022

Hyphens in crate names suck for all sorts of reasons, see hyphens considered harmful. Unfortunately, cargo will happily allow you to upload a crate with a hyphen without warning.

Do you mean crate names or package names? The linked RFC only speaks to crate names and not package names. I don't think I've seen a consensus that underscrores should be preferred to hyphens in package names and making cargo opinionated without more context or consensus seems premature.

btw cargo add is now in cargo and it accepts either and normalizes them though there is still some room for improvement (e.g. #10680)

Changing the name of crates once published appears to be effectively impossible as well.

I've been bit with this with clap. A clap developer prematurely took the clap-man names but then another one made several clap_* crates. Now I feel I can't use the clap-man name because I'd like _ and - to be consistent within clap (I would have preferred - but that boat has sailed). I ended up having to go with the clap_mangen name to get out of this.

@alice-i-cecile
Copy link
Author

Package names, my apologies. I've run into two serious headaches with these:

  • macros not working without special casing
  • divergences between the package name and how it's used; users will put foo-bar in their Cargo.toml, but use foo_bar in their library.

I also think there's a "confusability" argument to be made for progressively disallowing hyphens.

@ehuss
Copy link
Contributor

ehuss commented Aug 13, 2022

I'm going to close, as I don't think we'll be adding a warning in the short term. There are far too many packages using hyphens, and there isn't an agreed-upon standard. People are free to pick which particular method they want, and some people strongly prefer one or the other.

I think if any change is made to steer people towards one form or the other will require an RFC. This would impact a large number of users, and I suspect it just isn't worth the investment.

If there are specific places where the friction could be reduced, I think it would be good to examine those without jumping to a solution first. For example cargo add will handle the translation for the user.

I'm not entire sure I understand the two points raised. Macros shouldn't have any involvement with package names. And for the second point, I'm not really clear because crate names (in Rust) can only have underscores.

I understand that the difference from a package name and the library crate name can cause some confusion. However, I think there are several other issues already covering that (such as #2775 and #6827).
If there are specific situations where some use-case is difficult (such as whatever is alluded to with macros), I suggest opening a new issue with those specifics if there isn't already an issue for them.

@ehuss ehuss closed this as not planned Won't fix, can't repro, duplicate, stale Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

4 participants