2 * @fileoverview Rule to check for jsdoc presence.
3 * @author Gyandeep Singh
12 description: "require JSDoc comments",
13 category: "Stylistic Issues",
15 url: "https://eslint.org/docs/rules/require-jsdoc"
33 FunctionDeclaration: {
37 ArrowFunctionExpression: {
46 additionalProperties: false,
50 additionalProperties: false
58 missingJSDocComment: "Missing JSDoc comment."
63 const source = context.getSourceCode();
64 const DEFAULT_OPTIONS = {
65 FunctionDeclaration: true,
66 MethodDefinition: false,
67 ClassDeclaration: false,
68 ArrowFunctionExpression: false,
69 FunctionExpression: false
71 const options = Object.assign(DEFAULT_OPTIONS, context.options[0] && context.options[0].require);
74 * Report the error message
75 * @param {ASTNode} node node to report
78 function report(node) {
79 context.report({ node, messageId: "missingJSDocComment" });
83 * Check if the jsdoc comment is present or not.
84 * @param {ASTNode} node node to examine
87 function checkJsDoc(node) {
88 const jsdocComment = source.getJSDocComment(node);
96 FunctionDeclaration(node) {
97 if (options.FunctionDeclaration) {
101 FunctionExpression(node) {
103 (options.MethodDefinition && node.parent.type === "MethodDefinition") ||
104 (options.FunctionExpression && (node.parent.type === "VariableDeclarator" || (node.parent.type === "Property" && node === node.parent.value)))
109 ClassDeclaration(node) {
110 if (options.ClassDeclaration) {
114 ArrowFunctionExpression(node) {
115 if (options.ArrowFunctionExpression && node.parent.type === "VariableDeclarator") {