Merge #3349
3349: Fixes #3347: Lint for wildcard dependencies in Cargo.toml r=ordovicia a=ordovicia Add a lint for wildcard dependencies in Cargo.toml. How should I write a test for this lint? Fixes #3347 Co-authored-by: Hidehito Yabuuchi <hdht.ybuc@gmail.com>
This commit is contained in:
commit
319b75c75b
5 changed files with 77 additions and 10 deletions
|
@ -893,6 +893,7 @@ All notable changes to this project will be documented in this file.
|
||||||
[`while_immutable_condition`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#while_immutable_condition
|
[`while_immutable_condition`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#while_immutable_condition
|
||||||
[`while_let_loop`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#while_let_loop
|
[`while_let_loop`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#while_let_loop
|
||||||
[`while_let_on_iterator`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#while_let_on_iterator
|
[`while_let_on_iterator`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#while_let_on_iterator
|
||||||
|
[`wildcard_dependencies`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#wildcard_dependencies
|
||||||
[`write_literal`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#write_literal
|
[`write_literal`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#write_literal
|
||||||
[`write_with_newline`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#write_with_newline
|
[`write_with_newline`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#write_with_newline
|
||||||
[`writeln_empty_string`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#writeln_empty_string
|
[`writeln_empty_string`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#writeln_empty_string
|
||||||
|
|
|
@ -9,7 +9,7 @@ We are currently in the process of discussing Clippy 1.0 via the RFC process in
|
||||||
|
|
||||||
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
|
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
|
||||||
|
|
||||||
[There are 280 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)
|
[There are 281 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)
|
||||||
|
|
||||||
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
|
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
|
||||||
|
|
||||||
|
|
|
@ -200,6 +200,7 @@ pub mod unused_label;
|
||||||
pub mod unwrap;
|
pub mod unwrap;
|
||||||
pub mod use_self;
|
pub mod use_self;
|
||||||
pub mod vec;
|
pub mod vec;
|
||||||
|
pub mod wildcard_dependencies;
|
||||||
pub mod write;
|
pub mod write;
|
||||||
pub mod zero_div_zero;
|
pub mod zero_div_zero;
|
||||||
// end lints modules, do not remove this comment, it’s used in `update_lints`
|
// end lints modules, do not remove this comment, it’s used in `update_lints`
|
||||||
|
@ -438,6 +439,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
|
||||||
reg.register_late_lint_pass(box question_mark::Pass);
|
reg.register_late_lint_pass(box question_mark::Pass);
|
||||||
reg.register_late_lint_pass(box suspicious_trait_impl::SuspiciousImpl);
|
reg.register_late_lint_pass(box suspicious_trait_impl::SuspiciousImpl);
|
||||||
reg.register_early_lint_pass(box multiple_crate_versions::Pass);
|
reg.register_early_lint_pass(box multiple_crate_versions::Pass);
|
||||||
|
reg.register_early_lint_pass(box wildcard_dependencies::Pass);
|
||||||
reg.register_late_lint_pass(box map_unit_fn::Pass);
|
reg.register_late_lint_pass(box map_unit_fn::Pass);
|
||||||
reg.register_late_lint_pass(box infallible_destructuring_match::Pass);
|
reg.register_late_lint_pass(box infallible_destructuring_match::Pass);
|
||||||
reg.register_late_lint_pass(box inherent_impl::Pass::default());
|
reg.register_late_lint_pass(box inherent_impl::Pass::default());
|
||||||
|
@ -967,6 +969,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
|
||||||
|
|
||||||
reg.register_lint_group("clippy::cargo", Some("clippy_cargo"), vec![
|
reg.register_lint_group("clippy::cargo", Some("clippy_cargo"), vec![
|
||||||
multiple_crate_versions::MULTIPLE_CRATE_VERSIONS,
|
multiple_crate_versions::MULTIPLE_CRATE_VERSIONS,
|
||||||
|
wildcard_dependencies::WILDCARD_DEPENDENCIES,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
reg.register_lint_group("clippy::nursery", Some("clippy_nursery"), vec,
|
||||||
|
/// 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! {
|
||||||
|
pub WILDCARD_DEPENDENCIES,
|
||||||
|
cargo,
|
||||||
|
"wildcard dependencies being used"
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Pass;
|
||||||
|
|
||||||
|
impl LintPass for Pass {
|
||||||
|
fn get_lints(&self) -> LintArray {
|
||||||
|
lint_array!(WILDCARD_DEPENDENCIES)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EarlyLintPass for Pass {
|
||||||
|
fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &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");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
for dep in &metadata.packages[0].dependencies {
|
||||||
|
// VersionReq::any() does not work
|
||||||
|
if let Ok(wildcard_ver) = semver::VersionReq::parse("*") {
|
||||||
|
if dep.req == wildcard_ver {
|
||||||
|
span_lint(
|
||||||
|
cx,
|
||||||
|
WILDCARD_DEPENDENCIES,
|
||||||
|
DUMMY_SP,
|
||||||
|
&format!("wildcard dependency for `{}`", dep.name),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue