Skip to content

Commit 0bc9311

Browse files
committed
js domain: Remove extra parentheses from function arguments and errors
1 parent c76d1bd commit 0bc9311

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Features added
2020
``linkcheck_allowed_redirects = {}``.
2121
Patch by Adam Turner.
2222
* #13497: Support C domain objects in the table of contents.
23+
* #13217: Remove extra parentheses from :rst:dir:`js:function` arguments and errors.
24+
Patch by Shengyu Zhang.
2325

2426
Bugs fixed
2527
----------

doc/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@
181181
'template<typename TOuter> template<typename TInner> Wrapper::Outer<TOuter>::Inner',
182182
),
183183
('cpp:identifier', 'MyContainer'),
184-
('js:func', 'SomeError'),
185-
('js:func', 'number'),
186-
('js:func', 'string'),
184+
('js:class', 'SomeError'),
185+
('js:class', 'number'),
186+
('js:class', 'string'),
187187
('py:attr', 'srcline'),
188188
('py:class', '_AutodocProcessDocstringListener'),
189189
('py:class', '_ConfigRebuild'), # sphinx.application.Sphinx.add_config_value

sphinx/domains/javascript.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,13 @@ class JSCallable(JSObject):
273273
'arguments',
274274
label=_('Arguments'),
275275
names=('argument', 'arg', 'parameter', 'param'),
276-
typerolename='func',
276+
typerolename='class',
277277
typenames=('paramtype', 'type'),
278278
),
279279
GroupedField(
280280
'errors',
281281
label=_('Throws'),
282-
rolename='func',
282+
rolename='class',
283283
names=('throws',),
284284
can_collapse=True,
285285
),
@@ -431,7 +431,7 @@ class JavaScriptDomain(Domain):
431431
roles = {
432432
'func': JSXRefRole(fix_parens=True),
433433
'meth': JSXRefRole(fix_parens=True),
434-
'class': JSXRefRole(fix_parens=True),
434+
'class': JSXRefRole(),
435435
'data': JSXRefRole(),
436436
'attr': JSXRefRole(),
437437
'mod': JSXRefRole(),

tests/test_domains/test_domain_js.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
desc_sig_name,
2121
desc_sig_space,
2222
desc_signature,
23+
desc_optional,
2324
)
2425
from sphinx.domains.javascript import JavaScriptDomain
2526
from sphinx.testing import restructuredtext
@@ -892,3 +893,16 @@ def test_domain_js_javascript_trailing_comma_in_multi_line_signatures_in_text(ap
892893
expected_f,
893894
)
894895
assert expected_parameter_list_foo in content
896+
897+
# See: https://github.com/sphinx-doc/sphinx/issues/13217
898+
@pytest.mark.sphinx('html', testroot='_blank')
899+
def test_js_function_parentheses_in_arguments_and_errors(app):
900+
text = """.. js:function:: $.getJSON(herf[, error])
901+
902+
:param string arg:
903+
:throws err:"""
904+
doctree = restructuredtext.parse(app, text)
905+
refnodes = list(doctree.findall(addnodes.pending_xref))
906+
assert len(refnodes) == 2
907+
assert_node(refnodes[0], [addnodes.pending_xref, nodes.literal, 'string'])
908+
assert_node(refnodes[1], [addnodes.pending_xref, nodes.literal, 'err'])

0 commit comments

Comments
 (0)