Skip to content

Commit

Permalink
Add checker for searching unnecessary parentheses in func & meth role (
Browse files Browse the repository at this point in the history
…#115)

Co-authored-by: Hugo van Kemenade <[email protected]>
  • Loading branch information
mattwang44 and hugovk authored Sep 2, 2024
1 parent a9559ba commit 2f5b2d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sphinxlint/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,3 +513,15 @@ def check_dangling_hyphen(file, lines, options):
stripped_line = line.rstrip("\n")
if _has_dangling_hyphen(stripped_line):
yield lno + 1, "Line ends with dangling hyphen"


@checker(".rst", ".po", rst_only=False, enabled=True)
def check_unnecessary_parentheses(filename, lines, options):
"""Check for unnecessary parentheses in :func: and :meth: roles.
Bad: :func:`test()`
Good: :func:`test`
"""
for lno, line in enumerate(lines, start=1):
if match := rst.ROLE_WITH_UNNECESSARY_PARENTHESES_RE.search(line):
yield lno, f"Unnecessary parentheses in {match.group(0).strip()!r}"
2 changes: 2 additions & 0 deletions sphinxlint/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,5 @@ def inline_markup_gen(start_string, end_string, extra_allowed_before=""):
)

ROLE_MISSING_CLOSING_BACKTICK_RE = re.compile(rf"({ROLE_HEAD}`[^`]+?)[^`]*$")

ROLE_WITH_UNNECESSARY_PARENTHESES_RE = re.compile(r"(^|\s):(func|meth):`[^`]+\(\)`")

0 comments on commit 2f5b2d5

Please sign in to comment.