From 8748a5d7f02a55da50b98a1d57651c321441ef47 Mon Sep 17 00:00:00 2001 From: Shengyu Zhang Date: Sat, 17 May 2025 13:51:21 +0800 Subject: [PATCH] js domain: Remove extra parentheses from function arguments and errors --- CHANGES.rst | 2 ++ doc/conf.py | 6 +++--- sphinx/domains/javascript.py | 6 +++--- tests/test_domains/test_domain_js.py | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index d26a93871a5..df4dffb4d6a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -20,6 +20,8 @@ Features added ``linkcheck_allowed_redirects = {}``. Patch by Adam Turner. * #13497: Support C domain objects in the table of contents. +* #13217: Remove extra parentheses from :rst:dir:`js:function` arguments and errors. + Patch by Shengyu Zhang. Bugs fixed ---------- diff --git a/doc/conf.py b/doc/conf.py index 9cf2f9b4856..23ac9211dc6 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -181,9 +181,9 @@ 'template template Wrapper::Outer::Inner', ), ('cpp:identifier', 'MyContainer'), - ('js:func', 'SomeError'), - ('js:func', 'number'), - ('js:func', 'string'), + ('js:class', 'SomeError'), + ('js:class', 'number'), + ('js:class', 'string'), ('py:attr', 'srcline'), ('py:class', '_AutodocProcessDocstringListener'), ('py:class', '_ConfigRebuild'), # sphinx.application.Sphinx.add_config_value diff --git a/sphinx/domains/javascript.py b/sphinx/domains/javascript.py index 51a93bcf802..5dddfe061b2 100644 --- a/sphinx/domains/javascript.py +++ b/sphinx/domains/javascript.py @@ -273,13 +273,13 @@ class JSCallable(JSObject): 'arguments', label=_('Arguments'), names=('argument', 'arg', 'parameter', 'param'), - typerolename='func', + typerolename='class', typenames=('paramtype', 'type'), ), GroupedField( 'errors', label=_('Throws'), - rolename='func', + rolename='class', names=('throws',), can_collapse=True, ), @@ -431,7 +431,7 @@ class JavaScriptDomain(Domain): roles = { 'func': JSXRefRole(fix_parens=True), 'meth': JSXRefRole(fix_parens=True), - 'class': JSXRefRole(fix_parens=True), + 'class': JSXRefRole(), 'data': JSXRefRole(), 'attr': JSXRefRole(), 'mod': JSXRefRole(), diff --git a/tests/test_domains/test_domain_js.py b/tests/test_domains/test_domain_js.py index d43c4b03ce1..0e1e8b92e1c 100644 --- a/tests/test_domains/test_domain_js.py +++ b/tests/test_domains/test_domain_js.py @@ -892,3 +892,17 @@ def test_domain_js_javascript_trailing_comma_in_multi_line_signatures_in_text(ap expected_f, ) assert expected_parameter_list_foo in content + + +# See: https://github.com/sphinx-doc/sphinx/issues/13217 +@pytest.mark.sphinx('html', testroot='_blank') +def test_js_function_parentheses_in_arguments_and_errors(app): + text = """.. js:function:: $.getJSON(herf[, error]) + + :param string arg: + :throws err:""" + doctree = restructuredtext.parse(app, text) + refnodes = list(doctree.findall(addnodes.pending_xref)) + assert len(refnodes) == 2 + assert_node(refnodes[0], [addnodes.pending_xref, nodes.literal, 'string']) + assert_node(refnodes[1], [addnodes.pending_xref, nodes.literal, 'err'])