clippy_config/
metadata.rs
1use itertools::Itertools;
2use std::fmt;
3
4#[derive(Debug, Clone, Default)]
5pub struct ClippyConfiguration {
6 pub name: String,
7 pub default: String,
8 pub lints: &'static [&'static str],
9 pub doc: &'static str,
10 pub deprecation_reason: Option<&'static str>,
11}
12
13impl fmt::Display for ClippyConfiguration {
14 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15 write!(f, "- `{}`: {}", self.name, self.doc)?;
16 if !self.default.is_empty() {
17 write!(f, "\n\n (default: `{}`)", self.default)?;
18 }
19 Ok(())
20 }
21}
22
23impl ClippyConfiguration {
24 pub fn to_markdown_paragraph(&self) -> String {
25 format!(
26 "## `{}`\n{}\n\n**Default Value:** `{}`\n\n---\n**Affected lints:**\n{}\n\n",
27 self.name,
28 self.doc.lines().map(|x| x.strip_prefix(' ').unwrap_or(x)).join("\n"),
29 self.default,
30 self.lints.iter().format_with("\n", |name, f| f(&format_args!(
31 "* [`{name}`](https://rust-lang.github.io/rust-clippy/master/index.html#{name})"
32 ))),
33 )
34 }
35
36 pub fn to_markdown_link(&self) -> String {
37 const BOOK_CONFIGS_PATH: &str = "https://doc.rust-lang.org/clippy/lint_configuration.html";
38 format!("[`{}`]: {BOOK_CONFIGS_PATH}#{}", self.name, self.name)
39 }
40}