diff --git a/sphinxlint/checkers.py b/sphinxlint/checkers.py index 5354606f6..4fe038c62 100644 --- a/sphinxlint/checkers.py +++ b/sphinxlint/checkers.py @@ -461,10 +461,12 @@ def check_block(block_lineno, block): yield from errors +_DANGLING_HYPHEN_RE = re.compile(r".*[a-z]-$") + @checker(".rst", rst_only=True) def check_dangling_hyphen(file, lines, options): """Check for lines ending in a hyphen.""" for lno, line in enumerate(lines): stripped_line = line.rstrip("\n") - if re.match(r".*[a-z]-$", stripped_line): + if _DANGLING_HYPHEN_RE.match(stripped_line): yield lno + 1, f"Line ends with dangling hyphen"