Fix Options section of rule docs (#5741)

## Summary

Fix: #5740

A trailing line-break are needed for the anchor.

## Test Plan

http://127.0.0.1:8000/docs/rules/line-too-long/#options

|before|after|
|--|--|

|![image](b68d4fd7-da5a-4494-bb95-f7792f1a42db)|
This commit is contained in:
eggplants 2023-07-14 02:25:54 +09:00 committed by GitHub
parent fee0f43925
commit 06a04c10e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -81,7 +81,7 @@ fn process_documentation(documentation: &str, out: &mut String) {
// a non-CommonMark-compliant Markdown parser, which doesn't support code // a non-CommonMark-compliant Markdown parser, which doesn't support code
// tags in link definitions // tags in link definitions
// (see https://github.com/Python-Markdown/markdown/issues/280). // (see https://github.com/Python-Markdown/markdown/issues/280).
let documentation = Regex::new(r"\[`(.*?)`\]($|[^\[])").unwrap().replace_all( let documentation = Regex::new(r"\[`(.*?)`]($|[^\[])").unwrap().replace_all(
documentation, documentation,
|caps: &Captures| { |caps: &Captures| {
format!( format!(
@ -106,7 +106,7 @@ fn process_documentation(documentation: &str, out: &mut String) {
let anchor = option.replace('.', "-"); let anchor = option.replace('.', "-");
out.push_str(&format!("- [`{option}`][{option}]\n")); out.push_str(&format!("- [`{option}`][{option}]\n"));
after.push_str(&format!("[{option}]: ../../settings#{anchor}")); after.push_str(&format!("[{option}]: ../../settings#{anchor}\n"));
continue; continue;
} }
@ -115,10 +115,10 @@ fn process_documentation(documentation: &str, out: &mut String) {
out.push_str(line); out.push_str(line);
} }
if !after.is_empty() { if !after.is_empty() {
out.push_str("\n\n"); out.push('\n');
out.push('\n');
out.push_str(&after); out.push_str(&after);
} }
out.push('\n');
} }
#[cfg(test)] #[cfg(test)]
@ -130,11 +130,12 @@ mod tests {
let mut output = String::new(); let mut output = String::new();
process_documentation( process_documentation(
" "
See also [`mccabe.max-complexity`]. See also [`mccabe.max-complexity`] and [`task-tags`].
Something [`else`][other]. Something [`else`][other].
## Options ## Options
- `task-tags`
- `mccabe.max-complexity` - `mccabe.max-complexity`
[other]: http://example.com.", [other]: http://example.com.",
@ -143,16 +144,19 @@ Something [`else`][other].
assert_eq!( assert_eq!(
output, output,
" "
See also [`mccabe.max-complexity`][mccabe.max-complexity]. See also [`mccabe.max-complexity`][mccabe.max-complexity] and [`task-tags`][task-tags].
Something [`else`][other]. Something [`else`][other].
## Options ## Options
- [`task-tags`][task-tags]
- [`mccabe.max-complexity`][mccabe.max-complexity] - [`mccabe.max-complexity`][mccabe.max-complexity]
[other]: http://example.com. [other]: http://example.com.
[mccabe.max-complexity]: ../../settings#mccabe-max-complexity\n" [task-tags]: ../../settings#task-tags
[mccabe.max-complexity]: ../../settings#mccabe-max-complexity
"
); );
} }
} }