Skip to content

Disallow optional parameters notation with question mark #489

@yvele

Description

@yvele

With auto fix

I would like to disallow optional parameters notation with question mark character ?.

Disallow this:

/**
 * @param {string?} foo Optional parameter.
 */

and this:

/**
 * @param {?string} foo Optional parameter.
 */

In favor of this (auto fixed):

/**
 * @param {string} [foo] Optional parameter.
 */

Actually both {string?} and {?string} cannot be disallowed and leads to inconstancy when writing optional parameter notation.

Also I'm not sure about the {string} [foo] notation, is this really the "official" notation to use when writing optional parameters?

I think so 🤔 https://jsdoc.app/tags-param.html#optional-parameters-and-default-values

An optional parameter (using JSDoc syntax)

/**
 * @param {string} [somebody] - Somebody's name.
 */
function sayHello(somebody) {
    if (!somebody) {
        somebody = 'John Doe';
    }
    alert('Hello ' + somebody);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions