From 40e2fcb7007caea39b24f707dd200afb3b84d727 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 13 Sep 2023 12:13:07 -0400 Subject: [PATCH] Treat whitespace-only line as blank for D411 --- .../resources/test/fixtures/pydocstyle/sections.py | 13 +++++++++++++ crates/ruff/src/rules/pydocstyle/rules/sections.rs | 5 ++++- ..._rules__pydocstyle__tests__D407_sections.py.snap | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/ruff/resources/test/fixtures/pydocstyle/sections.py b/crates/ruff/resources/test/fixtures/pydocstyle/sections.py index fef7f2fba15c3..223c55dff5f1e 100644 --- a/crates/ruff/resources/test/fixtures/pydocstyle/sections.py +++ b/crates/ruff/resources/test/fixtures/pydocstyle/sections.py @@ -529,3 +529,16 @@ def replace_equals_with_dash2(): Parameters =========== """ + + +@expect(_D213) +def non_empty_blank_line_before_section(): # noqa: D416 + """Toggle the gizmo. + + The function's description. + + Returns + ------- + A value of some sort. + + """ diff --git a/crates/ruff/src/rules/pydocstyle/rules/sections.rs b/crates/ruff/src/rules/pydocstyle/rules/sections.rs index 3d10a0c27aa69..34f78655c89ca 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/sections.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/sections.rs @@ -1691,7 +1691,10 @@ fn common_section( } if checker.enabled(Rule::NoBlankLineBeforeSection) { - if !context.previous_line().is_some_and(str::is_empty) { + if !context + .previous_line() + .is_some_and(|line| line.trim().is_empty()) + { let mut diagnostic = Diagnostic::new( NoBlankLineBeforeSection { name: context.section_name().to_string(), diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D407_sections.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D407_sections.py.snap index f0eac751331cb..6c296e9ca0eb5 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D407_sections.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D407_sections.py.snap @@ -496,5 +496,6 @@ sections.py:527:5: D407 [*] Missing dashed underline after section ("Parameters" 530 |+ ---------- 530 531 | =========== 531 532 | """ +532 533 |