Treat whitespace-only line as blank for D411 (#7351)

This better aligns with the definition of "blank line" that we use
throughout the docstring rules.

Closes https://github.com/astral-sh/ruff/issues/7216.
This commit is contained in:
Charlie Marsh 2023-09-13 12:41:12 -04:00 committed by GitHub
parent 4f26002dd5
commit f0f7ea7502
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View File

@ -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.
"""

View File

@ -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(),

View File

@ -496,5 +496,6 @@ sections.py:527:5: D407 [*] Missing dashed underline after section ("Parameters"
530 |+ ----------
530 531 | ===========
531 532 | """
532 533 |