Merge pull request #2622 from szabgab/warn-on-invalid-configuration-field

warn on invalid fields in the root of book.toml
This commit is contained in:
Eric Huss
2025-04-03 18:23:26 +00:00
committed by GitHub

View File

@@ -312,6 +312,8 @@ impl<'de> serde::Deserialize<'de> for Config {
return Ok(Config::from_legacy(raw));
}
warn_on_invalid_fields(&raw);
use serde::de::Error;
let mut table = match raw {
Value::Table(t) => t,
@@ -376,6 +378,17 @@ fn parse_env(key: &str) -> Option<String> {
.map(|key| key.to_lowercase().replace("__", ".").replace('_', "-"))
}
fn warn_on_invalid_fields(table: &Value) {
let valid_items = ["book", "build", "rust", "output", "preprocessor"];
let table = table.as_table().expect("root must be a table");
for item in table.keys() {
if !valid_items.contains(&item.as_str()) {
warn!("Invalid field {:?} in book.toml", &item);
}
}
}
fn is_legacy_format(table: &Value) -> bool {
let legacy_items = [
"title",