Skip to content

Commit

Permalink
feat(checker): add checker for searching unncessary parentheses in func
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwang44 committed Aug 27, 2024
1 parent a9559ba commit 23f1f9b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions sphinxlint/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,3 +513,16 @@ 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)
def check_unnecessary_func_parentheses(filename, lines, options):
"""Check for unnecessary parentheses in :func: roles.
Bad: :func:`test()`
Good: :func:`test`
"""
for lno, line in enumerate(lines, start=1):
match = rst.FUNC_ROLE_WITH_UNNECESSARY_PARENTHESES.search(line)
if match:
yield lno, f"Unnecessary parentheses in {match.group(0)!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}`[^`]+?)[^`]*$")

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

0 comments on commit 23f1f9b

Please sign in to comment.