Overview of eslint-plugin-jsdoc
maineslint-plugin-jsdoc provides JSDoc linting rules for ESLint, allowing you to enforce documentation standards and quality within your JavaScript codebases.repository·main·Indexed 23 days ago
https://github.com/gajus/eslint-plugin-jsdocAn ESLint plugin providing a suite of rules for linting JSDoc comments to enforce documentation standards and quality. It supports ESLint Flat Config and legacy .eslintrc formats, offering recommended rulesets for JavaScript, TypeScript, and TSDoc. Features include fixable rules, custom rule definitions via extraRuleDefinitions, and a processor to lint JavaScript code inside JSDoc tags like @example.
eslint-plugin-jsdoc provides JSDoc linting rules for ESLint, allowing you to enforce documentation standards and quality within your JavaScript codebases.require-jsdoc rule checks for the presence of JSDoc comments on class declarations and functions. It can be configured to target specific AST contexts, handle exports, and automatically fix missing documentation.check-property-names rule ensures that JSDoc property names within the same block are not duplicated and that nested properties have clearly defined roots. It validates both @property and its alias @prop tags.The jsdoc/no-missing-syntax rule reports when specific, expected JSDoc comment structures are missing from certain AST contexts. It allows you to validate that arbitrary structures (like specific tags or types) exist above specific code elements (like function declarations or variable assignments).
This rule is useful for:
overrides.@type or other tags to ensure code can be compiled (e.g., to WebAssembly via AssemblyScript).@private or @enum) are always accompanied by the correct JSDoc block.Unlike similar rules in other plugins, this rule always looks for a comment above a structure, regardless of whether a comment condition is specified.
The check-examples rule ensures that JavaScript samples within @example tags adhere to your project's ESLint rules. It can also be configured to lint default values in @param, @arg, @argument, @property, @prop, or @default tags.
Important Compatibility Note: This rule only works in ESLint 7. For ESLint 9, you must use the processors instead.
The @next tag is a non-standard JSDoc tag used to indicate the type/description of the value supplied to an iterator via .next(value).
When the next: true option is enabled, the rule requires that any function using @next contains a yield statement that captures a return value, such as const rv = yield; or const rv = yield value;. It will report an error if the body only contains plain yield; or yield value; statements without assignment.
/**
* @next {SomeType}
*/
function * quux (foo) {
const a = yield; // Required when next: true is enabled
}The type-formatting rule is used to format JSDoc type values.
Warning: This rule is experimental. The stringification process might not preserve all aspects of your original formatting and could potentially introduce errors.
This rule can be configured via a single options object containing various properties to control spacing, brackets, quotes, and separators within JSDoc types.
You can configure the rule to skip parameter checks in specific scenarios:
exemptedBy: ['type'] to ignore functions that are documented via @type instead of @param.interfaceExemptsParamsCheck is true, functions whose types are defined by an interface (e.g., const quux: FunctionInterface = ...) will not be checked for parameters.contexts to target specific AST nodes like ArrowFunctionExpression or TSFunctionType./** @type {MyCallback} */
function quux () {
}
// "jsdoc/require-param": ["error"|"warn", {"exemptedBy":["type"]}]
/**
*
*/
const quux: FunctionInterface = function quux (foo) {
};
// "jsdoc/require-param": ["error"|"warn", {"interfaceExemptsParamsCheck":true}]The contexts option allows you to limit where the rule is applied. This is useful if you only want to enforce description rules on certain structures like class properties or TypeScript interfaces.
Commonly used contexts:
PropertyDefinition: For class fields.TSInterfaceDeclaration: For TypeScript interfaces.any: To apply to all contexts.You can also use complex selector objects for fine-grained control over which JSDoc blocks are targeted.
Many rules in eslint-plugin-jsdoc are marked as fixable, meaning they can be automatically corrected by running ESLint with the --fix flag.
Some fixable rules include an enableFixer option:
enableFixer: false to disable the automatic fixer for a specific rule.check-param-names, check-property-names, and no-blank-blocks, setting enableFixer: true enables a fixer that is not enabled by default in the recommended configuration.If you use custom JSDoc tags, you can use the settings.jsdoc.structuredTags setting to tell the no-undefined-types rule how to treat them:
name to a value that indicates it is "name-defining" or "namepath-defining".type to false.type to an array of strings.The rule's behavior changes significantly based on the descriptionStyle option:
body (Default)Requires text directly in the JSDoc block. Using only a @description tag without preceding text will fail.
/**
* This is a valid body description.
*/
function foo() {}
/**
* @description This will fail if style is 'body'
*/
function bar() {}tagRequires the @description or @desc tag. Implicit text in the body is not sufficient.
/**
* @description This is valid for 'tag' style.
*/
function foo() {}
/**
* This will fail if style is 'tag'
*/
function bar() {}anyAccepts both implicit body text and the @description tag.