Skip to content

Commit 2f5b2d5

Browse files
mattwang44hugovk
andauthored
Add checker for searching unnecessary parentheses in func & meth role (#115)
Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent a9559ba commit 2f5b2d5

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

sphinxlint/checkers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,3 +513,15 @@ 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, enabled=True)
519+
def check_unnecessary_parentheses(filename, lines, options):
520+
"""Check for unnecessary parentheses in :func: and :meth: roles.
521+
522+
Bad: :func:`test()`
523+
Good: :func:`test`
524+
"""
525+
for lno, line in enumerate(lines, start=1):
526+
if match := rst.ROLE_WITH_UNNECESSARY_PARENTHESES_RE.search(line):
527+
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+
ROLE_WITH_UNNECESSARY_PARENTHESES_RE = re.compile(r"(^|\s):(func|meth):`[^`]+\(\)`")

0 commit comments

Comments
 (0)