mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:26 +00:00
Avoid fixing D200 for docstrings that end in escapes (#6779)
Appease the fuzzers! Closes https://github.com/astral-sh/ruff/issues/6755.
This commit is contained in:
parent
749da6589a
commit
558b56f8a8
4 changed files with 61 additions and 1 deletions
13
crates/ruff/resources/test/fixtures/pydocstyle/D200.py
vendored
Normal file
13
crates/ruff/resources/test/fixtures/pydocstyle/D200.py
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
def func():
|
||||
"""\
|
||||
"""
|
||||
|
||||
|
||||
def func():
|
||||
"""\\
|
||||
"""
|
||||
|
||||
|
||||
def func():
|
||||
"""\ \
|
||||
"""
|
|
@ -39,6 +39,7 @@ mod tests {
|
|||
#[test_case(Rule::NewLineAfterLastParagraph, Path::new("D.py"))]
|
||||
#[test_case(Rule::NewLineAfterSectionName, Path::new("sections.py"))]
|
||||
#[test_case(Rule::NoBlankLineAfterFunction, Path::new("D.py"))]
|
||||
#[test_case(Rule::FitsOnOneLine, Path::new("D200.py"))]
|
||||
#[test_case(Rule::NoBlankLineAfterFunction, Path::new("D202.py"))]
|
||||
#[test_case(Rule::BlankLineBeforeClass, Path::new("D.py"))]
|
||||
#[test_case(Rule::NoBlankLineBeforeFunction, Path::new("D.py"))]
|
||||
|
|
|
@ -74,7 +74,8 @@ pub(crate) fn one_liner(checker: &mut Checker, docstring: &Docstring) {
|
|||
// characters, avoid applying the fix.
|
||||
let body = docstring.body();
|
||||
let trimmed = body.trim();
|
||||
if !trimmed.ends_with(trailing.chars().last().unwrap())
|
||||
if trimmed.chars().rev().take_while(|c| *c == '\\').count() % 2 == 0
|
||||
&& !trimmed.ends_with(trailing.chars().last().unwrap())
|
||||
&& !trimmed.starts_with(leading.chars().last().unwrap())
|
||||
{
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
---
|
||||
source: crates/ruff/src/rules/pydocstyle/mod.rs
|
||||
---
|
||||
D200.py:2:5: D200 One-line docstring should fit on one line
|
||||
|
|
||||
1 | def func():
|
||||
2 | """\
|
||||
| _____^
|
||||
3 | | """
|
||||
| |_______^ D200
|
||||
|
|
||||
= help: Reformat to one line
|
||||
|
||||
D200.py:7:5: D200 [*] One-line docstring should fit on one line
|
||||
|
|
||||
6 | def func():
|
||||
7 | """\\
|
||||
| _____^
|
||||
8 | | """
|
||||
| |_______^ D200
|
||||
|
|
||||
= help: Reformat to one line
|
||||
|
||||
ℹ Suggested fix
|
||||
4 4 |
|
||||
5 5 |
|
||||
6 6 | def func():
|
||||
7 |- """\\
|
||||
8 |- """
|
||||
7 |+ """\\"""
|
||||
9 8 |
|
||||
10 9 |
|
||||
11 10 | def func():
|
||||
|
||||
D200.py:12:5: D200 One-line docstring should fit on one line
|
||||
|
|
||||
11 | def func():
|
||||
12 | """\ \
|
||||
| _____^
|
||||
13 | | """
|
||||
| |_______^ D200
|
||||
|
|
||||
= help: Reformat to one line
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue