Format Init/New Directory for Cargo.toml and Package Names #15452
+24
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Format Init/New Directory for Cargo.toml and Package Names
Motivation
This started when I was porting (nob.h)[https://github.com/tsoding/nob.h] to Rust as a fun side project and I named my directory
nob.rs
before initialization (I like to make my directory first then go in andcargo init
it). I got an error saying that.
is an illegal char. Wasn't a fan, so I decided to add a function that auto fixes it and still provides the error as a warning (the error on the legality of the parent directory's name)(This my first PR, so I am sorry if my explanation is not exactly up to par. Thank you in advance for the review!)
Testing
This passes all of the tests for
cargo_new
and all but one forcargo_init
(the one for malformed package name)TODO
--format-name
which would supersede--name <NAME>
_
Issues
The only potential problem with this merge is it would establish how crates must be named. It would not force this format, but push future crates to use the underscore syntax