1 use crate::utils::span_lint;
2 use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
3 use rustc::{declare_lint_pass, declare_tool_lint};
4 use syntax::{ast::*, source_map::DUMMY_SP};
7 use if_chain::if_chain;
10 declare_clippy_lint! {
11 /// **What it does:** Checks for wildcard dependencies in the `Cargo.toml`.
13 /// **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),
14 /// it is highly unlikely that you work with any possible version of your dependency,
15 /// and wildcard dependencies would cause unnecessary breakage in the ecosystem.
17 /// **Known problems:** None.
25 pub WILDCARD_DEPENDENCIES,
27 "wildcard dependencies being used"
30 declare_lint_pass!(WildcardDependencies => [WILDCARD_DEPENDENCIES]);
32 impl EarlyLintPass for WildcardDependencies {
33 fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
34 let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() {
37 span_lint(cx, WILDCARD_DEPENDENCIES, DUMMY_SP, "could not read cargo metadata");
41 for dep in &metadata.packages[0].dependencies {
42 // VersionReq::any() does not work
44 if let Ok(wildcard_ver) = semver::VersionReq::parse("*");
45 if let Some(ref source) = dep.source;
46 if !source.starts_with("git");
47 if dep.req == wildcard_ver;
51 WILDCARD_DEPENDENCIES,
53 &format!("wildcard dependency for `{}`", dep.name),