From 322a768c7709005e2e996b65594b579c3966301f Mon Sep 17 00:00:00 2001 From: xFrednet Date: Wed, 19 May 2021 00:08:31 +0200 Subject: Adapting the lint list to Clippy's new metadata format Changes included: - Minimum adaption to the new `lints.json` format - Fixing filtering for the new `lints.json` format; hardcoding the lint groups in the index - Recreating the original doc styling for the new format - Fixed sytax highlighting for rust,ignore code blocks - Fixed markdown table extraction in the metadata collector and fixed lint level output - Adding the additional information row for lints - Changed the website title to Clippy's lint list - Flexing the website for mobile users - Added (?) references for lint levels and groups - Making deprecated lints look dead - Removed JS code block language extraction in favor of a rust implementation `rust-clippy#7352` - Added the suspicious lint group to the lint list - Remove trailing whitespaces from index.html - Fix code highlighting - Use default value if the docVersion is empty Co-authored-by: Philipp Krones --- .../src/utils/internal_lints/metadata_collector.rs | 36 ++++++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'clippy_lints') diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs index 3eccc89cdeb..c9234a85dd2 100644 --- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -114,6 +114,8 @@ const DEPRECATED_LINT_TYPE: [&str; 3] = ["clippy_lints", "deprecated_lints", "Cl /// The index of the applicability name of `paths::APPLICABILITY_VALUES` const APPLICABILITY_NAME_INDEX: usize = 2; +/// This applicability will be set for unresolved applicability values. +const APPLICABILITY_UNRESOLVED_STR: &str = "Unresolved"; declare_clippy_lint! { /// **What it does:** Collects metadata about clippy lints for the website. @@ -192,7 +194,7 @@ impl Drop for MetadataCollector { let mut lints = std::mem::take(&mut self.lints).into_sorted_vec(); lints .iter_mut() - .for_each(|x| x.applicability = applicability_info.remove(&x.id)); + .for_each(|x| x.applicability = Some(applicability_info.remove(&x.id).unwrap_or_default())); // Outputting if Path::new(OUTPUT_FILE).exists() { @@ -208,7 +210,7 @@ struct LintMetadata { id: String, id_span: SerializableSpan, group: String, - level: &'static str, + level: String, docs: String, /// This field is only used in the output and will only be /// mapped shortly before the actual output. @@ -221,7 +223,7 @@ impl LintMetadata { id, id_span, group, - level, + level: level.to_string(), docs, applicability: None, } @@ -269,14 +271,16 @@ impl Serialize for ApplicabilityInfo { where S: Serializer, { - let index = self.applicability.unwrap_or_default(); - let mut s = serializer.serialize_struct("ApplicabilityInfo", 2)?; s.serialize_field("is_multi_part_suggestion", &self.is_multi_part_suggestion)?; - s.serialize_field( - "applicability", - &paths::APPLICABILITY_VALUES[index][APPLICABILITY_NAME_INDEX], - )?; + if let Some(index) = self.applicability { + s.serialize_field( + "applicability", + &paths::APPLICABILITY_VALUES[index][APPLICABILITY_NAME_INDEX], + )?; + } else { + s.serialize_field("applicability", APPLICABILITY_UNRESOLVED_STR)?; + } s.end() } } @@ -486,6 +490,13 @@ fn extract_attr_docs_or_lint(cx: &LateContext<'_>, item: &Item<'_>) -> Option, item: &Item<'_>) -> Option { let attrs = cx.tcx.hir().attrs(item.hir_id()); let mut lines = attrs.iter().filter_map(ast::Attribute::doc_str); @@ -510,7 +521,12 @@ fn extract_attr_docs(cx: &LateContext<'_>, item: &Item<'_>) -> Option { continue; } } - docs.push_str(line); + // This removes the leading space that the macro translation introduces + if let Some(stripped_doc) = line.strip_prefix(' ') { + docs.push_str(stripped_doc); + } else if !line.is_empty() { + docs.push_str(line); + } } Some(docs) } -- cgit 1.4.1-3-g733a5