mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:43 +00:00
parent
5a7d8c25f4
commit
1ab0273aa7
4 changed files with 51 additions and 2 deletions
9
resources/test/fixtures/pydocstyle/D.py
vendored
9
resources/test/fixtures/pydocstyle/D.py
vendored
|
@ -579,3 +579,12 @@ def multiline_trailing_and_leading_space():
|
|||
"or exclamation point (not '\"')")
|
||||
def endswith_quote():
|
||||
"""Whitespace at the end, but also a quote" """
|
||||
|
||||
|
||||
@expect('D209: Multi-line docstring closing quotes should be on a separate '
|
||||
'line')
|
||||
@expect('D213: Multi-line docstring summary should start at the second line')
|
||||
def asdfljdjgf24():
|
||||
"""Summary.
|
||||
|
||||
Description. """
|
||||
|
|
|
@ -528,12 +528,25 @@ pub fn newline_after_last_paragraph(checker: &mut Checker, docstring: &Docstring
|
|||
);
|
||||
if checker.patch(diagnostic.kind.code()) {
|
||||
// Insert a newline just before the end-quote(s).
|
||||
let num_trailing_quotes = "'''".len();
|
||||
let num_trailing_spaces = last_line
|
||||
.chars()
|
||||
.rev()
|
||||
.skip(num_trailing_quotes)
|
||||
.take_while(|c| c.is_whitespace())
|
||||
.count();
|
||||
let content = format!("\n{}", whitespace::clean(docstring.indentation));
|
||||
diagnostic.amend(Fix::insertion(
|
||||
diagnostic.amend(Fix::replacement(
|
||||
content,
|
||||
Location::new(
|
||||
docstring.expr.end_location.unwrap().row(),
|
||||
docstring.expr.end_location.unwrap().column() - "\"\"\"".len(),
|
||||
docstring.expr.end_location.unwrap().column()
|
||||
- num_trailing_spaces
|
||||
- num_trailing_quotes,
|
||||
),
|
||||
Location::new(
|
||||
docstring.expr.end_location.unwrap().row(),
|
||||
docstring.expr.end_location.unwrap().column() - num_trailing_quotes,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
|
|
@ -19,4 +19,21 @@ expression: diagnostics
|
|||
row: 283
|
||||
column: 16
|
||||
parent: ~
|
||||
- kind:
|
||||
NewLineAfterLastParagraph: ~
|
||||
location:
|
||||
row: 588
|
||||
column: 4
|
||||
end_location:
|
||||
row: 590
|
||||
column: 21
|
||||
fix:
|
||||
content: "\n "
|
||||
location:
|
||||
row: 590
|
||||
column: 16
|
||||
end_location:
|
||||
row: 590
|
||||
column: 18
|
||||
parent: ~
|
||||
|
||||
|
|
|
@ -192,4 +192,14 @@ expression: diagnostics
|
|||
column: 7
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
MultiLineSummarySecondLine: ~
|
||||
location:
|
||||
row: 588
|
||||
column: 4
|
||||
end_location:
|
||||
row: 590
|
||||
column: 21
|
||||
fix: ~
|
||||
parent: ~
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue