mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:56 +00:00
Don't trim last empty line in docstrings (#9813)
This commit is contained in:
parent
55d0e1148c
commit
80fc02e7d5
3 changed files with 186 additions and 2 deletions
|
@ -6,6 +6,7 @@ use std::{borrow::Cow, collections::VecDeque};
|
|||
|
||||
use ruff_formatter::printer::SourceMapGeneration;
|
||||
use ruff_python_parser::ParseError;
|
||||
|
||||
use {once_cell::sync::Lazy, regex::Regex};
|
||||
use {
|
||||
ruff_formatter::{write, FormatOptions, IndentStyle, LineWidth, Printed},
|
||||
|
@ -114,7 +115,10 @@ pub(crate) fn format(normalized: &NormalizedString, f: &mut PyFormatter) -> Form
|
|||
// is_borrowed is unstable :/
|
||||
let already_normalized = matches!(docstring, Cow::Borrowed(_));
|
||||
|
||||
let mut lines = docstring.lines().peekable();
|
||||
// Use `split` instead of `lines` to preserve the closing quotes on their own line
|
||||
// if they have no indentation (in which case the last line is `\n` which
|
||||
// `lines` omit for the last element).
|
||||
let mut lines = docstring.split('\n').peekable();
|
||||
|
||||
// Start the string
|
||||
write!(f, [normalized.prefix, normalized.quotes])?;
|
||||
|
@ -259,7 +263,7 @@ impl<'ast, 'buf, 'fmt, 'src> DocstringLinePrinter<'ast, 'buf, 'fmt, 'src> {
|
|||
/// iterator given contains all lines except for the first.
|
||||
fn add_iter(
|
||||
&mut self,
|
||||
mut lines: std::iter::Peekable<std::str::Lines<'src>>,
|
||||
mut lines: std::iter::Peekable<std::str::Split<'src, char>>,
|
||||
) -> FormatResult<()> {
|
||||
while let Some(line) = lines.next() {
|
||||
let line = InputDocstringLine {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue