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.
This commit is contained in:
Urgau 2024-05-16 13:22:17 +02:00
parent 8d68ed4fb2
commit 1e4857a4d9
3 changed files with 20 additions and 3 deletions

View file

@ -1503,6 +1503,13 @@ impl TomlLint {
Self::Config(config) => config.priority,
}
}
pub fn config(&self) -> Option<&toml::Table> {
match self {
Self::Level(_) => None,
Self::Config(config) => Some(&config.config),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
@ -1511,6 +1518,8 @@ pub struct TomlLintConfig {
pub level: TomlLintLevel,
#[serde(default)]
pub priority: i8,
#[serde(flatten)]
pub config: toml::Table,
}
#[derive(Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq)]

View file

@ -2265,7 +2265,7 @@ supported tools: {}",
if tool == "cargo" && !gctx.cli_unstable().cargo_lints {
warn_for_cargo_lint_feature(gctx, warnings);
}
for name in lints.keys() {
for (name, config) in lints {
if let Some((prefix, suffix)) = name.split_once("::") {
if tool == prefix {
anyhow::bail!(
@ -2278,6 +2278,14 @@ supported tools: {}",
} else {
anyhow::bail!("`lints.{tool}.{name}` is not a valid lint name")
}
} else if let Some(config) = config.config() {
for config_name in config.keys() {
// manually report unused manifest key warning since we collect all the "extra"
// keys and values inside the config table
let message =
format!("unused manifest key: `lints.{tool}.{name}.{config_name}`");
warnings.push(message);
}
}
}
}

View file

@ -172,8 +172,8 @@ fn warn_on_unused_key() {
foo.cargo("check")
.with_stderr(
"\
[WARNING] [CWD]/Cargo.toml: unused manifest key: lints.rust.rust-2018-idioms.unused
[WARNING] [CWD]/Cargo.toml: unused manifest key: workspace.lints.rust.rust-2018-idioms.unused
[WARNING][..]unused manifest key: `lints.rust.rust-2018-idioms.unused`
[WARNING][..]unused manifest key: `lints.rust.rust-2018-idioms.unused`
[CHECKING] foo v0.0.1 ([CWD])
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s
",