Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Commit

Permalink
feat: Catch types in Cargo.toml and warn about them
Browse files Browse the repository at this point in the history
  • Loading branch information
drager committed Nov 12, 2018
1 parent 51e6351 commit 59039e4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ openssl = { version = '0.10.11', optional = true }
parking_lot = "0.6"
serde = "1.0.74"
serde_derive = "1.0.74"
serde_ignored = "0.0.4"
serde_json = "1.0.26"
siphasher = "0.2.3"
slog = "2.3"
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern crate parking_lot;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_ignored;
extern crate serde_json;
extern crate siphasher;
#[macro_use]
Expand Down
22 changes: 20 additions & 2 deletions src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use failure::{Error, ResultExt};
use progressbar::Step;
use serde::{self, Deserialize};
use serde_json;
use std::collections::BTreeSet;
use toml;
use PBAR;

Expand Down Expand Up @@ -210,8 +211,25 @@ impl CrateData {
}
let manifest = fs::read_to_string(&manifest_path)
.with_context(|_| format!("failed to read: {}", manifest_path.display()))?;
let manifest: CargoManifest = toml::from_str(&manifest)
.with_context(|_| format!("failed to parse manifest: {}", manifest_path.display()))?;
let manifest = &mut toml::Deserializer::new(&manifest);

let mut unused_keys = BTreeSet::new();

let manifest: CargoManifest = serde_ignored::deserialize(manifest, |path| {
let path_string = path.to_string();

if path_string.contains("metadata") {
unused_keys.insert(path_string);
}
})
.with_context(|_| format!("failed to parse manifest: {}", manifest_path.display()))?;

unused_keys.iter().for_each(|path| {
PBAR.warn(&format!(
"\"{}\" is misspelled and will be ignored. Please check your Cargo.toml.",
path
));
});

let data =
cargo_metadata::metadata(Some(&manifest_path)).map_err(error_chain_to_failure)?;
Expand Down

0 comments on commit 59039e4

Please sign in to comment.