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 about crate name's format when creating new crate #12766

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ fn check_name(
name
))?;
}
let name_in_lowercase = name.to_lowercase();
if name != name_in_lowercase {
shell.warn(format!(
"the name `{name}` is not snake_case or kebab-case which is recommended for package names, consider `{name_in_lowercase}`"
))?;
}

Ok(())
}
Expand Down
24 changes: 24 additions & 0 deletions tests/testsuite/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ fn non_ascii_name() {
"\
[WARNING] the name `Привет` contains non-ASCII characters
Non-ASCII crate names are not supported by Rust.
[WARNING] the name `Привет` is not snake_case or kebab-case which is recommended for package names, consider `привет`
[CREATED] binary (application) `Привет` package
",
)
Expand Down Expand Up @@ -501,6 +502,29 @@ or change the name in Cargo.toml with:
.run();
}

#[cargo_test]
fn non_snake_case_name() {
cargo_process("new UPPERcase_name")
.with_stderr(
"\
shnaramn marked this conversation as resolved.
Show resolved Hide resolved
[WARNING] the name `UPPERcase_name` is not snake_case or kebab-case which is recommended for package names, consider `uppercase_name`
[CREATED] binary (application) `UPPERcase_name` package
",
)
.run();
}

#[cargo_test]
fn kebab_case_name_is_accepted() {
cargo_process("new kebab-case-is-valid")
.with_stderr(
"\
[CREATED] binary (application) `kebab-case-is-valid` package
",
)
.run();
}

#[cargo_test]
fn git_default_branch() {
// Check for init.defaultBranch support.
Expand Down