tsdoc-require-2/require
Require TSDoc comments for supported TypeScript declarations and default exports, with configurable export scope.
Rule catalog ID: R001
Targeted pattern scopeâ
By default, this rule reports supported exported declarations that do not have a TSDoc block comment (/** ... */) directly above them.
It evaluates top-level declarations and handles both inline exports and export specifiers.
What this rule reportsâ
It checks:
- exported classes
- exported functions
- exported interfaces
- exported namespaces and
declare moduledeclarations - exported type aliases
- exported enums
- exported variables
- default exports (including default-exported identifiers)
For default exports, supported expression forms include function/class expressions, object expressions, and arrow functions.
When exportMode: "all" is enabled, the same checks also apply to non-exported top-level declarations. When exportMode: "non-exported" is enabled, only non-exported top-level declarations are checked.
Why this rule existsâ
If exported APIs are undocumented, consumers have to infer contracts from implementation details.
This rule is the foundation for the plugin's policy model:
required-tagsrules validate comment content.restrict-tagsvalidates tag vocabulary.requireensures those checks have an actual comment block to validate.
â Incorrectâ
export class MissingDocs {}
interface Shape {
radius: number;
}
export { Shape };
const createUser = () => ({ id: "1" });
export default createUser;
â Correctâ
/** Public class used by external callers. */
export class DocumentedClass {}
/** Shape shared in the public API. */
interface Shape {
radius: number;
}
export { Shape };
/** Creates the default exported user payload. */
const createUser = () => ({ id: "1" });
export default createUser;
Behavior and migration notesâ
- Start with
exportMode: "exported"to enforce public API docs first. - Expand to
"all"when internal top-level declarations should also be documented. - Keep
exportModeandenforceForaligned withrequire-*andrestrict-tagsrules so documentation policy remains consistent. includeNonExportedremains supported as a legacy alias forexportMode: "all", but new configurations should preferexportMode.
Additional examplesâ
Optionsâ
This rule accepts one optional object.
type Options = [
{
enforceFor?: Array<
| "class"
| "enum"
| "function"
| "interface"
| "namespace"
| "object"
| "type"
| "variable"
>;
exportMode?: "all" | "exported" | "non-exported";
includeNonExported?: boolean;
},
];
Default options:
[
{
enforceFor: [
"class",
"enum",
"function",
"interface",
"namespace",
"object",
"type",
"variable",
],
exportMode: "exported",
},
];
enforceForâ
Limits which entity kinds are checked.
Example flat config that only enforces docs for classes and functions:
import tsdocRequire from "eslint-plugin-tsdoc-require-2";
export default [
{
plugins: {
"tsdoc-require-2": tsdocRequire,
},
rules: {
"tsdoc-require-2/require": [
"error",
{
enforceFor: ["class", "function"],
},
],
},
},
];
exportModeâ
Controls whether the rule checks exported declarations, non-exported top-level declarations, or both.
"exported"(default): check exported declarations and default exports."non-exported": only check supported non-exported top-level declarations."all": check both exported and non-exported top-level declarations.
Example flat config:
import tsdocRequire from "eslint-plugin-tsdoc-require-2";
export default [
{
plugins: {
"tsdoc-require-2": tsdocRequire,
},
rules: {
"tsdoc-require-2/require": [
"error",
{
exportMode: "all",
},
],
},
},
];
includeNonExportedâ
includeNonExported is still supported as a backward-compatible alias for exportMode: "all". Prefer exportMode in new configurations because it can also express "non-exported" explicitly.
When not to use itâ
Disable this rule if your project intentionally does not require API documentation on exported declarations (or internal declarations when includeNonExported is enabled).