2024-08-09 12:04:48 +00:00
|
|
|
/**
|
|
|
|
* @fileoverview Rule to check for jsdoc presence.
|
|
|
|
* @author Gyandeep Singh
|
2024-08-21 06:34:30 +00:00
|
|
|
* @deprecated in ESLint v5.10.0
|
2024-08-09 12:04:48 +00:00
|
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
|
2024-08-21 06:34:30 +00:00
|
|
|
/** @type {import('../shared/types').Rule} */
|
2024-08-09 12:04:48 +00:00
|
|
|
module.exports = {
|
|
|
|
meta: {
|
|
|
|
type: "suggestion",
|
|
|
|
|
|
|
|
docs: {
|
2024-08-21 06:34:30 +00:00
|
|
|
description: "Require JSDoc comments",
|
2024-08-09 12:04:48 +00:00
|
|
|
recommended: false,
|
2024-08-21 06:34:30 +00:00
|
|
|
url: "https://eslint.org/docs/latest/rules/require-jsdoc"
|
2024-08-09 12:04:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
schema: [
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
require: {
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
ClassDeclaration: {
|
|
|
|
type: "boolean",
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
MethodDefinition: {
|
|
|
|
type: "boolean",
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
FunctionDeclaration: {
|
|
|
|
type: "boolean",
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
ArrowFunctionExpression: {
|
|
|
|
type: "boolean",
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
FunctionExpression: {
|
|
|
|
type: "boolean",
|
|
|
|
default: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
additionalProperties: false,
|
|
|
|
default: {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
additionalProperties: false
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
deprecated: true,
|
|
|
|
replacedBy: [],
|
|
|
|
|
|
|
|
messages: {
|
|
|
|
missingJSDocComment: "Missing JSDoc comment."
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
create(context) {
|
2024-08-21 06:34:30 +00:00
|
|
|
const source = context.sourceCode;
|
2024-08-09 12:04:48 +00:00
|
|
|
const DEFAULT_OPTIONS = {
|
|
|
|
FunctionDeclaration: true,
|
|
|
|
MethodDefinition: false,
|
|
|
|
ClassDeclaration: false,
|
|
|
|
ArrowFunctionExpression: false,
|
|
|
|
FunctionExpression: false
|
|
|
|
};
|
|
|
|
const options = Object.assign(DEFAULT_OPTIONS, context.options[0] && context.options[0].require);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Report the error message
|
|
|
|
* @param {ASTNode} node node to report
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function report(node) {
|
|
|
|
context.report({ node, messageId: "missingJSDocComment" });
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the jsdoc comment is present or not.
|
|
|
|
* @param {ASTNode} node node to examine
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function checkJsDoc(node) {
|
|
|
|
const jsdocComment = source.getJSDocComment(node);
|
|
|
|
|
|
|
|
if (!jsdocComment) {
|
|
|
|
report(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
FunctionDeclaration(node) {
|
|
|
|
if (options.FunctionDeclaration) {
|
|
|
|
checkJsDoc(node);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
FunctionExpression(node) {
|
|
|
|
if (
|
|
|
|
(options.MethodDefinition && node.parent.type === "MethodDefinition") ||
|
|
|
|
(options.FunctionExpression && (node.parent.type === "VariableDeclarator" || (node.parent.type === "Property" && node === node.parent.value)))
|
|
|
|
) {
|
|
|
|
checkJsDoc(node);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ClassDeclaration(node) {
|
|
|
|
if (options.ClassDeclaration) {
|
|
|
|
checkJsDoc(node);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ArrowFunctionExpression(node) {
|
|
|
|
if (options.ArrowFunctionExpression && node.parent.type === "VariableDeclarator") {
|
|
|
|
checkJsDoc(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|