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
59 const source = context.getSourceCode();
60 const DEFAULT_OPTIONS = {
61 FunctionDeclaration: true,
62 MethodDefinition: false,
63 ClassDeclaration: false,
64 ArrowFunctionExpression: false,
65 FunctionExpression: false
67 const options = Object.assign(DEFAULT_OPTIONS, context.options[0] && context.options[0].require);
70 * Report the error message
71 * @param {ASTNode} node node to report
74 function report(node) {
75 context.report({ node, message: "Missing JSDoc comment." });
79 * Check if the jsdoc comment is present or not.
80 * @param {ASTNode} node node to examine
83 function checkJsDoc(node) {
84 const jsdocComment = source.getJSDocComment(node);
92 FunctionDeclaration(node) {
93 if (options.FunctionDeclaration) {
97 FunctionExpression(node) {
99 (options.MethodDefinition && node.parent.type === "MethodDefinition") ||
100 (options.FunctionExpression && (node.parent.type === "VariableDeclarator" || (node.parent.type === "Property" && node === node.parent.value)))
105 ClassDeclaration(node) {
106 if (options.ClassDeclaration) {
110 ArrowFunctionExpression(node) {
111 if (options.ArrowFunctionExpression && node.parent.type === "VariableDeclarator") {