From c35f966b0f1d3a0ba2600b50e4c7df7d62a5ee70 Mon Sep 17 00:00:00 2001 From: Shengyu Zhang Date: Sat, 17 May 2025 13:51:21 +0800 Subject: [PATCH 1/3] 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 792f6ce2201..1a155a84086 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -68,6 +68,8 @@ Features added Patch by Jean-François B. * #13508: Initial support for :pep:`695` type aliases. Patch by Martin Matouš, Jeremy Maitin-Shepard, and Adam Turner. +* #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 28dbdb58c46..ec4e24fab8b 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 6ebd1dec3fd..6702d9566a5 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, ), @@ -434,7 +434,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..4495360c017 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(href) + + :param string href: + :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']) From 6b29a290402dbd377679c193ba61a48723ea57ec Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 30 Nov 2025 05:01:34 +0000 Subject: [PATCH 2/3] post-merge --- tests/test_domains/test_domain_js.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/test_domains/test_domain_js.py b/tests/test_domains/test_domain_js.py index 4495360c017..32321b1b218 100644 --- a/tests/test_domains/test_domain_js.py +++ b/tests/test_domains/test_domain_js.py @@ -26,6 +26,10 @@ from sphinx.testing.util import assert_node from sphinx.writers.text import STDINDENT +TYPE_CHECKING = False +if TYPE_CHECKING: + from sphinx.testing.util import SphinxTestApp + @pytest.mark.sphinx('dummy', testroot='domain-js') def test_domain_js_xrefs(app): @@ -896,11 +900,13 @@ def test_domain_js_javascript_trailing_comma_in_multi_line_signatures_in_text(ap # 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(href) +def test_js_function_parentheses_in_arguments_and_errors(app: SphinxTestApp) -> None: + text = """\ +.. js:function:: $.getJSON(href) - :param string href: - :throws err:""" + :param string href: + :throws err: +""" doctree = restructuredtext.parse(app, text) refnodes = list(doctree.findall(addnodes.pending_xref)) assert len(refnodes) == 2 From ba4ec9456e9aceb4f23bf40dc34d948c979903a4 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 30 Nov 2025 06:07:21 +0000 Subject: [PATCH 3/3] Fix CHANGES entry --- CHANGES.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9bc519dd9e3..57b5a3d8723 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -102,8 +102,6 @@ Features added Patch by Matthias Geier. * #14029: intersphinx: Fix error in format string interpolation. Patch by Matthieu de Cibeins. -* #13217: Remove extra parentheses from :rst:dir:`js:function` arguments and errors. - Patch by Shengyu Zhang. Bugs fixed ---------- @@ -193,6 +191,8 @@ Bugs fixed Patch by Akihiro Takizawa. * #13741: text builder: fix an infinite loop when processing CSV tables. Patch by Bénédikt Tran. +* #13217: Remove extra parentheses from :rst:dir:`js:function` arguments and errors. + Patch by Shengyu Zhang. Testing