From 8bdb54adec6a985a698cbaef9df005c77b29ac99 Mon Sep 17 00:00:00 2001 From: Yuriy Andamasov Date: Thu, 14 May 2026 00:44:52 +0300 Subject: ci(doc-linter): fix RST code-block exit on short dedented lines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dedent check inside `handle_file_action()` was if in_rst_codeblock: if len(line) > rst_codeblock_indent and not line[rst_codeblock_indent].isspace(): in_rst_codeblock = False This worked only when the next line was at least `rst_codeblock_indent + 1` chars long — the indexing `line[rst_codeblock_indent]` requires that. A short dedented line (e.g., a single character at column 0 under a directive indented at column 4) failed the length guard and `in_rst_codeblock` stayed True. The block remained open longer than it should, suppressing line-length checks on subsequent prose until either EOF or the next `.. code-block::` reset the state. Replace with a leading-whitespace-count check: on any non-blank line, exit the block when leading-ws is <= the directive's column. Blank lines don't reset the block context. Test: a 3-line file with `.. code-block:: text` directive at col 0, one body line, a single `a` at col 0, then a 113-char line at col 0. With the old logic the long line is still treated as inside the code block and not flagged. With the new logic the single-`a` dedent exits the block and the long line is flagged as expected. Tracked as items 6 and 12 of the rolling-side cleanup backlog from PR #2014 / #2019 / #2020 reviews. 🤖 Generated by [robots](https://vyos.io) (cherry picked from commit 6628b2901933f67568ba68617ee27c6f843c6dcf) --- scripts/doc-linter.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'scripts/doc-linter.py') diff --git a/scripts/doc-linter.py b/scripts/doc-linter.py index f4628c0b..fe262d98 100644 --- a/scripts/doc-linter.py +++ b/scripts/doc-linter.py @@ -180,8 +180,21 @@ def handle_file_action(filepath): # Each `.. code-block::` directive resets the tracked indent so a # later dedent past that column exits the block — even when the # directive itself appears inside an already-open outer block. - if in_rst_codeblock: - if len(line) > rst_codeblock_indent and not line[rst_codeblock_indent].isspace(): + # + # Exit when the next non-blank line's leading-whitespace count is + # <= the directive's column. The body of an RST code-block must + # be indented MORE than the directive itself, so leading-ws at or + # below `rst_codeblock_indent` signals the block has ended. + # + # Previously this used `len(line) > rst_codeblock_indent and not + # line[rst_codeblock_indent].isspace()`, which silently skipped + # the exit check on lines shorter than `rst_codeblock_indent + 1` + # chars — e.g., a 3-char dedented line under a directive at + # column 4 left the block open, suppressing line-length checks + # downstream. + if in_rst_codeblock and line.strip(): + leading = len(line) - len(line.lstrip()) + if leading <= rst_codeblock_indent: in_rst_codeblock = False if ".. code-block::" in line: in_rst_codeblock = True -- cgit v1.2.3