summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorYuriy Andamasov <yuriy@vyos.io>2026-05-14 00:44:52 +0300
committerMergify <37929162+mergify[bot]@users.noreply.github.com>2026-05-14 05:08:37 +0000
commitf25ab53af3bb081f6d125f0c14ff9e611d201af3 (patch)
treea09aea0d093a8ec227dd89156298518d54f777f4 /scripts
parent9f7c9c56f3dd1cbbc18ccb7c3f5f039a9d7a2dd2 (diff)
downloadvyos-documentation-f25ab53af3bb081f6d125f0c14ff9e611d201af3.tar.gz
vyos-documentation-f25ab53af3bb081f6d125f0c14ff9e611d201af3.zip
ci(doc-linter): fix RST code-block exit on short dedented lines
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)
Diffstat (limited to 'scripts')
-rw-r--r--scripts/doc-linter.py17
1 files changed, 15 insertions, 2 deletions
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