Skip to content

Conversation

drager
Copy link
Owner

@drager drager commented Nov 12, 2018

This intends to fix #443.

@drager drager changed the title feat: Catch types in Cargo.toml and warn about them feat: Catch typos in Cargo.toml and warn about them Nov 12, 2018
Copy link
Contributor

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Ideally we would add a test for this as well but I'm not sure that we can at this time easily do that.

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

if path_string.contains("metadata") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may want to be metadata.wasm-pack perhaps? That way we won't accidentally warn about other metadata sections accidentally

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right! That makes sense. Thanks!

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcrichton: Hmm, if I do metadata.wasm-pack we wouldn't warn about misspelled wasm-pack. i.e. if someone writes [package.metadata.wasmpack.profile.dev.wasm-bindgen].

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, but I personally would think that we can't land this while it warns about [package.metadata.some-unrelated-tool].

We can possibly do a lehvenstein distance thing (typically used for "did you typo this?") to figure out if it looks like wasm-pack specifically, but other crates/tools using [package.metadata] should not be warned about when using wasm-pack

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable! Pushed some code for this.


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may want to be reworded a bit because we don't actually know if it's misspelled, perhaps this could just say that it's an ignored/unknown key?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was somewhat unsure what to put there and "unknown and will be ignored" sounds good.

Cargo.toml Outdated
name = "wasm-pack"
readme = "README.md"
repository = "https://github.com/ashleygwilliams/wasm-pack.git"
version = "0.5.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like some unrelated changes snuck in here?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I used cargo add to add strsim and it did some reordering. I will push a commit that restores it.

Cargo.toml Outdated

[dependencies.openssl]
optional = true
version = "0.10.11"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the movement here may be an unrelated change?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I used cargo add to add strsim and it did some reordering. I will push a commit that restores it.

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

if levenshtein(WASM_PACK_METADATA_KEY, &path_string) == levenshtein_threshold {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this perhaps have some more guards like testing that the key starts with package.metadata and then just running levenshtein over the key afterwards, ideally only matching "wasm-pack" up against the next part of the key?

Also, I think this may perhaps want to be <= threshold to ensure that exact matches are warned about

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! Ah, ofc it should be <=.

let path_string = path.to_string();

if levenshtein(WASM_PACK_METADATA_KEY, &path_string) == levenshtein_threshold {
has_possible_typo = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's still good to warn about all the keys here, so it's fine for this to take the same path as the one below where it just throws a new key in the set to get warned about, that way the exact key that wasn't used is printed as well and the user doesn't have to guess

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense. Much better to print the key so the user doesn't have to guess.

@alexcrichton
Copy link
Contributor

Code-wise looks great to me, thanks!

@drager
Copy link
Owner Author

drager commented Nov 19, 2018

Awesome! Thank you for the guidance and feedback!

Copy link
Contributor

@ashleygwilliams ashleygwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great! thank you so much!

@ashleygwilliams ashleygwilliams added this to the 0.6.0 milestone Dec 21, 2018
@ashleygwilliams ashleygwilliams merged commit 8ed6e3d into drager:master Dec 21, 2018
@drager drager deleted the catch-types-in-cargo-toml branch December 21, 2018 21:16
@fitzgen fitzgen added the TWiRaWA Nominate this PR for inclusion in the next issue of This Week in Rust and WebAssembly label Feb 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog - feature TWiRaWA Nominate this PR for inclusion in the next issue of This Week in Rust and WebAssembly

4 participants