diff --git a/sphinxlint/checkers.py b/sphinxlint/checkers.py index ab54a3ec5..ff8b28809 100644 --- a/sphinxlint/checkers.py +++ b/sphinxlint/checkers.py @@ -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}" diff --git a/sphinxlint/rst.py b/sphinxlint/rst.py index 445689813..6dcc7d7bd 100644 --- a/sphinxlint/rst.py +++ b/sphinxlint/rst.py @@ -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:`[^`]+\(\)`")