JSDoc linting rules for ESLint with comprehensive validation and configuration options.
npx @tessl/cli install tessl/npm-eslint-plugin-jsdoc@54.3.0ESLint Plugin JSDoc provides comprehensive JSDoc linting rules for ESLint that enforce documentation standards and best practices in JavaScript and TypeScript projects. It offers 57 linting rules to validate JSDoc comments including parameter descriptions, return types, example code syntax, and proper formatting, with extensive configuration options for teams requiring consistent documentation standards.
npm install eslint-plugin-jsdocESM (ES modules):
import jsdocPlugin from "eslint-plugin-jsdoc";CommonJS:
const jsdocPlugin = require("eslint-plugin-jsdoc");import jsdocPlugin from "eslint-plugin-jsdoc";
export default [
{
plugins: {
jsdoc: jsdocPlugin,
},
rules: {
"jsdoc/require-jsdoc": "error",
"jsdoc/require-param": "error",
"jsdoc/require-returns": "error",
},
},
// Use a predefined configuration
jsdocPlugin.configs["flat/recommended"],
];{
"plugins": ["jsdoc"],
"extends": ["plugin:jsdoc/recommended"],
"rules": {
"jsdoc/require-jsdoc": "error"
}
}import jsdocPlugin from "eslint-plugin-jsdoc";
export default [
jsdocPlugin.configs["flat/recommended-typescript"],
{
rules: {
"jsdoc/require-param-type": "off", // TypeScript provides types
"jsdoc/require-returns-type": "off"
}
}
];ESLint Plugin JSDoc is built around several key components:
Complete set of 57 ESLint rules for validating JSDoc comments, covering syntax, content, formatting, and semantic correctness.
// Plugin object with rules property
interface ESLintPluginJSDoc {
rules: {
[ruleName: string]: ESLintRule;
};
configs: {
[configName: string]: ESLintConfig;
};
}
// Individual rule structure
interface ESLintRule {
meta: {
type: "problem" | "suggestion" | "layout";
docs: {
description: string;
category: string;
recommended: boolean;
};
schema: JSONSchema7;
};
create(context: ESLintRuleContext): ESLintVisitors;
}Ready-to-use ESLint configurations for common JSDoc validation scenarios, including TypeScript-specific and stylistic variants.
interface ESLintConfig {
plugins?: string[] | { [pluginName: string]: ESLintPlugin };
rules: {
[ruleName: string]: ESLintRuleConfig;
};
name?: string;
}
type ESLintRuleConfig = "off" | "warn" | "error" |
["off" | "warn" | "error", ...any[]];Advanced processor plugin for validating JSDoc example code and default expressions as executable JavaScript/TypeScript.
interface JsdocProcessorOptions {
captionRequired?: boolean;
paddedIndent?: number;
checkDefaults?: boolean;
checkParams?: boolean;
checkExamples?: boolean;
checkProperties?: boolean;
matchingFileName?: string;
matchingFileNameDefaults?: string;
matchingFileNameParams?: string;
matchingFileNameProperties?: string;
exampleCodeRegex?: string | RegExp;
rejectExampleCodeRegex?: string | RegExp;
allowedLanguagesToProcess?: string[];
sourceType?: "script" | "module";
parser?: ESLintParser;
}
function getJsdocProcessorPlugin(options?: JsdocProcessorOptions): ESLintPlugin;Internal utilities for building custom JSDoc ESLint rules (advanced usage).
// Core rule builder function
function iterateJsdoc(
iterator: RuleIterator,
ruleConfig: RuleConfig
): ESLintRule;
// Additional utility exports
interface UtilityExports {
parseComment: (comment: Comment) => JsdocBlock;
}These utilities are primarily intended for plugin developers who need to create custom JSDoc rules.
interface ESLintPlugin {
meta: {
name: string;
version: string;
};
rules?: { [ruleName: string]: ESLintRule };
configs?: { [configName: string]: ESLintConfig };
processors?: { [processorName: string]: ESLintProcessor };
}
interface ESLintRuleContext {
getSourceCode(): SourceCode;
report(descriptor: ReportDescriptor): void;
options: any[];
settings: { [name: string]: any };
}
interface ReportDescriptor {
node: ESTreeNode;
message: string;
data?: { [key: string]: string };
fix?: (fixer: RuleFixer) => Fix | Fix[] | null;
}
type ESLintVisitors = {
[nodeType: string]: (node: ESTreeNode) => void;
};