Skip to content

Commit 70d20fc

Browse files
committed
[FIX] tests: don't confuse separators for heading delimiters
RST separators (`-----`) look similar to H3 delimiters that use the same `-` character, but separators' length should not be checked. X-original-commit: a54a688 Part-of: #12270 Signed-off-by: Antoine Vandevenne (anv) <[email protected]>
1 parent d87a254 commit 70d20fc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Diff for: tests/checkers/rst_style.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ def check_min_one_main_heading(file, lines, options=None):
7474
def check_heading_delimiters_length(file, lines, options=None):
7575
""" Check that heading delimiters have the same length as their heading. """
7676
for lno, line in enumerate(lines):
77-
if HEADING_DELIMITER_RE.search(line): # The line is a heading delimiter.
77+
previous_line = lno >= 1 and lines[lno - 1]
78+
if HEADING_DELIMITER_RE.search(line) and previous_line != '\n': # Heading delimiter found.
7879
if MAIN_HEADING_RE.search(''.join(lines[lno:lno+3])): # Upper delimiter of h1.
7980
heading_lno = lno + 1
8081
else: # Lower delimiter of a heading of any level.
@@ -87,7 +88,8 @@ def check_heading_delimiters_length(file, lines, options=None):
8788
def check_heading_spacing(file, lines, options=None):
8889
""" Check that headings are preceded and followed by at least one blank line. """
8990
for lno, line in enumerate(lines):
90-
if HEADING_DELIMITER_RE.search(line): # The line is a heading delimiter.
91+
previous_line = lno > 1 and lines[lno - 1]
92+
if HEADING_DELIMITER_RE.search(line) and previous_line != '\n': # Heading delimiter found.
9193
if MAIN_HEADING_RE.search(''.join(lines[lno:lno+3])): # Upper delimiter of h1.
9294
continue # We handle this heading via its lower delimiter.
9395

0 commit comments

Comments
 (0)