Skip to content

Commit

Permalink
refactor: Make lint names snake_case
Browse files Browse the repository at this point in the history
  • Loading branch information
Muscraft committed Mar 25, 2024
1 parent 77506e5 commit 0a400d5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/cargo/core/workspace.rs
Expand Up @@ -1128,18 +1128,23 @@ impl<'gctx> Workspace<'gctx> {

pub fn emit_lints(&self, pkg: &Package, path: &Path) -> CargoResult<()> {
let mut error_count = 0;
let lints = pkg
let toml_lints = pkg
.manifest()
.resolved_toml()
.lints
.clone()
.map(|lints| lints.lints)
.unwrap_or(manifest::TomlLints::default())
.unwrap_or(manifest::TomlLints::default());
let cargo_lints = toml_lints
.get("cargo")
.cloned()
.unwrap_or(manifest::TomlToolLints::default());
let normalized_lints = cargo_lints
.into_iter()
.map(|(name, lint)| (name.replace('-', "_"), lint))
.collect();

check_implicit_features(pkg, &path, &lints, &mut error_count, self.gctx)?;
check_implicit_features(pkg, &path, &normalized_lints, &mut error_count, self.gctx)?;
if error_count > 0 {
Err(crate::util::errors::AlreadyPrintedError::new(anyhow!(
"encountered {error_count} errors(s) while running lints"
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/util/lints.rs
Expand Up @@ -67,7 +67,7 @@ pub struct LintGroup {
}

const RUST_2024_COMPATIBILITY: LintGroup = LintGroup {
name: "rust-2024-compatibility",
name: "rust_2024_compatibility",
default_level: LintLevel::Allow,
desc: "warn about compatibility with Rust 2024",
edition_lint_opts: Some((Edition::Edition2024, LintLevel::Deny)),
Expand Down Expand Up @@ -150,7 +150,7 @@ impl From<TomlLintLevel> for LintLevel {
/// [RFC #3143]: https://rust-lang.github.io/rfcs/3143-cargo-weak-namespaced-features.html
/// [RFC #3491]: https://rust-lang.github.io/rfcs/3491-remove-implicit-features.html
const IMPLICIT_FEATURES: Lint = Lint {
name: "implicit-features",
name: "implicit_features",
desc: "warn about the use of unstable features",
groups: &[RUST_2024_COMPATIBILITY],
default_level: LintLevel::Allow,
Expand Down
42 changes: 42 additions & 0 deletions tests/testsuite/lints_table.rs
Expand Up @@ -846,3 +846,45 @@ fn cargo_lints_success() {
)
.run();
}

#[cargo_test]
fn cargo_lints_underscore_supported() {
Package::new("bar", "0.1.0").publish();
let foo = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2021"
authors = []
[lints.cargo]
"implicit_features" = "warn"
[dependencies]
bar = { version = "0.1.0", optional = true }
"#,
)
.file("src/lib.rs", "")
.build();

foo.cargo("check -Zcargo-lints")
.masquerade_as_nightly_cargo(&["-Zcargo-lints"])
.with_stderr(
"\
warning: unused optional dependency
--> Cargo.toml:12:17
|
12 | bar = { version = \"0.1.0\", optional = true }
| ---
|
[UPDATING] `dummy-registry` index
[LOCKING] [..]
[CHECKING] foo v0.0.1 ([CWD])
[FINISHED] [..]
",
)
.run();
}

0 comments on commit 0a400d5

Please sign in to comment.