Skip to content

Commit 1e4857a

Browse files
committed
Allow lint config to have extra custom configs
And report the unused manifest key warning for every key that we do not use, which is currently every of them.
1 parent 8d68ed4 commit 1e4857a

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

crates/cargo-util-schemas/src/manifest/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,13 @@ impl TomlLint {
15031503
Self::Config(config) => config.priority,
15041504
}
15051505
}
1506+
1507+
pub fn config(&self) -> Option<&toml::Table> {
1508+
match self {
1509+
Self::Level(_) => None,
1510+
Self::Config(config) => Some(&config.config),
1511+
}
1512+
}
15061513
}
15071514

15081515
#[derive(Serialize, Deserialize, Debug, Clone)]
@@ -1511,6 +1518,8 @@ pub struct TomlLintConfig {
15111518
pub level: TomlLintLevel,
15121519
#[serde(default)]
15131520
pub priority: i8,
1521+
#[serde(flatten)]
1522+
pub config: toml::Table,
15141523
}
15151524

15161525
#[derive(Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq)]

src/cargo/util/toml/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2265,7 +2265,7 @@ supported tools: {}",
22652265
if tool == "cargo" && !gctx.cli_unstable().cargo_lints {
22662266
warn_for_cargo_lint_feature(gctx, warnings);
22672267
}
2268-
for name in lints.keys() {
2268+
for (name, config) in lints {
22692269
if let Some((prefix, suffix)) = name.split_once("::") {
22702270
if tool == prefix {
22712271
anyhow::bail!(
@@ -2278,6 +2278,14 @@ supported tools: {}",
22782278
} else {
22792279
anyhow::bail!("`lints.{tool}.{name}` is not a valid lint name")
22802280
}
2281+
} else if let Some(config) = config.config() {
2282+
for config_name in config.keys() {
2283+
// manually report unused manifest key warning since we collect all the "extra"
2284+
// keys and values inside the config table
2285+
let message =
2286+
format!("unused manifest key: `lints.{tool}.{name}.{config_name}`");
2287+
warnings.push(message);
2288+
}
22812289
}
22822290
}
22832291
}

tests/testsuite/lints_table.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ fn warn_on_unused_key() {
172172
foo.cargo("check")
173173
.with_stderr(
174174
"\
175-
[WARNING] [CWD]/Cargo.toml: unused manifest key: lints.rust.rust-2018-idioms.unused
176-
[WARNING] [CWD]/Cargo.toml: unused manifest key: workspace.lints.rust.rust-2018-idioms.unused
175+
[WARNING][..]unused manifest key: `lints.rust.rust-2018-idioms.unused`
176+
[WARNING][..]unused manifest key: `lints.rust.rust-2018-idioms.unused`
177177
[CHECKING] foo v0.0.1 ([CWD])
178178
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s
179179
",

0 commit comments

Comments
 (0)