diff --git a/crates/ruff_linter/resources/test/fixtures/pydocstyle/D400.py b/crates/ruff_linter/resources/test/fixtures/pydocstyle/D400.py index 38547d4addd9a..3c6cc5bfce7b1 100644 --- a/crates/ruff_linter/resources/test/fixtures/pydocstyle/D400.py +++ b/crates/ruff_linter/resources/test/fixtures/pydocstyle/D400.py @@ -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 + """ diff --git a/crates/ruff_linter/src/rules/pydocstyle/helpers.rs b/crates/ruff_linter/src/rules/pydocstyle/helpers.rs index 355ff6ea16a8b..c165d34fa6815 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/helpers.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/helpers.rs @@ -10,8 +10,9 @@ pub(super) fn logical_line(content: &str) -> Option { // 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; } diff --git a/crates/ruff_linter/src/rules/pydocstyle/snapshots/ruff_linter__rules__pydocstyle__tests__D400_D400.py.snap b/crates/ruff_linter/src/rules/pydocstyle/snapshots/ruff_linter__rules__pydocstyle__tests__D400_D400.py.snap index 6b522fd3e9172..f7a9059cce9bd 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/snapshots/ruff_linter__rules__pydocstyle__tests__D400_D400.py.snap +++ b/crates/ruff_linter/src/rules/pydocstyle/snapshots/ruff_linter__rules__pydocstyle__tests__D400_D400.py.snap @@ -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 +