Skip to main content

require-jsdoc

Require JSDoc comments for configured declaration kinds.

Targeted pattern scopeโ€‹

This rule checks declaration nodes that are configured via kinds, including:

  • function (FunctionDeclaration with an identifier)
  • class (ClassDeclaration with an identifier)
  • method (MethodDefinition, excluding constructors)
  • type (TSInterfaceDeclaration, TSTypeAliasDeclaration)
  • arrow-function (named const variable declarators initialized with an arrow function)

Each targeted declaration must have a leading JSDoc block comment (/** ... */).

What this rule reportsโ€‹

This rule reports declarations of configured kinds when they do not have a leading JSDoc block comment.

Why this rule existsโ€‹

When teams rely on declarations as API boundaries, missing JSDoc usually means missing intent, missing parameter semantics, and inconsistent generated docs. This rule enforces baseline documentation hygiene for selected declaration kinds.

โŒ Incorrectโ€‹

function f() {}

with options:

{
kinds: ["function"];
}

โœ… Correctโ€‹

/**
* Convert a domain identifier into a cache key.
*/
function f() {}

with options:

{
kinds: ["function"];
}

Deprecatedโ€‹

  • Lifecycle: Deprecated and frozen.
  • Deprecated since: v1.0.0
  • Available until: v2.0.0
  • Use instead: jsdoc/require-jsdoc

Behavior and migration notesโ€‹

This rule does not auto-fix because it cannot infer accurate documentation text.

For large repositories, start with a narrower kinds set (for example only function and class), then add method, type, and arrow-function after the initial backlog is resolved.

Optionsโ€‹

type Kind = "arrow-function" | "class" | "function" | "method" | "type";

type Options = [
{
kinds?: Kind[];
},
];

Default configurationโ€‹

[
{
kinds: [
"arrow-function",
"class",
"function",
"method",
"type",
],
},
];

Statusโ€‹

  • Lifecycle: Deprecated and frozen.
  • Deprecated since: v1.0.0
  • Available until: v2.0.0
  • Use instead: jsdoc/require-jsdoc

Additional examplesโ€‹

const identity = <T>(value: T) => value;

with options:

{
kinds: ["arrow-function"];
}
/**
* Return the input value unchanged.
*/
const identity = <T>(value: T) => value;

ESLint flat config exampleโ€‹

import etcMisc from "eslint-plugin-etc-misc";

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/require-jsdoc": ["error", { kinds: ["function"] }],
},
},
];

When not to use itโ€‹

Disable this rule if your project uses external documentation sources (for example ADRs or API schema files) and intentionally avoids inline JSDoc.

Package documentationโ€‹

Rule catalog ID: R062

Further readingโ€‹

Adoption resourcesโ€‹

  • Start at warning level in CI, then move to error after cleanup.
  • Use focused codemods/autofix batches per package or directory.