diff --git a/pyproject.toml b/pyproject.toml index 8cb3b23e2..13c583f41 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,8 @@ packages = [ "sphinxlint" ] [tool.hatch.version.raw-options] local_scheme = "no-local-version" +[tool.black] + [tool.ruff] fix = true diff --git a/sphinxlint/checkers.py b/sphinxlint/checkers.py index 79d62ff2a..e70188831 100644 --- a/sphinxlint/checkers.py +++ b/sphinxlint/checkers.py @@ -261,15 +261,17 @@ def check_missing_underscore_after_hyperlink(file, lines, options=None): URLs within download directives don't need trailing underscores. https://www.sphinx-doc.org/en/master/usage/referencing.html#role-download """ - for lno, line in enumerate(lines, start=1): - if "`" not in line: + for paragraph_lno, paragraph in paragraphs(lines): + if "`" not in paragraph: continue - for match in rst.SEEMS_HYPERLINK_RE.finditer(line): + for match in rst.SEEMS_HYPERLINK_RE.finditer(paragraph): if not match.group(2): # Check if this is within any download directive on the line # Include optional underscore in pattern to handle both cases is_in_download = False - for download_match in rst.HYPERLINK_WITHIN_DOWNLOAD_RE.finditer(line): + for download_match in rst.HYPERLINK_WITHIN_DOWNLOAD_RE.finditer( + paragraph + ): if ( match.start() >= download_match.start() and match.end() <= download_match.end() @@ -277,7 +279,11 @@ def check_missing_underscore_after_hyperlink(file, lines, options=None): is_in_download = True break if not is_in_download: - yield lno, "missing underscore after closing backtick in hyperlink" + error_offset = paragraph[: match.start()].count("\n") + yield ( + paragraph_lno + error_offset, + "missing underscore after closing backtick in hyperlink", + ) @checker(".rst", ".po") diff --git a/tests/fixtures/xfail/hyperlink-missing-underscore-split-in-two-lines.rst b/tests/fixtures/xfail/hyperlink-missing-underscore-split-in-two-lines.rst new file mode 100644 index 000000000..7aef4149f --- /dev/null +++ b/tests/fixtures/xfail/hyperlink-missing-underscore-split-in-two-lines.rst @@ -0,0 +1,4 @@ +.. expect: missing underscore after closing backtick in hyperlink (missing-underscore-after-hyperlink) + +`Link text +`