Skip to content

Commit

Permalink
Another pre-compiled RE for better perf
Browse files Browse the repository at this point in the history
Signed-off-by: Rodrigo Tobar <[email protected]>
  • Loading branch information
rtobar committed Oct 11, 2023
1 parent c6e81e4 commit a004288
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sphinxlint/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit a004288

Please sign in to comment.