Page MenuHomePhabricator

Improve indicator for optional parameters
Closed, ResolvedPublic

Description

In headings in the JSDoc WMF theme, optional parameters are indicated by a subscript opt following the parameter, while in JSDuck optional parameters are indicated with square brackets. In addition, the color contrast between the opt text and the background is not accessible, originally reported in this on wiki comment.

I suggest replacing opt with square brackets for parity with JSDuck but happy to hear other ideas.

Note that parameters will be removed from titles as part of T359220

Event Timeline

apaskulin moved this task from Backlog to Accepted Enhancement on the JSDoc WMF theme board.

Change 1012431 had a related patch set uploaded (by Alex Paskulin; author: Alex Paskulin):

[jsdoc/wmf-theme@master] headings: Remove optional indicator

https://gerrit.wikimedia.org/r/1012431

After thinking about this, I don't think the square brackets are very obvious as indicators either, so I think we should instead rely on the parameters table to indicate explicitly which parameters are optional.

Change #1012431 merged by jenkins-bot:

[jsdoc/wmf-theme@master] headings: Remove optional indicator

https://gerrit.wikimedia.org/r/1012431

I support this change (I think no indicator at all is better than the "opt"), but the square brackets are a fairly common convention in documentation in various languages. Another common convention, maybe more obvious, is providing the default value after a "=" sign. Here's a few examples from docs that our developers may be familiar with:

I think it's fair to say that = is used when the parameter has some meaningful default value, and [] is used when it doesn't and the behavior of the function depends on the presence of the parameter (but since it's JavaScript, it's probably close enough to use =undefined in this case).


So, considering for example the function mw.util.debounce:

I think the ideal way to display it would be something like this:

  • debounce( func, wait=0, [immediate] ) → {function}, or
  • debounce( func, wait=0, immediate=undefined ) → {function}

Thanks for this comment, @matmarex. I think using square brackets sounds reasonable.

I worry about displaying defaults since we occasionally have really long defaults (see bugsLink on mw.Feedback) that would be noisy to display in a heading.

I looked into adding square brackets, but it wasn't trivial, so I opened T361154 to follow up.

Released as part of v1.0.0