Skip to content

Warn on invalid fields in the [book] section of book.toml #2637

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ impl<'de> serde::Deserialize<'de> for Config {
}

warn_on_invalid_fields(&raw);
warn_on_invalid_fields_in_book_section(&raw);

use serde::de::Error;
let mut table = match raw {
Expand Down Expand Up @@ -389,6 +390,28 @@ fn warn_on_invalid_fields(table: &Value) {
}
}

fn warn_on_invalid_fields_in_book_section(table: &Value) {
let valid_items = [
"title",
"authors",
"description",
"src",
"language",
"text-direction",
];
if let Some(book) = table.get("book") {
let table = book.as_table().expect("root.book must be a table");
for item in table.keys() {
if !valid_items.contains(&item.as_str()) {
warn!(
"Invalid field {:?} in the [book] section of book.toml",
&item
);
}
}
}
}

fn is_legacy_format(table: &Value) -> bool {
let legacy_items = [
"title",
Expand Down