1 | /**
|
---|
2 | * @fileoverview Rule to check for jsdoc presence.
|
---|
3 | * @author Gyandeep Singh
|
---|
4 | * @deprecated in ESLint v5.10.0
|
---|
5 | */
|
---|
6 | "use strict";
|
---|
7 |
|
---|
8 | /** @type {import('../shared/types').Rule} */
|
---|
9 | module.exports = {
|
---|
10 | meta: {
|
---|
11 | type: "suggestion",
|
---|
12 |
|
---|
13 | docs: {
|
---|
14 | description: "Require JSDoc comments",
|
---|
15 | recommended: false,
|
---|
16 | url: "https://eslint.org/docs/latest/rules/require-jsdoc"
|
---|
17 | },
|
---|
18 |
|
---|
19 | schema: [
|
---|
20 | {
|
---|
21 | type: "object",
|
---|
22 | properties: {
|
---|
23 | require: {
|
---|
24 | type: "object",
|
---|
25 | properties: {
|
---|
26 | ClassDeclaration: {
|
---|
27 | type: "boolean",
|
---|
28 | default: false
|
---|
29 | },
|
---|
30 | MethodDefinition: {
|
---|
31 | type: "boolean",
|
---|
32 | default: false
|
---|
33 | },
|
---|
34 | FunctionDeclaration: {
|
---|
35 | type: "boolean",
|
---|
36 | default: true
|
---|
37 | },
|
---|
38 | ArrowFunctionExpression: {
|
---|
39 | type: "boolean",
|
---|
40 | default: false
|
---|
41 | },
|
---|
42 | FunctionExpression: {
|
---|
43 | type: "boolean",
|
---|
44 | default: false
|
---|
45 | }
|
---|
46 | },
|
---|
47 | additionalProperties: false,
|
---|
48 | default: {}
|
---|
49 | }
|
---|
50 | },
|
---|
51 | additionalProperties: false
|
---|
52 | }
|
---|
53 | ],
|
---|
54 |
|
---|
55 | deprecated: true,
|
---|
56 | replacedBy: [],
|
---|
57 |
|
---|
58 | messages: {
|
---|
59 | missingJSDocComment: "Missing JSDoc comment."
|
---|
60 | }
|
---|
61 | },
|
---|
62 |
|
---|
63 | create(context) {
|
---|
64 | const source = context.sourceCode;
|
---|
65 | const DEFAULT_OPTIONS = {
|
---|
66 | FunctionDeclaration: true,
|
---|
67 | MethodDefinition: false,
|
---|
68 | ClassDeclaration: false,
|
---|
69 | ArrowFunctionExpression: false,
|
---|
70 | FunctionExpression: false
|
---|
71 | };
|
---|
72 | const options = Object.assign(DEFAULT_OPTIONS, context.options[0] && context.options[0].require);
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Report the error message
|
---|
76 | * @param {ASTNode} node node to report
|
---|
77 | * @returns {void}
|
---|
78 | */
|
---|
79 | function report(node) {
|
---|
80 | context.report({ node, messageId: "missingJSDocComment" });
|
---|
81 | }
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Check if the jsdoc comment is present or not.
|
---|
85 | * @param {ASTNode} node node to examine
|
---|
86 | * @returns {void}
|
---|
87 | */
|
---|
88 | function checkJsDoc(node) {
|
---|
89 | const jsdocComment = source.getJSDocComment(node);
|
---|
90 |
|
---|
91 | if (!jsdocComment) {
|
---|
92 | report(node);
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | return {
|
---|
97 | FunctionDeclaration(node) {
|
---|
98 | if (options.FunctionDeclaration) {
|
---|
99 | checkJsDoc(node);
|
---|
100 | }
|
---|
101 | },
|
---|
102 | FunctionExpression(node) {
|
---|
103 | if (
|
---|
104 | (options.MethodDefinition && node.parent.type === "MethodDefinition") ||
|
---|
105 | (options.FunctionExpression && (node.parent.type === "VariableDeclarator" || (node.parent.type === "Property" && node === node.parent.value)))
|
---|
106 | ) {
|
---|
107 | checkJsDoc(node);
|
---|
108 | }
|
---|
109 | },
|
---|
110 | ClassDeclaration(node) {
|
---|
111 | if (options.ClassDeclaration) {
|
---|
112 | checkJsDoc(node);
|
---|
113 | }
|
---|
114 | },
|
---|
115 | ArrowFunctionExpression(node) {
|
---|
116 | if (options.ArrowFunctionExpression && node.parent.type === "VariableDeclarator") {
|
---|
117 | checkJsDoc(node);
|
---|
118 | }
|
---|
119 | }
|
---|
120 | };
|
---|
121 | }
|
---|
122 | };
|
---|