Skip to content

Commit 77a1cfe

Browse files
committed
feat(checker): add checker for searching unncessary parentheses in func
1 parent a9559ba commit 77a1cfe

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

sphinxlint/checkers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,3 +513,16 @@ def check_dangling_hyphen(file, lines, options):
513513
stripped_line = line.rstrip("\n")
514514
if _has_dangling_hyphen(stripped_line):
515515
yield lno + 1, "Line ends with dangling hyphen"
516+
517+
518+
@checker(".rst", ".po", rst_only=False)
519+
def check_unnecessary_func_parentheses(filename, lines, options):
520+
"""Check for unnecessary parentheses in :func: roles.
521+
522+
Bad: :func:`test()`
523+
Good: :func:`test`
524+
"""
525+
for lno, line in enumerate(lines, start=1):
526+
match = rst.FUNC_ROLE_WITH_UNNECESSARY_PARENTHESES.search(line)
527+
if match:
528+
yield lno, f"Unnecessary parentheses in {match.group(0).strip()!r}"

sphinxlint/rst.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,5 @@ def inline_markup_gen(start_string, end_string, extra_allowed_before=""):
280280
)
281281

282282
ROLE_MISSING_CLOSING_BACKTICK_RE = re.compile(rf"({ROLE_HEAD}`[^`]+?)[^`]*$")
283+
284+
FUNC_ROLE_WITH_UNNECESSARY_PARENTHESES = re.compile(r"(^|\s):func:`[^`]+\(\)`")

0 commit comments

Comments
 (0)