1 use crate::utils::span_lint;
2 use rustc_lint::{EarlyContext, EarlyLintPass};
3 use rustc_session::{declare_lint_pass, declare_tool_lint};
4 use rustc_span::source_map::DUMMY_SP;
7 use if_chain::if_chain;
10 /// **What it does:** Checks for wildcard dependencies in the `Cargo.toml`.
12 /// **Why is this bad?** [As the edition guide says](https://rust-lang-nursery.github.io/edition-guide/rust-2018/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.html),
13 /// it is highly unlikely that you work with any possible version of your dependency,
14 /// and wildcard dependencies would cause unnecessary breakage in the ecosystem.
16 /// **Known problems:** None.
24 pub WILDCARD_DEPENDENCIES,
26 "wildcard dependencies being used"
29 declare_lint_pass!(WildcardDependencies => [WILDCARD_DEPENDENCIES]);
31 impl EarlyLintPass for WildcardDependencies {
32 fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
33 let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() {
36 span_lint(cx, WILDCARD_DEPENDENCIES, DUMMY_SP, "could not read cargo metadata");
40 for dep in &metadata.packages[0].dependencies {
41 // VersionReq::any() does not work
43 if let Ok(wildcard_ver) = semver::VersionReq::parse("*");
44 if let Some(ref source) = dep.source;
45 if !source.starts_with("git");
46 if dep.req == wildcard_ver;
50 WILDCARD_DEPENDENCIES,
52 &format!("wildcard dependency for `{}`", dep.name),