Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid fixing D200 for docstrings that end in escapes #6779

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions crates/ruff/resources/test/fixtures/pydocstyle/D200.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def func():
"""\
"""


def func():
"""\\
"""


def func():
"""\ \
"""
1 change: 1 addition & 0 deletions crates/ruff/src/rules/pydocstyle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
3 changes: 2 additions & 1 deletion crates/ruff/src/rules/pydocstyle/rules/one_liner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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