requireJsdoc.js
3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var OPTIONS_SCHEMA = {
additionalProperties: false,
properties: {
require: {
additionalProperties: false,
default: {},
properties: {
ArrowFunctionExpression: {
default: false,
type: 'boolean'
},
ClassDeclaration: {
default: false,
type: 'boolean'
},
FunctionDeclaration: {
default: true,
type: 'boolean'
},
FunctionExpression: {
default: false,
type: 'boolean'
},
MethodDefinition: {
default: false,
type: 'boolean'
}
},
type: 'object'
}
},
type: 'object'
};
var getOption = function getOption(context, key) {
if (!context.options.length) {
return OPTIONS_SCHEMA.properties.require.properties[key].default;
}
if (!context.options[0] || !context.options[0].require) {
return OPTIONS_SCHEMA.properties.require.properties[key].default;
}
if (!context.options[0].require.hasOwnProperty(key)) {
return OPTIONS_SCHEMA.properties.require.properties[key].default;
}
return context.options[0].require[key];
};
var getOptions = function getOptions(context) {
return {
ArrowFunctionExpression: getOption(context, 'ArrowFunctionExpression'),
ClassDeclaration: getOption(context, 'ClassDeclaration'),
FunctionDeclaration: getOption(context, 'FunctionDeclaration'),
FunctionExpression: getOption(context, 'FunctionExpression'),
MethodDefinition: getOption(context, 'MethodDefinition')
};
};
var checkJsDoc = function checkJsDoc(context, node) {
var jsDocNode = context.getSourceCode().getJSDocComment(node);
if (jsDocNode) {
return;
}
context.report({
messageId: 'missingJsDoc',
node
});
};
var _default = {
/**
* The entrypoint for the JSDoc rule.
*
* @param {*} context
* a reference to the context which hold all important information
* like settings and the sourcecode to check.
* @returns {*}
* a list with parser callback function.
*/
create(context) {
var options = getOptions(context);
return {
ArrowFunctionExpression: function ArrowFunctionExpression(node) {
if (!options.ArrowFunctionExpression) {
return;
}
if (node.parent.type !== 'VariableDeclarator') {
return;
}
checkJsDoc(context, node);
},
ClassDeclaration: function ClassDeclaration(node) {
if (!options.ClassDeclaration) {
return;
}
checkJsDoc(context, node);
},
FunctionDeclaration: function FunctionDeclaration(node) {
if (!options.FunctionDeclaration) {
return;
}
checkJsDoc(context, node);
},
FunctionExpression: function FunctionExpression(node) {
if (options.MethodDefinition && node.parent.type === 'MethodDefinition') {
checkJsDoc(context, node);
return;
}
if (!options.FunctionExpression) {
return;
}
if (node.parent.type === 'VariableDeclarator') {
checkJsDoc(context, node);
}
if (node.parent.type === 'Property' && node === node.parent.value) {
checkJsDoc(context, node);
}
}
};
},
meta: {
doc: {
category: 'Stylistic Issues',
description: 'Require JSDoc comments',
recommended: 'true',
url: 'https://github.com/gajus/eslint-plugin-jsdoc'
},
messages: {
missingJsDoc: 'Missing JSDoc comment.'
},
schema: [OPTIONS_SCHEMA],
type: 'suggestion'
}
};
exports.default = _default;
module.exports = exports.default;
//# sourceMappingURL=requireJsdoc.js.map