Skip to content

Improvement jsdoc/require-returns rule #518

@alejandroclaro

Description

@alejandroclaro

The current jsdoc/require-returns implementation depends on the presence of a return statement, but an inconsistent case remains even when forceReturnsWithAsync is set to true.

It will be nice, at least in Typescript, to detect when async/await is used and the return is Promise<void> type. It strange and not very insightful document this case just because the type change from void to Promise. For example:

/**
 * Do something.
 *
 * @throws {Error} If something bad occurs.
 */
function doFoo(): void {
  // Do something.
}

/**
 * Do something.
 *
 * @returns The promise that is resolved once something is completed.
 *
 * @throws {Error} If something bad occurs.
 */
async function doBar(): Promise<void> {
  // Do something.
}

/**
 * Do something.
 *
 * @returns The promise that is resolved once something is completed.
 *
 * @throws {Error} If something bad occurs.
 */
async function doBaz(): Promise<void> {
  return new Promise<void>((resolve, reject) => {
    // For some reason its more convenient at some point to return a contruction like this.
  });
}

doFoo();
await doBar();
await doBaz();

To me all methods are similar in structure and documentation. However, the rule makes mandatory to document the result in doBar() and/or doBaz().

It would be nice if you can configure the rule to avoid having to document Promise<void> return when using async / wait.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions