mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-29 19:17:20 +00:00
[ty] Adapt generate_ty_rules for MkDocs (#19087)
## Summary Adapts the Markdown for the rules-reference documentation page for MkDocs.
This commit is contained in:
parent
e9b5ea71b3
commit
e599c9d0d3
2 changed files with 704 additions and 776 deletions
|
|
@ -78,7 +78,10 @@ fn generate_markdown() -> String {
|
||||||
.documentation_lines()
|
.documentation_lines()
|
||||||
.map(|line| {
|
.map(|line| {
|
||||||
if line.starts_with('#') {
|
if line.starts_with('#') {
|
||||||
Cow::Owned(format!("#{line}"))
|
Cow::Owned(format!(
|
||||||
|
"**{line}**\n",
|
||||||
|
line = line.trim_start_matches('#').trim_start()
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
Cow::Borrowed(line)
|
Cow::Borrowed(line)
|
||||||
}
|
}
|
||||||
|
|
@ -87,21 +90,15 @@ fn generate_markdown() -> String {
|
||||||
|
|
||||||
let _ = writeln!(
|
let _ = writeln!(
|
||||||
&mut output,
|
&mut output,
|
||||||
r#"**Default level**: {level}
|
r#"<small>
|
||||||
|
Default level: [`{level}`](/rules/#rule-levels "This lint has a default severity of '{level}'.") ·
|
||||||
<details>
|
[Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20{encoded_name}) ·
|
||||||
<summary>{summary}</summary>
|
[View source](https://github.com/astral-sh/ruff/blob/main/{file}#L{line})
|
||||||
|
</small>
|
||||||
|
|
||||||
{documentation}
|
{documentation}
|
||||||
|
|
||||||
### Links
|
|
||||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20{encoded_name})
|
|
||||||
* [View source](https://github.com/astral-sh/ruff/blob/main/{file}#L{line})
|
|
||||||
</details>
|
|
||||||
"#,
|
"#,
|
||||||
level = lint.default_level(),
|
level = lint.default_level(),
|
||||||
// GitHub doesn't support markdown in `summary` headers
|
|
||||||
summary = replace_inline_code(lint.summary()),
|
|
||||||
encoded_name = url::form_urlencoded::byte_serialize(lint.name().as_str().as_bytes())
|
encoded_name = url::form_urlencoded::byte_serialize(lint.name().as_str().as_bytes())
|
||||||
.collect::<String>(),
|
.collect::<String>(),
|
||||||
file = url::form_urlencoded::byte_serialize(lint.file().replace('\\', "/").as_bytes())
|
file = url::form_urlencoded::byte_serialize(lint.file().replace('\\', "/").as_bytes())
|
||||||
|
|
@ -113,25 +110,6 @@ fn generate_markdown() -> String {
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Replaces inline code blocks (`code`) with `<code>code</code>`
|
|
||||||
fn replace_inline_code(input: &str) -> String {
|
|
||||||
let mut output = String::new();
|
|
||||||
let mut parts = input.split('`');
|
|
||||||
|
|
||||||
while let Some(before) = parts.next() {
|
|
||||||
if let Some(between) = parts.next() {
|
|
||||||
output.push_str(before);
|
|
||||||
output.push_str("<code>");
|
|
||||||
output.push_str(between);
|
|
||||||
output.push_str("</code>");
|
|
||||||
} else {
|
|
||||||
output.push_str(before);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
output
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
|
||||||
1440
crates/ty/docs/rules.md
generated
1440
crates/ty/docs/rules.md
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue