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

Ignore underlines when determining docstring logical lines #8929

Merged
merged 1 commit into from
Nov 30, 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
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


Loading