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

Commit

Permalink
fix: Print the possible misspelled key so the user doesnt have to guess
Browse files Browse the repository at this point in the history
  • Loading branch information
drager committed Nov 14, 2018
1 parent 8dd6fe4 commit 07d813f
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ struct NpmData {
pub struct ManifestAndUnsedKeys {
pub manifest: CargoManifest,
pub unused_keys: BTreeSet<String>,
pub has_possible_typo: bool,
}

impl CrateData {
Expand Down Expand Up @@ -266,17 +265,15 @@ impl CrateData {
let manifest = &mut toml::Deserializer::new(&manifest);

let mut unused_keys = BTreeSet::new();
let mut has_possible_typo = false;
let levenshtein_threshold = 1;

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

if levenshtein(WASM_PACK_METADATA_KEY, &path_string) == levenshtein_threshold {
has_possible_typo = true;
}

if path_string.contains(WASM_PACK_METADATA_KEY) {
if path_string.starts_with("package.metadata")
&& (path_string.contains("wasm-pack")
|| levenshtein(WASM_PACK_METADATA_KEY, &path_string) <= levenshtein_threshold)
{
unused_keys.insert(path_string);
}
})
Expand All @@ -285,19 +282,12 @@ impl CrateData {
Ok(ManifestAndUnsedKeys {
manifest,
unused_keys,
has_possible_typo,
})
}

/// Iterating through all the passed `unused_keys` and output
/// a warning for each unknown key.
pub fn warn_for_unused_keys(manifest_and_keys: &ManifestAndUnsedKeys) {
if manifest_and_keys.has_possible_typo {
PBAR.warn(&format!(
"It's possible that you misspelled the \"{}\" setting in your Cargo.toml.",
WASM_PACK_METADATA_KEY
));
}
manifest_and_keys.unused_keys.iter().for_each(|path| {
PBAR.warn(&format!(
"\"{}\" is a unknown key and will be ignored. Please check your Cargo.toml.",
Expand Down

0 comments on commit 07d813f

Please sign in to comment.