From bc8fe1d22a6a894b85a8130daabc8228c228fd2b Mon Sep 17 00:00:00 2001 From: Daniel Ching Date: Fri, 30 May 2025 18:26:44 -0500 Subject: [PATCH 1/2] NEW: Ignore line length when line is only a long URL Ignores lines whose contents are some whitespace, <, any text, >`_, then an optional punctuation. This allows for long lines to be a URL without breaking then, so that they remain clickable. --- sphinxlint/checkers.py | 3 +++ tests/fixtures/xpass/long-inline-link.rst | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/fixtures/xpass/long-inline-link.rst diff --git a/sphinxlint/checkers.py b/sphinxlint/checkers.py index 05afe352d..e4d36df72 100644 --- a/sphinxlint/checkers.py +++ b/sphinxlint/checkers.py @@ -421,6 +421,7 @@ def check_missing_final_newline(file, lines, options=None): _starts_with_directive_or_hyperlink = re.compile(r"^\s*\.\. ").match _starts_with_anonymous_hyperlink = re.compile(r"^\s*__ ").match _is_very_long_string_literal = re.compile(r"^\s*``[^`]+``$").match +_is_very_long_inline_link = re.compile(r"^\s*<.*(>`_).?$").match @checker(".rst", ".po", enabled=False, rst_only=True) @@ -439,6 +440,8 @@ def check_line_too_long(file, lines, options=None): continue # ignore anonymous hyperlink targets if _is_very_long_string_literal(line): continue # ignore a very long literal string + if _is_very_long_inline_link(line): + continue # ignore a very long URL on its own line" yield lno + 1, f"Line too long ({len(line) - 1}/{options.max_line_length})" diff --git a/tests/fixtures/xpass/long-inline-link.rst b/tests/fixtures/xpass/long-inline-link.rst new file mode 100644 index 000000000..c4facbffe --- /dev/null +++ b/tests/fixtures/xpass/long-inline-link.rst @@ -0,0 +1,16 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent rhoncus +volutpat felis, eu egestas sapien tristique a. Vivamus scelerisque nunc nec arcu +pharetra, sit amet feugiat lorem consequat. See this extremely long link here: +`A Very Long Inline Link Example +`_. + +Donec ultrices, nisi sit amet cursus pharetra, arcu lacus tincidunt ligula, eget +fringilla ex turpis vel odio. Curabitur feugiat pretium lorem a fringilla. +Suspendisse eget orci eu sem tincidunt auctor. + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent rhoncus + volutpat felis, eu egestas sapien tristique a. Vivamus scelerisque nunc nec + arcu pharetra, sit amet feugiat lorem consequat. See this extremely long + link here: `A Very Long Inline Link Example + `_. + From a86625c7e4e3f02170518f9bfb1d2bdd62686cf2 Mon Sep 17 00:00:00 2001 From: Daniel Ching Date: Mon, 2 Jun 2025 09:56:06 -0500 Subject: [PATCH 2/2] STY: Fixup line endings --- sphinxlint/checkers.py | 2 +- tests/fixtures/xpass/long-inline-link.rst | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/sphinxlint/checkers.py b/sphinxlint/checkers.py index e4d36df72..f0998d329 100644 --- a/sphinxlint/checkers.py +++ b/sphinxlint/checkers.py @@ -441,7 +441,7 @@ def check_line_too_long(file, lines, options=None): if _is_very_long_string_literal(line): continue # ignore a very long literal string if _is_very_long_inline_link(line): - continue # ignore a very long URL on its own line" + continue # ignore a very long URL on its own line yield lno + 1, f"Line too long ({len(line) - 1}/{options.max_line_length})" diff --git a/tests/fixtures/xpass/long-inline-link.rst b/tests/fixtures/xpass/long-inline-link.rst index c4facbffe..e34197d73 100644 --- a/tests/fixtures/xpass/long-inline-link.rst +++ b/tests/fixtures/xpass/long-inline-link.rst @@ -13,4 +13,3 @@ Suspendisse eget orci eu sem tincidunt auctor. arcu pharetra, sit amet feugiat lorem consequat. See this extremely long link here: `A Very Long Inline Link Example `_. -