mirror of https://github.com/astral-sh/ruff
Bug fix: Prevent fully defined links [``name``](link) from being reformatted (#10442)
## Summary
Currently fully define markdown links which include ticks are being
reformatted by
8619986123/crates/ruff_dev/src/generate_docs.rs (L105-L114)
```[`name`](link)``` -> ```[`name`][name](link)```
For example: https://docs.astral.sh/ruff/rules/typed-argument-default-in-stub/
This PR excludes the open parentheses from the regex, so that these types of links won't be reformatted.
## Test Plan
Extended the regression test.
This commit is contained in:
parent
2edd61709f
commit
91e81413db
|
|
@ -102,16 +102,15 @@ fn process_documentation(documentation: &str, out: &mut String, rule_name: &str)
|
||||||
// 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"\[`([^`]*?)`]($|[^\[\(])")
|
||||||
documentation,
|
.unwrap()
|
||||||
|caps: &Captures| {
|
.replace_all(documentation, |caps: &Captures| {
|
||||||
format!(
|
format!(
|
||||||
"[`{option}`][{option}]{sep}",
|
"[`{option}`][{option}]{sep}",
|
||||||
option = &caps[1],
|
option = &caps[1],
|
||||||
sep = &caps[2]
|
sep = &caps[2]
|
||||||
)
|
)
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
for line in documentation.split_inclusive('\n') {
|
for line in documentation.split_inclusive('\n') {
|
||||||
if line.starts_with("## ") {
|
if line.starts_with("## ") {
|
||||||
|
|
@ -159,7 +158,7 @@ mod tests {
|
||||||
process_documentation(
|
process_documentation(
|
||||||
"
|
"
|
||||||
See also [`lint.mccabe.max-complexity`] and [`lint.task-tags`].
|
See also [`lint.mccabe.max-complexity`] and [`lint.task-tags`].
|
||||||
Something [`else`][other].
|
Something [`else`][other]. Some [link](https://example.com).
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
|
|
@ -174,7 +173,7 @@ Something [`else`][other].
|
||||||
output,
|
output,
|
||||||
"
|
"
|
||||||
See also [`lint.mccabe.max-complexity`][lint.mccabe.max-complexity] and [`lint.task-tags`][lint.task-tags].
|
See also [`lint.mccabe.max-complexity`][lint.mccabe.max-complexity] and [`lint.task-tags`][lint.task-tags].
|
||||||
Something [`else`][other].
|
Something [`else`][other]. Some [link](https://example.com).
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue