1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
11 use crate::rustc::{declare_tool_lint, lint_array};
12 use crate::syntax::ast::*;
13 use crate::utils::span_lint;
16 use lazy_static::lazy_static;
19 /// **What it does:** Checks to see if wildcard dependencies are being used.
21 /// **Why is this bad?** [As the edition guide sais](https://rust-lang-nursery.github.io/edition-guide/rust-2018/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.html),
22 /// it is highly unlikely that you work with any possible version of your dependency,
23 /// and wildcard dependencies would cause unnecessary breakage in the ecosystem.
25 /// **Known problems:** None.
33 declare_clippy_lint! {
34 pub WILDCARD_DEPENDENCIES,
36 "wildcard dependencies being used"
41 impl LintPass for Pass {
42 fn get_lints(&self) -> LintArray {
43 lint_array!(WILDCARD_DEPENDENCIES)
47 impl EarlyLintPass for Pass {
48 fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &Crate) {
49 let metadata = if let Ok(metadata) = cargo_metadata::metadata(None) {
52 span_lint(cx, WILDCARD_DEPENDENCIES, krate.span, "could not read cargo metadata");
57 // VersionReq::any() does not work
58 static ref WILDCARD_VERSION_REQ: semver::VersionReq = semver::VersionReq::parse("*").unwrap();
61 for dep in &metadata.packages[0].dependencies {
62 if dep.req == *WILDCARD_VERSION_REQ {
65 WILDCARD_DEPENDENCIES,
67 &format!("wildcard dependency for `{}`", dep.name),