Skip to content

require-returns-check: warns for @returns union with undefined #925

@kevinoid

Description

@kevinoid

Expected behavior

jsdoc/require-returns-check should not produce a warning or error for functions with @returns types which include undefined.

Actual behavior

The following warning is produced:

1:1  warning  JSDoc @returns declaration present but return expression not available in function  jsdoc/require-returns-check

ESLint Config

{
  "extends": [
    "plugin:jsdoc/recommended"
  ]
}

ESLint sample

/** Maybe return a boolean.
 *
 * @returns {boolean|undefined} true, or undefined.
 */
function maybeTrue() {
  if (Math.random() > 0.5) {
    return true;
  }
}

Environment

  • Node version: v18.10.0
  • ESLint version v8.26.0
  • eslint-plugin-jsdoc version: 39.3.22

Related Issues

#924

Additional Notes

I noticed the same issue occurs with @returns {boolean=}, but I'm not sure whether = is allowed in @returns types. It's only documented to signify optional parameters, not optional return values, as far as I can see.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions