]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/cargo_common_metadata.rs
Auto merge of #4809 - iankronquist:patch-1, r=flip1995
[rust.git] / clippy_lints / src / cargo_common_metadata.rs
index 115bb9ee8c8a1abe35c08b7b066ca44a12dcaf67..ec53e08f50cd3a1edeb4bdb56496f44cb473d618 100644 (file)
@@ -1,11 +1,12 @@
 //! lint on missing cargo common metadata
 
-use crate::utils::span_lint;
-use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
-use rustc::{declare_lint_pass, declare_tool_lint};
-use syntax::{ast::*, source_map::DUMMY_SP};
+use std::path::PathBuf;
 
-use cargo_metadata;
+use crate::utils::span_lint;
+use rustc_lint::{EarlyContext, EarlyLintPass};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::source_map::DUMMY_SP;
+use syntax::ast::*;
 
 declare_clippy_lint! {
     /// **What it does:** Checks to see if all common metadata is defined in
@@ -25,7 +26,7 @@
     /// description = "A bunch of helpful lints to avoid common pitfalls in Rust"
     /// repository = "https://github.com/rust-lang/rust-clippy"
     /// readme = "README.md"
-    /// license = "MIT/Apache-2.0"
+    /// license = "MIT OR Apache-2.0"
     /// keywords = ["clippy", "lint", "plugin"]
     /// categories = ["development-tools", "development-tools::cargo-plugins"]
     /// ```
@@ -47,9 +48,13 @@ fn is_empty_str(value: &Option<String>) -> bool {
     value.as_ref().map_or(true, String::is_empty)
 }
 
+fn is_empty_path(value: &Option<PathBuf>) -> bool {
+    value.as_ref().and_then(|x| x.to_str()).map_or(true, str::is_empty)
+}
+
 fn is_empty_vec(value: &[String]) -> bool {
     // This works because empty iterators return true
-    value.iter().all(std::string::String::is_empty)
+    value.iter().all(String::is_empty)
 }
 
 declare_lint_pass!(CargoCommonMetadata => [CARGO_COMMON_METADATA]);
@@ -72,15 +77,15 @@ fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
                 missing_warning(cx, &package, "package.description");
             }
 
-            if is_empty_str(&package.license) {
-                missing_warning(cx, &package, "package.license");
+            if is_empty_str(&package.license) && is_empty_path(&package.license_file) {
+                missing_warning(cx, &package, "either package.license or package.license_file");
             }
 
             if is_empty_str(&package.repository) {
                 missing_warning(cx, &package, "package.repository");
             }
 
-            if is_empty_str(&package.readme) {
+            if is_empty_path(&package.readme) {
                 missing_warning(cx, &package, "package.readme");
             }