[pydocstyle] Trim whitespace when removing blank lines after sectio… · astral-sh/ruff@c73c497 (original) (raw)

File tree

4 files changed

lines changed

4 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -57,3 +57,15 @@ def func():
57 57
58 58 Returns:
59 59 the value"""
60 +
61 +
62 +def func():
63 +"""Do something.
64 +
65 + Args:
66 + x: the value
67 + with a hanging indent
68 +
69 + Returns:
70 + the value
71 + """
Original file line number Diff line number Diff line change
@@ -1665,21 +1665,30 @@ fn common_section(
1665 1665 .take_while(|line
1666 1666 .count();
1667 1667 if num_blank_lines < 2 {
1668 -let mut diagnostic = Diagnostic::new(
1669 -BlankLineAfterLastSection {
1670 - name: context.section_name().to_string(),
1671 - },
1672 -docstring.range(),
1673 -);
1674 - // Add a newline after the section.
1675 -diagnostic.set_fix(Fix::safe_edit(Edit::insertion(
1668 +let del_len = if num_blank_lines == 1 {
1669 +// SAFETY: Guaranteed to not be None, because `num_blank_lines`is 1.
1670 + context.following_lines().next_back().unwrap().text_len()
1671 +} else {
1672 +TextSize::new(0)
1673 +};
1674 +
1675 +let edit = Edit::replacement(
1676 1676 format!(
1677 1677 "{}{}",
1678 1678 line_end.repeat(2 - num_blank_lines),
1679 1679 docstring.indentation
1680 1680 ),
1681 + context.end() - del_len,
1681 1682 context.end(),
1682 -)));
1683 +);
1684 +
1685 +let mut diagnostic = Diagnostic::new(
1686 +BlankLineAfterLastSection {
1687 +name: context.section_name().to_string(),
1688 +},
1689 + docstring.range(),
1690 +);
1691 + diagnostic.set_fix(Fix::safe_edit(edit));
1683 1692 checker.diagnostics.push(diagnostic);
1684 1693 }
1685 1694 }
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ D413.py:13:5: D413 [*] Missing blank line after last section ("Returns")
46 46 18 18 |
47 47 19 19 | Returns:
48 48 20 20 | the value
49 -21 |+
49 +21 |+
50 50 21 22 | """
51 51 22 23 |
52 52 23 24 |
@@ -75,5 +75,31 @@ D413.py:52:5: D413 [*] Missing blank line after last section ("Returns")
75 75 59 |+ the value
76 76 60 |+
77 77 61 |+ """
78 +60 62 |
79 +61 63 |
80 +62 64 | def func():
78 81
82 +D413.py:63:5: D413 [*] Missing blank line after last section ("Returns")
83 +|
84 +62 | def func():
85 +63 | """Do something.
86 +| _____^
87 +64 |
88 +65 |
89 +66 |
90 +67 |
91 +68 |
92 +69 |
93 +70 |
94 +71 |
95 + |
96 +|
97 += help: Add blank line after "Returns"
79 98
99 +ℹ Safe fix
100 +68 68 |
101 +69 69 | Returns:
102 +70 70 | the value
103 +71 |- """
104 + 71 |+
105 +72 |+ """
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ sections.py:120:5: D413 [*] Missing blank line after last section ("Returns")
44 44 122 122 | Returns
45 45 123 123 | -------
46 46 124 124 | A value of some sort.
47 -125 |+
47 +125 |+
48 48 125 126 | """
49 49 126 127 |
50 50 127 128 |
@@ -67,7 +67,7 @@ sections.py:170:5: D413 [*] Missing blank line after last section ("Returns")
67 67 171 171 |
68 68 172 172 | Returns
69 69 173 173 | -------
70 -174 |+
70 +174 |+
71 71 174 175 | """
72 72 175 176 |
73 73 176 177 |
@@ -89,7 +89,7 @@ sections.py:519:5: D413 [*] Missing blank line after last section ("Parameters")
89 89 520 520 |
90 90 521 521 | Parameters
91 91 522 522 | ==========
92 -523 |+
92 +523 |+
93 93 523 524 | """
94 94 524 525 |
95 95 525 526 |
@@ -111,7 +111,7 @@ sections.py:527:5: D413 [*] Missing blank line after last section ("Parameters")
111 111 528 528 |
112 112 529 529 | Parameters
113 113 530 530 | ===========
114 -531 |+
114 +531 |+
115 115 531 532 | """
116 116 532 533 |
117 117 533 534 |
@@ -135,7 +135,7 @@ sections.py:548:5: D413 [*] Missing blank line after last section ("Args")
135 135 551 551 | Here's a note.
136 136 552 552 |
137 137 553 553 | returns:
138 -554 |+
138 +554 |+
139 139 554 555 | """
140 140 555 556 |
141 141 556 557 |
@@ -159,7 +159,7 @@ sections.py:558:5: D413 [*] Missing blank line after last section ("Returns")
159 159 561 561 | Here's a note.
160 160 562 562 |
161 161 563 563 | Returns:
162 -564 |+
162 +564 |+
163 163 564 565 | """
164 164 565 566 |
165 165 566 567 |
@@ -185,9 +185,7 @@ sections.py:588:5: D413 [*] Missing blank line after last section ("Parameters")
185 185 593 593 | A list of string parameters
186 186 594 594 | value:
187 187 595 595 | Some value
188 -596 |+
188 +596 |+
189 189 596 597 | """
190 190 597 598 |
191 -598 599 |
192 -
193 -
191 +598 599 |