2 min read

REQUIRE_DOCS_ON_EXPORTED_FUNCTIONS

Requires that all exported functions have JSDoc comments.
Table of Contents

Conformance is available on Enterprise plans

This rule is available from version 1.8.0.

Adding JSDoc to exported functions helps engineers to quickly understand the purpose and application of those functions when reviewing or using them.

This is particularly important in packages where the source code may be minified and/or obfuscated, and can save users time by avoiding the need to find usage information in external documentation.

For more information on JSDoc, see Getting started with JSDoc.

Additionally, for non-TypeScript projects, JSDoc can be used to declare type information for function parameters and return values. For packages, these declarations can provide type information for both JavaScript and TypeScript consumers.

The below function is a minimal example of a function that would be caught by this rule.

export function appendWorld(str: string): string {
  return str + ' world';
}

This rule will also catch references within the same file, and different ways of declaring functions. For example:

const appendWorld = function (str: string): string {
  return str + ' world';
};
 
export default appendWorld;

This rule non-function exports and re-exports of functions.

To resolve this issue, add a JSDoc comment to the exported function.

/**
 * Modifies a string by appending `' world'` to it.
 */
export function appendWorld(str: string): string {
  return str + ' world';
}

You can add additional information to the JSDoc comment, such as descriptions of the function's parameters and return value.

/**
 * Modifies a string by appending `' world'` to it.
 *
 * @param str - The string to modify.
 * @returns The modified string.
 */
export function appendWorld(str: string): string {
  return str + ' world';
}

The example above doesn't provide type information in the JSDoc comment, as this information is already provided by the function signature. When working without TypeScript, you can also provide this information using JSDoc.

/**
 * Modifies a string by appending `' world'` to it.
 *
 * @param {string} str - The string to modify.
 * @returns {string} The modified string.
 */
export function appendWorld(str) {
  return str + ' world';
}
Last updated on May 18, 2024