sphinx-contrib/sphinx-lint

Line mismatch in error message

hugovk opened this issue · 2 comments

sphinx-lint==0.6 finds a valid bug in this file:

https://github.com/python-pillow/Pillow/blame/a50addb8e212e57dfe703b3d792691b3e18b2587/winbuild/build.rst#L45

winbuild/build.rst:44: inline literal missing (escaped) space after literal: '``ARM64``b' (missing-space-after-literal)

However, the problem is on line 45 not 44.

This seems caused by a bug in the paragraph function:

sphinx-lint/sphinxlint.py

Lines 239 to 253 in b377556

def paragraphs(lines):
"""Yield (paragraph_line_no, paragraph_text) pairs describing
paragraphs of the given lines.
"""
paragraph = []
paragraph_lno = 1
for lno, line in enumerate(lines, start=1):
if line != "\n":
paragraph.append(line)
elif paragraph:
yield paragraph_lno, "".join(paragraph)
paragraph = []
paragraph_lno = lno
if paragraph:
yield paragraph_lno, "".join(paragraph)

I tried to run it on the file you linked, and it produced these numbers:

>>> with open(fname) as f:
...   for lno, p in paragraphs(f.readlines()):
...     print(lno, repr(p[:30]))
... 
1 'Building Pillow on Windows\n==='
3 '.. note:: For most people, the'
7 'This page describes the steps '
10 'Prerequisites\n-------------\n'
13 'Compilers\n^^^^^^^^^\n'
17 'Download and install:\n'
19 '* `Microsoft Visual Studio 201'
23 '* `CMake 3.12 or newer <https:'
26 '* x86/x64: `NASM <https://www.'
28 'Any version of Visual Studio 2'
31 'Paths to CMake (if standalone)'
34 'Build configuration\n----------'
37 'The following environment vari'
40 '* ``PYTHON`` + ``EXECUTABLE`` '
53 '``build_prepare.py`` also supp'
55 '* ``-v`` will print generated '

The relevant paragraph here is the one that starts with * ``PYTHON`` + ``EXECUTABLE`` . The paragraphs function says it starts at line 40, however the correct line number should be 41. Some of the other values are also off.

The following bit of code in check_missing_space_after_literal does 40 + 4 and gets 44, instead of doing 41 + 4 and get 45.

sphinx-lint/sphinxlint.py

Lines 230 to 236 in b377556

if not re.match(end_string_suffix, role.group(0)[-1]):
error_offset = paragraph[: role.start()].count("\n")
yield (
paragraph_lno + error_offset,
"inline literal missing "
f"(escaped) space after literal: {role.group(0)!r}",
)

I'm releasing v0.6.1 to fix this, thanks for reporting @hugovk! (And for fixing @ezio-melotti!)