Document configurations in table and paragraphs
Signed-off-by: Tyler Weaver <maybe@tylerjw.dev>
This commit is contained in:
parent
2e2ae68d5a
commit
7d1609dce3
5 changed files with 551 additions and 79 deletions
|
|
@ -219,7 +219,8 @@ define_Conf! {
|
|||
///
|
||||
/// #### Noteworthy
|
||||
///
|
||||
/// A type, say `SomeType`, listed in this configuration has the same behavior of `["SomeType" , "*"], ["*", "SomeType"]` in `arithmetic_side_effects_allowed_binary`.
|
||||
/// A type, say `SomeType`, listed in this configuration has the same behavior of
|
||||
/// `["SomeType" , "*"], ["*", "SomeType"]` in `arithmetic_side_effects_allowed_binary`.
|
||||
(arithmetic_side_effects_allowed: rustc_data_structures::fx::FxHashSet<String> = <_>::default()),
|
||||
/// Lint: ARITHMETIC_SIDE_EFFECTS.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -180,13 +180,22 @@ This lint has the following configuration variables:
|
|||
})
|
||||
}
|
||||
|
||||
fn get_markdown_table(&self) -> String {
|
||||
fn configs_to_markdown(&self, map_fn: fn(&ClippyConfiguration) -> String) -> String {
|
||||
self.config
|
||||
.iter()
|
||||
.filter(|config| config.deprecation_reason.is_none())
|
||||
.map(ClippyConfiguration::to_markdown_table_entry)
|
||||
.filter(|config| !config.lints.is_empty())
|
||||
.map(map_fn)
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
fn get_markdown_docs(&self) -> String {
|
||||
format!(
|
||||
"## Lint Configuration Options\n| <div style=\"width:290px\">Option</div> | Default Value |\n|--|--|\n{}\n\n{}\n",
|
||||
self.configs_to_markdown(ClippyConfiguration::to_markdown_table_entry),
|
||||
self.configs_to_markdown(ClippyConfiguration::to_markdown_paragraph),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for MetadataCollector {
|
||||
|
|
@ -230,12 +239,7 @@ impl Drop for MetadataCollector {
|
|||
.create(true)
|
||||
.open(MARKDOWN_OUTPUT_FILE)
|
||||
.unwrap();
|
||||
writeln!(
|
||||
file,
|
||||
"## Lint Configuration\n\n| Option | Default | Description | Lints |\n|--|--|--|--|\n{}\n",
|
||||
self.get_markdown_table()
|
||||
)
|
||||
.unwrap();
|
||||
writeln!(file, "{}", self.get_markdown_docs(),).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -537,24 +541,27 @@ impl ClippyConfiguration {
|
|||
}
|
||||
}
|
||||
|
||||
fn to_markdown_table_entry(&self) -> String {
|
||||
fn to_markdown_paragraph(&self) -> String {
|
||||
format!(
|
||||
"| {} | `{}` | {} | {} |",
|
||||
"### {}\n{}\n\n**Default Value:** `{}` (`{}`)\n\n{}\n\n",
|
||||
self.name,
|
||||
self.default,
|
||||
self.doc
|
||||
.split('.')
|
||||
.next()
|
||||
.unwrap_or("")
|
||||
.replace('|', "\\|")
|
||||
.replace("\n ", " "),
|
||||
.lines()
|
||||
.map(|line| line.strip_prefix(" ").unwrap_or(line))
|
||||
.join("\n"),
|
||||
self.default,
|
||||
self.config_type,
|
||||
self.lints
|
||||
.iter()
|
||||
.map(|name| name.to_string().split_whitespace().next().unwrap().to_string())
|
||||
.map(|name| format!("[{name}](https://rust-lang.github.io/rust-clippy/master/index.html#{name})"))
|
||||
.join(" ")
|
||||
.map(|name| format!("* [{name}](https://rust-lang.github.io/rust-clippy/master/index.html#{name})"))
|
||||
.join("\n"),
|
||||
)
|
||||
}
|
||||
|
||||
fn to_markdown_table_entry(&self) -> String {
|
||||
format!("| [{}](#{}) | `{}` |", self.name, self.name, self.default)
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_configs() -> Vec<ClippyConfiguration> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue