Skip to content

Commit

Permalink
Ignore underlines when determining docstring logical lines
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Nov 30, 2023
1 parent 073eddb commit a3732ca
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
9 changes: 9 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pydocstyle/D400.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,12 @@ def f(rounds: list[int], number: int) -> bool:
bool: was the round played?
"""
return number in rounds


def f():
"""
My example
==========
My example explanation
"""
5 changes: 3 additions & 2 deletions crates/ruff_linter/src/rules/pydocstyle/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ pub(super) fn logical_line(content: &str) -> Option<usize> {
// Find the first logical line.
let mut logical_line = None;
for (i, line) in content.universal_newlines().enumerate() {
if line.trim().is_empty() {
// Empty line. If this is the line _after_ the first logical line, stop.
let trimmed = line.trim();
if trimmed.is_empty() || trimmed.chars().all(|c| matches!(c, '-' | '~' | '=' | '#')) {
// Empty line, or underline. If this is the line _after_ the first logical line, stop.
if logical_line.is_some() {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,28 @@ D400.py:69:5: D400 [*] First line should end with a period
73 73 |
74 74 |

D400.py:97:5: D400 [*] First line should end with a period
|
96 | def f():
97 | """
| _____^
98 | | My example
99 | | ==========
100 | |
101 | | My example explanation
102 | | """
| |_______^ D400
|
= help: Add period

Unsafe fix
95 95 |
96 96 | def f():
97 97 | """
98 |- My example
98 |+ My example.
99 99 | ==========
100 100 |
101 101 | My example explanation


0 comments on commit a3732ca

Please sign in to comment.