X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=clippy_lints%2Fsrc%2Fwildcard_dependencies.rs;h=60c3489a449b6796714a416120985ec2e8a7f33d;hb=b094bb1bd7f1cc702823c91ca509f338fedee24a;hp=e3c352862518e2a7630a02ae3d6606404f5bc2b3;hpb=38d4ac7ceaf8ace26864e847c8280dc66410587c;p=rust.git diff --git a/clippy_lints/src/wildcard_dependencies.rs b/clippy_lints/src/wildcard_dependencies.rs index e3c35286251..60c3489a449 100644 --- a/clippy_lints/src/wildcard_dependencies.rs +++ b/clippy_lints/src/wildcard_dependencies.rs @@ -1,48 +1,41 @@ -use crate::utils::span_lint; -use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; -use rustc::{declare_tool_lint, lint_array}; -use syntax::{ast::*, source_map::DUMMY_SP}; +use clippy_utils::diagnostics::span_lint; +use clippy_utils::run_lints; +use rustc_hir::{hir_id::CRATE_HIR_ID, Crate}; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::source_map::DUMMY_SP; -use cargo_metadata; use if_chain::if_chain; -use semver; -/// **What it does:** Checks for wildcard dependencies in the `Cargo.toml`. -/// -/// **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), -/// it is highly unlikely that you work with any possible version of your dependency, -/// and wildcard dependencies would cause unnecessary breakage in the ecosystem. -/// -/// **Known problems:** None. -/// -/// **Example:** -/// -/// ```toml -/// [dependencies] -/// regex = "*" -/// ``` declare_clippy_lint! { + /// **What it does:** Checks for wildcard dependencies in the `Cargo.toml`. + /// + /// **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), + /// it is highly unlikely that you work with any possible version of your dependency, + /// and wildcard dependencies would cause unnecessary breakage in the ecosystem. + /// + /// **Known problems:** None. + /// + /// **Example:** + /// + /// ```toml + /// [dependencies] + /// regex = "*" + /// ``` pub WILDCARD_DEPENDENCIES, cargo, "wildcard dependencies being used" } -pub struct Pass; +declare_lint_pass!(WildcardDependencies => [WILDCARD_DEPENDENCIES]); -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(WILDCARD_DEPENDENCIES) - } -} - -impl EarlyLintPass for Pass { - fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) { - let metadata = if let Ok(metadata) = cargo_metadata::metadata(None) { - metadata - } else { - span_lint(cx, WILDCARD_DEPENDENCIES, DUMMY_SP, "could not read cargo metadata"); +impl LateLintPass<'_> for WildcardDependencies { + fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { + if !run_lints(cx, &[WILDCARD_DEPENDENCIES], CRATE_HIR_ID) { return; - }; + } + + let metadata = unwrap_cargo_metadata!(cx, WILDCARD_DEPENDENCIES, false); for dep in &metadata.packages[0].dependencies { // VersionReq::any() does not work