Skip to content

Enforce crate naming rules of rustc #2708

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
sanmai-NL opened this issue May 17, 2016 · 8 comments · Fixed by #12766
Closed

Enforce crate naming rules of rustc #2708

sanmai-NL opened this issue May 17, 2016 · 8 comments · Fixed by #12766
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-new S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing.

Comments

@sanmai-NL
Copy link

sanmai-NL commented May 17, 2016

Actual behavior

Creating a new crate:

cargo new --bin 'UPPERcase_name'

No issue.

Compiling it:

 cargo build
warning: crate `UPPERcase_name` should have a snake case name such as `uppercase_name`, #[warn(non_snake_case)] on by default

Expected behavior

Cargo should only create crates with names that raise rustc warnings if forced.

Meta

  rustc --version --verbose
rustc 1.8.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.8.0
  cargo --version
cargo 0.10.0 (10ddd7d 2016-04-08)
@gsurrel
Copy link

gsurrel commented May 8, 2017

I would say that it should warn before creation that it's not according to rules and offer the following options:

  1. Edit the name
  2. Continue
  3. Continue and add the ignore directive where needed

@carols10cents carols10cents added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-new labels Sep 25, 2017
@shnaramn
Copy link

Can I try a fix for this? I've just started learning rust/cargo and this feels like a good first fix.

There are several validations for crate name at function check_name in cargo_new.rs. Will adding a warning (similar to the existing ones) about the casing be a good fix? The existing validations don't prompt for a new name. Want to be consistent with the existing behavior.

@epage epage added the S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing. label Sep 28, 2023
@epage
Copy link
Contributor

epage commented Sep 28, 2023

So long as its only a warning, I feel that is the most we should do. My main concern about a warning is making sure we get the language right to give people a heads up without coming across to strong (since they can just allow it or ignore it). I wonder if we should also check the status of the warning in the lints table (#12115).

@sanmai-NL
Copy link
Author

Rather than warning or not warning you could just be informative. Something like this name doesn't match the naming rules standard X, please see documentation blah blah blah blah.

@epage
Copy link
Contributor

epage commented Sep 28, 2023

How is that different from a warning?

@sanmai-NL
Copy link
Author

A warning is a value judgment.

shnaramn pushed a commit to shnaramn/cargo that referenced this issue Sep 30, 2023
Warns about not using snake case format when creating new packages with `cargo new` command.
@shnaramn
Copy link

shnaramn commented Sep 30, 2023

If this change looks good, I can start a PR:
master...shnaramn:cargo:WarnAboutNameCase

Using the language mentioned in RFC 430.

I've not added the link to API naming guidelines since it still stays unclear for naming convention for crates.

The fix reuses the method that checks for snake_case when building.

@epage
Copy link
Contributor

epage commented Oct 2, 2023

Theres details to work out in a PR but that is the general direction of what I'd expect.

bors added a commit that referenced this issue Oct 23, 2023
Warn about crate name's format when creating new crate

### What does this PR try to resolve?
Warns about a crate's name during creation (`crate new ...`) if it doesn't follow the preferred snake_case format.

Fixes #2708

The warning message uses the language mentioned in [RFC 430](https://github.com/rust-lang/rfcs/blob/master/text/0430-finalizing-naming-conventions.md#general-naming-conventions).

### How should we test and review this PR?
Verified existing tests succeeded with updates.  Added new tests to verify fix.

### Additional information
The link to [API naming guidelines](https://rust-lang.github.io/api-guidelines/naming.html) was not used since it still stays `unclear` for naming convention for crates.
@bors bors closed this as completed in 901018c Oct 23, 2023
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` Command-new S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants