eslint-plugin-jsdoc 55.3.0 → 56.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/WarnSettings.d.ts +16 -0
- package/dist/cjs/WarnSettings.js +30 -0
- package/dist/cjs/alignTransform.d.ts +33 -0
- package/dist/cjs/alignTransform.js +285 -0
- package/dist/cjs/defaultTagOrder.d.ts +4 -0
- package/dist/cjs/defaultTagOrder.js +152 -0
- package/dist/cjs/exportParser.d.ts +40 -0
- package/dist/cjs/exportParser.js +754 -0
- package/dist/cjs/getDefaultTagStructureForMode.d.ts +10 -0
- package/dist/cjs/getDefaultTagStructureForMode.js +840 -0
- package/dist/cjs/getJsdocProcessorPlugin.cjs +4 -0
- package/dist/cjs/getJsdocProcessorPlugin.d.cts +1 -0
- package/dist/cjs/getJsdocProcessorPlugin.d.ts +66 -0
- package/dist/cjs/getJsdocProcessorPlugin.js +553 -0
- package/dist/cjs/index-cjs.d.ts +16 -0
- package/dist/cjs/index-cjs.js +492 -0
- package/dist/cjs/index.cjs.cjs +6 -0
- package/dist/cjs/index.cjs.d.cts +2 -0
- package/dist/cjs/iterateJsdoc.cjs +38 -0
- package/dist/cjs/iterateJsdoc.d.cts +2 -0
- package/dist/cjs/iterateJsdoc.d.ts +462 -0
- package/dist/cjs/iterateJsdoc.js +1981 -0
- package/dist/cjs/jsdocUtils.d.ts +454 -0
- package/dist/cjs/jsdocUtils.js +1470 -0
- package/dist/cjs/rules/checkAccess.d.ts +2 -0
- package/dist/cjs/rules/checkAccess.js +35 -0
- package/dist/cjs/rules/checkAlignment.d.ts +2 -0
- package/dist/cjs/rules/checkAlignment.js +63 -0
- package/dist/cjs/rules/checkExamples.d.ts +3 -0
- package/dist/cjs/rules/checkExamples.js +486 -0
- package/dist/cjs/rules/checkIndentation.d.ts +2 -0
- package/dist/cjs/rules/checkIndentation.js +66 -0
- package/dist/cjs/rules/checkLineAlignment.d.ts +9 -0
- package/dist/cjs/rules/checkLineAlignment.js +297 -0
- package/dist/cjs/rules/checkParamNames.d.ts +2 -0
- package/dist/cjs/rules/checkParamNames.js +320 -0
- package/dist/cjs/rules/checkPropertyNames.d.ts +2 -0
- package/dist/cjs/rules/checkPropertyNames.js +105 -0
- package/dist/cjs/rules/checkSyntax.d.ts +2 -0
- package/dist/cjs/rules/checkSyntax.js +27 -0
- package/dist/cjs/rules/checkTagNames.d.ts +2 -0
- package/dist/cjs/rules/checkTagNames.js +252 -0
- package/dist/cjs/rules/checkTemplateNames.d.ts +2 -0
- package/dist/cjs/rules/checkTemplateNames.js +189 -0
- package/dist/cjs/rules/checkTypes.d.ts +2 -0
- package/dist/cjs/rules/checkTypes.js +421 -0
- package/dist/cjs/rules/checkValues.d.ts +2 -0
- package/dist/cjs/rules/checkValues.js +163 -0
- package/dist/cjs/rules/convertToJsdocComments.d.ts +251 -0
- package/dist/cjs/rules/convertToJsdocComments.js +313 -0
- package/dist/cjs/rules/emptyTags.d.ts +2 -0
- package/dist/cjs/rules/emptyTags.js +79 -0
- package/dist/cjs/rules/implementsOnClasses.d.ts +2 -0
- package/dist/cjs/rules/implementsOnClasses.js +63 -0
- package/dist/cjs/rules/importsAsDependencies.d.ts +2 -0
- package/dist/cjs/rules/importsAsDependencies.js +105 -0
- package/dist/cjs/rules/informativeDocs.d.ts +2 -0
- package/dist/cjs/rules/informativeDocs.js +153 -0
- package/dist/cjs/rules/linesBeforeBlock.d.ts +2 -0
- package/dist/cjs/rules/linesBeforeBlock.js +106 -0
- package/dist/cjs/rules/matchDescription.d.ts +2 -0
- package/dist/cjs/rules/matchDescription.js +240 -0
- package/dist/cjs/rules/matchName.d.ts +2 -0
- package/dist/cjs/rules/matchName.js +122 -0
- package/dist/cjs/rules/multilineBlocks.d.ts +2 -0
- package/dist/cjs/rules/multilineBlocks.js +339 -0
- package/dist/cjs/rules/noBadBlocks.d.ts +2 -0
- package/dist/cjs/rules/noBadBlocks.js +88 -0
- package/dist/cjs/rules/noBlankBlockDescriptions.d.ts +2 -0
- package/dist/cjs/rules/noBlankBlockDescriptions.js +56 -0
- package/dist/cjs/rules/noBlankBlocks.d.ts +2 -0
- package/dist/cjs/rules/noBlankBlocks.js +41 -0
- package/dist/cjs/rules/noDefaults.d.ts +2 -0
- package/dist/cjs/rules/noDefaults.js +84 -0
- package/dist/cjs/rules/noMissingSyntax.d.ts +9 -0
- package/dist/cjs/rules/noMissingSyntax.js +164 -0
- package/dist/cjs/rules/noMultiAsterisks.d.ts +2 -0
- package/dist/cjs/rules/noMultiAsterisks.js +83 -0
- package/dist/cjs/rules/noRestrictedSyntax.d.ts +2 -0
- package/dist/cjs/rules/noRestrictedSyntax.js +75 -0
- package/dist/cjs/rules/noTypes.d.ts +2 -0
- package/dist/cjs/rules/noTypes.js +88 -0
- package/dist/cjs/rules/noUndefinedTypes.d.ts +2 -0
- package/dist/cjs/rules/noUndefinedTypes.js +451 -0
- package/dist/cjs/rules/requireAsteriskPrefix.d.ts +2 -0
- package/dist/cjs/rules/requireAsteriskPrefix.js +144 -0
- package/dist/cjs/rules/requireDescription.d.ts +2 -0
- package/dist/cjs/rules/requireDescription.js +136 -0
- package/dist/cjs/rules/requireDescriptionCompleteSentence.d.ts +2 -0
- package/dist/cjs/rules/requireDescriptionCompleteSentence.js +258 -0
- package/dist/cjs/rules/requireExample.d.ts +2 -0
- package/dist/cjs/rules/requireExample.js +103 -0
- package/dist/cjs/rules/requireFileOverview.d.ts +2 -0
- package/dist/cjs/rules/requireFileOverview.js +117 -0
- package/dist/cjs/rules/requireHyphenBeforeParamDescription.d.ts +2 -0
- package/dist/cjs/rules/requireHyphenBeforeParamDescription.js +144 -0
- package/dist/cjs/rules/requireJsdoc.d.ts +25 -0
- package/dist/cjs/rules/requireJsdoc.js +629 -0
- package/dist/cjs/rules/requireParam.d.ts +3 -0
- package/dist/cjs/rules/requireParam.js +480 -0
- package/dist/cjs/rules/requireParamDescription.d.ts +2 -0
- package/dist/cjs/rules/requireParamDescription.js +77 -0
- package/dist/cjs/rules/requireParamName.d.ts +2 -0
- package/dist/cjs/rules/requireParamName.js +52 -0
- package/dist/cjs/rules/requireParamType.d.ts +2 -0
- package/dist/cjs/rules/requireParamType.js +77 -0
- package/dist/cjs/rules/requireProperty.d.ts +2 -0
- package/dist/cjs/rules/requireProperty.js +44 -0
- package/dist/cjs/rules/requirePropertyDescription.d.ts +2 -0
- package/dist/cjs/rules/requirePropertyDescription.js +22 -0
- package/dist/cjs/rules/requirePropertyName.d.ts +2 -0
- package/dist/cjs/rules/requirePropertyName.js +22 -0
- package/dist/cjs/rules/requirePropertyType.d.ts +2 -0
- package/dist/cjs/rules/requirePropertyType.js +22 -0
- package/dist/cjs/rules/requireReturns.d.ts +2 -0
- package/dist/cjs/rules/requireReturns.js +197 -0
- package/dist/cjs/rules/requireReturnsCheck.d.ts +2 -0
- package/dist/cjs/rules/requireReturnsCheck.js +108 -0
- package/dist/cjs/rules/requireReturnsDescription.d.ts +2 -0
- package/dist/cjs/rules/requireReturnsDescription.js +58 -0
- package/dist/cjs/rules/requireReturnsType.d.ts +2 -0
- package/dist/cjs/rules/requireReturnsType.js +52 -0
- package/dist/cjs/rules/requireTemplate.d.ts +2 -0
- package/dist/cjs/rules/requireTemplate.js +173 -0
- package/dist/cjs/rules/requireThrows.d.ts +2 -0
- package/dist/cjs/rules/requireThrows.js +101 -0
- package/dist/cjs/rules/requireYields.d.ts +2 -0
- package/dist/cjs/rules/requireYields.js +172 -0
- package/dist/cjs/rules/requireYieldsCheck.d.ts +2 -0
- package/dist/cjs/rules/requireYieldsCheck.js +164 -0
- package/dist/cjs/rules/sortTags.d.ts +2 -0
- package/dist/cjs/rules/sortTags.js +392 -0
- package/dist/cjs/rules/tagLines.d.ts +2 -0
- package/dist/cjs/rules/tagLines.js +259 -0
- package/dist/cjs/rules/textEscaping.d.ts +2 -0
- package/dist/cjs/rules/textEscaping.js +125 -0
- package/dist/cjs/rules/typeFormatting.d.ts +2 -0
- package/dist/cjs/rules/typeFormatting.js +328 -0
- package/dist/cjs/rules/validTypes.d.ts +2 -0
- package/dist/cjs/rules/validTypes.js +333 -0
- package/dist/cjs/tagNames.d.ts +15 -0
- package/dist/cjs/tagNames.js +209 -0
- package/dist/cjs/utils/hasReturnValue.d.ts +19 -0
- package/dist/cjs/utils/hasReturnValue.js +469 -0
- package/dist/getJsdocProcessorPlugin.cts +3 -0
- package/dist/index.cjs.cts +3 -0
- package/dist/iterateJsdoc.cts +6 -0
- package/dist/rules/typeFormatting.cjs +82 -38
- package/dist/rules/typeFormatting.cjs.map +1 -1
- package/dist/rules.d.ts +4 -7
- package/package.json +24 -13
- package/src/getJsdocProcessorPlugin.cts +3 -0
- package/src/index.cjs.cts +3 -0
- package/src/iterateJsdoc.cts +6 -0
- package/src/rules/typeFormatting.js +104 -40
- package/src/rules.d.ts +4 -7
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const exportParser_js_1 = __importDefault(require("../exportParser.js"));
|
|
7
|
+
const iterateJsdoc_js_1 = require("../iterateJsdoc.js");
|
|
8
|
+
const jsdocUtils_js_1 = require("../jsdocUtils.js");
|
|
9
|
+
const jsdoccomment_1 = require("@es-joy/jsdoccomment");
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {{
|
|
12
|
+
* ancestorsOnly: boolean,
|
|
13
|
+
* esm: boolean,
|
|
14
|
+
* initModuleExports: boolean,
|
|
15
|
+
* initWindow: boolean
|
|
16
|
+
* }} RequireJsdocOpts
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {import('eslint').Rule.Node|
|
|
20
|
+
* import('@typescript-eslint/types').TSESTree.Node} ESLintOrTSNode
|
|
21
|
+
*/
|
|
22
|
+
/** @type {import('json-schema').JSONSchema4} */
|
|
23
|
+
const OPTIONS_SCHEMA = {
|
|
24
|
+
additionalProperties: false,
|
|
25
|
+
properties: {
|
|
26
|
+
checkConstructors: {
|
|
27
|
+
default: true,
|
|
28
|
+
type: 'boolean',
|
|
29
|
+
},
|
|
30
|
+
checkGetters: {
|
|
31
|
+
anyOf: [
|
|
32
|
+
{
|
|
33
|
+
type: 'boolean',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
enum: [
|
|
37
|
+
'no-setter',
|
|
38
|
+
],
|
|
39
|
+
type: 'string',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
default: true,
|
|
43
|
+
},
|
|
44
|
+
checkSetters: {
|
|
45
|
+
anyOf: [
|
|
46
|
+
{
|
|
47
|
+
type: 'boolean',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
enum: [
|
|
51
|
+
'no-getter',
|
|
52
|
+
],
|
|
53
|
+
type: 'string',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
default: true,
|
|
57
|
+
},
|
|
58
|
+
contexts: {
|
|
59
|
+
items: {
|
|
60
|
+
anyOf: [
|
|
61
|
+
{
|
|
62
|
+
type: 'string',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
additionalProperties: false,
|
|
66
|
+
properties: {
|
|
67
|
+
context: {
|
|
68
|
+
type: 'string',
|
|
69
|
+
},
|
|
70
|
+
inlineCommentBlock: {
|
|
71
|
+
type: 'boolean',
|
|
72
|
+
},
|
|
73
|
+
minLineCount: {
|
|
74
|
+
type: 'integer',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
type: 'object',
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
type: 'array',
|
|
82
|
+
},
|
|
83
|
+
enableFixer: {
|
|
84
|
+
default: true,
|
|
85
|
+
type: 'boolean',
|
|
86
|
+
},
|
|
87
|
+
exemptEmptyConstructors: {
|
|
88
|
+
default: false,
|
|
89
|
+
type: 'boolean',
|
|
90
|
+
},
|
|
91
|
+
exemptEmptyFunctions: {
|
|
92
|
+
default: false,
|
|
93
|
+
type: 'boolean',
|
|
94
|
+
},
|
|
95
|
+
exemptOverloadedImplementations: {
|
|
96
|
+
default: false,
|
|
97
|
+
type: 'boolean',
|
|
98
|
+
},
|
|
99
|
+
fixerMessage: {
|
|
100
|
+
default: '',
|
|
101
|
+
type: 'string',
|
|
102
|
+
},
|
|
103
|
+
minLineCount: {
|
|
104
|
+
type: 'integer',
|
|
105
|
+
},
|
|
106
|
+
publicOnly: {
|
|
107
|
+
oneOf: [
|
|
108
|
+
{
|
|
109
|
+
default: false,
|
|
110
|
+
type: 'boolean',
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
additionalProperties: false,
|
|
114
|
+
default: {},
|
|
115
|
+
properties: {
|
|
116
|
+
ancestorsOnly: {
|
|
117
|
+
type: 'boolean',
|
|
118
|
+
},
|
|
119
|
+
cjs: {
|
|
120
|
+
type: 'boolean',
|
|
121
|
+
},
|
|
122
|
+
esm: {
|
|
123
|
+
type: 'boolean',
|
|
124
|
+
},
|
|
125
|
+
window: {
|
|
126
|
+
type: 'boolean',
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
type: 'object',
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
require: {
|
|
134
|
+
additionalProperties: false,
|
|
135
|
+
default: {},
|
|
136
|
+
properties: {
|
|
137
|
+
ArrowFunctionExpression: {
|
|
138
|
+
default: false,
|
|
139
|
+
type: 'boolean',
|
|
140
|
+
},
|
|
141
|
+
ClassDeclaration: {
|
|
142
|
+
default: false,
|
|
143
|
+
type: 'boolean',
|
|
144
|
+
},
|
|
145
|
+
ClassExpression: {
|
|
146
|
+
default: false,
|
|
147
|
+
type: 'boolean',
|
|
148
|
+
},
|
|
149
|
+
FunctionDeclaration: {
|
|
150
|
+
default: true,
|
|
151
|
+
type: 'boolean',
|
|
152
|
+
},
|
|
153
|
+
FunctionExpression: {
|
|
154
|
+
default: false,
|
|
155
|
+
type: 'boolean',
|
|
156
|
+
},
|
|
157
|
+
MethodDefinition: {
|
|
158
|
+
default: false,
|
|
159
|
+
type: 'boolean',
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
type: 'object',
|
|
163
|
+
},
|
|
164
|
+
skipInterveningOverloadedDeclarations: {
|
|
165
|
+
default: true,
|
|
166
|
+
type: 'boolean',
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
type: 'object',
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* @param {string} interfaceName
|
|
173
|
+
* @param {string} methodName
|
|
174
|
+
* @param {import("eslint").Scope.Scope | null} scope
|
|
175
|
+
* @returns {import('@typescript-eslint/types').TSESTree.TSMethodSignature|null}
|
|
176
|
+
*/
|
|
177
|
+
const getMethodOnInterface = (interfaceName, methodName, scope) => {
|
|
178
|
+
let scp = scope;
|
|
179
|
+
while (scp) {
|
|
180
|
+
for (const { identifiers, name, } of scp.variables) {
|
|
181
|
+
if (interfaceName !== name) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
for (const identifier of identifiers) {
|
|
185
|
+
const interfaceDeclaration = /** @type {import('@typescript-eslint/types').TSESTree.Identifier & {parent: import('@typescript-eslint/types').TSESTree.TSInterfaceDeclaration}} */ (identifier).parent;
|
|
186
|
+
/* c8 ignore next 3 -- TS */
|
|
187
|
+
if (interfaceDeclaration.type !== 'TSInterfaceDeclaration') {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
for (const bodyItem of interfaceDeclaration.body.body) {
|
|
191
|
+
const methodSig = /** @type {import('@typescript-eslint/types').TSESTree.TSMethodSignature} */ (bodyItem);
|
|
192
|
+
if (methodName === /** @type {import('@typescript-eslint/types').TSESTree.Identifier} */ (methodSig.key).name) {
|
|
193
|
+
return methodSig;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
scp = scp.upper;
|
|
199
|
+
}
|
|
200
|
+
return null;
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* @param {import('eslint').Rule.Node} node
|
|
204
|
+
* @param {import('eslint').SourceCode} sourceCode
|
|
205
|
+
* @param {import('eslint').Rule.RuleContext} context
|
|
206
|
+
* @param {import('../iterateJsdoc.js').Settings} settings
|
|
207
|
+
*/
|
|
208
|
+
const isExemptedImplementer = (node, sourceCode, context, settings) => {
|
|
209
|
+
if (node.type === 'FunctionExpression' &&
|
|
210
|
+
node.parent.type === 'MethodDefinition' &&
|
|
211
|
+
node.parent.parent.type === 'ClassBody' &&
|
|
212
|
+
node.parent.parent.parent.type === 'ClassDeclaration' &&
|
|
213
|
+
'implements' in node.parent.parent.parent) {
|
|
214
|
+
const implments = /** @type {import('@typescript-eslint/types').TSESTree.TSClassImplements[]} */ (node.parent.parent.parent.implements);
|
|
215
|
+
const { name: methodName, } = /** @type {import('@typescript-eslint/types').TSESTree.Identifier} */ (node.parent.key);
|
|
216
|
+
for (const impl of implments) {
|
|
217
|
+
const { name: interfaceName, } = /** @type {import('@typescript-eslint/types').TSESTree.Identifier} */ (impl.expression);
|
|
218
|
+
const interfaceMethodNode = getMethodOnInterface(interfaceName, methodName, node && ((sourceCode.getScope &&
|
|
219
|
+
/* c8 ignore next 3 */
|
|
220
|
+
sourceCode.getScope(node)) ||
|
|
221
|
+
// @ts-expect-error ESLint 8
|
|
222
|
+
context.getScope()));
|
|
223
|
+
if (interfaceMethodNode) {
|
|
224
|
+
// @ts-expect-error Ok
|
|
225
|
+
const comment = (0, jsdoccomment_1.getJSDocComment)(sourceCode, interfaceMethodNode, settings);
|
|
226
|
+
if (comment) {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return false;
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* @param {import('eslint').Rule.RuleContext} context
|
|
236
|
+
* @param {import('json-schema').JSONSchema4Object} baseObject
|
|
237
|
+
* @param {string} option
|
|
238
|
+
* @param {string} key
|
|
239
|
+
* @returns {boolean|undefined}
|
|
240
|
+
*/
|
|
241
|
+
const getOption = (context, baseObject, option, key) => {
|
|
242
|
+
if (context.options[0] && option in context.options[0] &&
|
|
243
|
+
// Todo: boolean shouldn't be returning property, but
|
|
244
|
+
// tests currently require
|
|
245
|
+
(typeof context.options[0][option] === 'boolean' ||
|
|
246
|
+
key in context.options[0][option])) {
|
|
247
|
+
return context.options[0][option][key];
|
|
248
|
+
}
|
|
249
|
+
return /** @type {{[key: string]: {default?: boolean|undefined}}} */ (baseObject.properties)[key].default;
|
|
250
|
+
};
|
|
251
|
+
/**
|
|
252
|
+
* @param {import('eslint').Rule.RuleContext} context
|
|
253
|
+
* @param {import('../iterateJsdoc.js').Settings} settings
|
|
254
|
+
* @returns {{
|
|
255
|
+
* contexts: (string|{
|
|
256
|
+
* context: string,
|
|
257
|
+
* inlineCommentBlock: boolean,
|
|
258
|
+
* minLineCount: import('../iterateJsdoc.js').Integer
|
|
259
|
+
* })[],
|
|
260
|
+
* enableFixer: boolean,
|
|
261
|
+
* exemptEmptyConstructors: boolean,
|
|
262
|
+
* exemptEmptyFunctions: boolean,
|
|
263
|
+
* skipInterveningOverloadedDeclarations: boolean,
|
|
264
|
+
* exemptOverloadedImplementations: boolean,
|
|
265
|
+
* fixerMessage: string,
|
|
266
|
+
* minLineCount: undefined|import('../iterateJsdoc.js').Integer,
|
|
267
|
+
* publicOnly: boolean|{[key: string]: boolean|undefined}
|
|
268
|
+
* require: {[key: string]: boolean|undefined}
|
|
269
|
+
* }}
|
|
270
|
+
*/
|
|
271
|
+
const getOptions = (context, settings) => {
|
|
272
|
+
const { contexts = settings.contexts || [], enableFixer = true, exemptEmptyConstructors = true, exemptEmptyFunctions = false, exemptOverloadedImplementations = false, fixerMessage = '', minLineCount = undefined, publicOnly, skipInterveningOverloadedDeclarations = true, } = context.options[0] || {};
|
|
273
|
+
return {
|
|
274
|
+
contexts,
|
|
275
|
+
enableFixer,
|
|
276
|
+
exemptEmptyConstructors,
|
|
277
|
+
exemptEmptyFunctions,
|
|
278
|
+
exemptOverloadedImplementations,
|
|
279
|
+
fixerMessage,
|
|
280
|
+
minLineCount,
|
|
281
|
+
publicOnly: ((baseObj) => {
|
|
282
|
+
if (!publicOnly) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
/** @type {{[key: string]: boolean|undefined}} */
|
|
286
|
+
const properties = {};
|
|
287
|
+
for (const prop of Object.keys(
|
|
288
|
+
/** @type {import('json-schema').JSONSchema4Object} */ (
|
|
289
|
+
/** @type {import('json-schema').JSONSchema4Object} */ (baseObj).properties))) {
|
|
290
|
+
const opt = getOption(context,
|
|
291
|
+
/** @type {import('json-schema').JSONSchema4Object} */ (baseObj), 'publicOnly', prop);
|
|
292
|
+
properties[prop] = opt;
|
|
293
|
+
}
|
|
294
|
+
return properties;
|
|
295
|
+
})(
|
|
296
|
+
/** @type {import('json-schema').JSONSchema4Object} */
|
|
297
|
+
(
|
|
298
|
+
/** @type {import('json-schema').JSONSchema4Object} */
|
|
299
|
+
(
|
|
300
|
+
/** @type {import('json-schema').JSONSchema4Object} */
|
|
301
|
+
(OPTIONS_SCHEMA.properties).publicOnly).oneOf)[1]),
|
|
302
|
+
require: ((baseObj) => {
|
|
303
|
+
/** @type {{[key: string]: boolean|undefined}} */
|
|
304
|
+
const properties = {};
|
|
305
|
+
for (const prop of Object.keys(
|
|
306
|
+
/** @type {import('json-schema').JSONSchema4Object} */ (
|
|
307
|
+
/** @type {import('json-schema').JSONSchema4Object} */ (baseObj).properties))) {
|
|
308
|
+
const opt = getOption(context,
|
|
309
|
+
/** @type {import('json-schema').JSONSchema4Object} */
|
|
310
|
+
(baseObj), 'require', prop);
|
|
311
|
+
properties[prop] = opt;
|
|
312
|
+
}
|
|
313
|
+
return properties;
|
|
314
|
+
})(
|
|
315
|
+
/** @type {import('json-schema').JSONSchema4Object} */
|
|
316
|
+
(OPTIONS_SCHEMA.properties).require),
|
|
317
|
+
skipInterveningOverloadedDeclarations,
|
|
318
|
+
};
|
|
319
|
+
};
|
|
320
|
+
/**
|
|
321
|
+
* @param {ESLintOrTSNode} node
|
|
322
|
+
*/
|
|
323
|
+
const isFunctionWithOverload = (node) => {
|
|
324
|
+
if (node.type !== 'FunctionDeclaration') {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
let parent;
|
|
328
|
+
let child;
|
|
329
|
+
if (node.parent?.type === 'Program') {
|
|
330
|
+
parent = node.parent;
|
|
331
|
+
child = node;
|
|
332
|
+
}
|
|
333
|
+
else if (node.parent?.type === 'ExportNamedDeclaration' &&
|
|
334
|
+
node.parent?.parent.type === 'Program') {
|
|
335
|
+
parent = node.parent?.parent;
|
|
336
|
+
child = node.parent;
|
|
337
|
+
}
|
|
338
|
+
if (!child || !parent) {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
const functionName = node.id.name;
|
|
342
|
+
const idx = parent.body.indexOf(child);
|
|
343
|
+
const prevSibling = parent.body[idx - 1];
|
|
344
|
+
return (
|
|
345
|
+
// @ts-expect-error Should be ok
|
|
346
|
+
(prevSibling?.type === 'TSDeclareFunction' &&
|
|
347
|
+
// @ts-expect-error Should be ok
|
|
348
|
+
functionName === prevSibling.id.name) ||
|
|
349
|
+
(prevSibling?.type === 'ExportNamedDeclaration' &&
|
|
350
|
+
// @ts-expect-error Should be ok
|
|
351
|
+
prevSibling.declaration?.type === 'TSDeclareFunction' &&
|
|
352
|
+
// @ts-expect-error Should be ok
|
|
353
|
+
prevSibling.declaration?.id?.name === functionName));
|
|
354
|
+
};
|
|
355
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
356
|
+
exports.default = {
|
|
357
|
+
create(context) {
|
|
358
|
+
/* c8 ignore next -- Fallback to deprecated method */
|
|
359
|
+
const { sourceCode = context.getSourceCode(), } = context;
|
|
360
|
+
const settings = (0, iterateJsdoc_js_1.getSettings)(context);
|
|
361
|
+
if (!settings) {
|
|
362
|
+
return {};
|
|
363
|
+
}
|
|
364
|
+
const opts = getOptions(context, settings);
|
|
365
|
+
const { contexts, enableFixer, exemptEmptyConstructors, exemptEmptyFunctions, exemptOverloadedImplementations, fixerMessage, minLineCount, require: requireOption, skipInterveningOverloadedDeclarations, } = opts;
|
|
366
|
+
const publicOnly =
|
|
367
|
+
/**
|
|
368
|
+
* @type {{
|
|
369
|
+
* [key: string]: boolean | undefined;
|
|
370
|
+
* }}
|
|
371
|
+
*/ (opts.publicOnly);
|
|
372
|
+
/**
|
|
373
|
+
* @type {import('../iterateJsdoc.js').CheckJsdoc}
|
|
374
|
+
*/
|
|
375
|
+
const checkJsDoc = (info, _handler, node) => {
|
|
376
|
+
if (
|
|
377
|
+
// Optimize
|
|
378
|
+
minLineCount !== undefined || contexts.some((ctxt) => {
|
|
379
|
+
if (typeof ctxt === 'string') {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
const { minLineCount: count, } = ctxt;
|
|
383
|
+
return count !== undefined;
|
|
384
|
+
})) {
|
|
385
|
+
/**
|
|
386
|
+
* @param {undefined|import('../iterateJsdoc.js').Integer} count
|
|
387
|
+
*/
|
|
388
|
+
const underMinLine = (count) => {
|
|
389
|
+
return count !== undefined && count >
|
|
390
|
+
(sourceCode.getText(node).match(/\n/gv)?.length ?? 0) + 1;
|
|
391
|
+
};
|
|
392
|
+
if (underMinLine(minLineCount)) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
const { minLineCount: contextMinLineCount, } =
|
|
396
|
+
/**
|
|
397
|
+
* @type {{
|
|
398
|
+
* context: string;
|
|
399
|
+
* inlineCommentBlock: boolean;
|
|
400
|
+
* minLineCount: number;
|
|
401
|
+
* }}
|
|
402
|
+
*/ (contexts.find((ctxt) => {
|
|
403
|
+
if (typeof ctxt === 'string') {
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
const { context: ctx, } = ctxt;
|
|
407
|
+
return ctx === (info.selector || node.type);
|
|
408
|
+
})) || {};
|
|
409
|
+
if (underMinLine(contextMinLineCount)) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
if (exemptOverloadedImplementations && isFunctionWithOverload(node)) {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
const jsDocNode = (0, jsdoccomment_1.getJSDocComment)(sourceCode, node, settings, {
|
|
417
|
+
checkOverloads: skipInterveningOverloadedDeclarations,
|
|
418
|
+
});
|
|
419
|
+
if (jsDocNode) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
// For those who have options configured against ANY constructors (or
|
|
423
|
+
// setters or getters) being reported
|
|
424
|
+
if ((0, jsdocUtils_js_1.exemptSpeciaMethods)({
|
|
425
|
+
description: '',
|
|
426
|
+
inlineTags: [],
|
|
427
|
+
problems: [],
|
|
428
|
+
source: [],
|
|
429
|
+
tags: [],
|
|
430
|
+
}, node, context, [
|
|
431
|
+
OPTIONS_SCHEMA,
|
|
432
|
+
])) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
if (
|
|
436
|
+
// Avoid reporting param-less, return-less functions (when
|
|
437
|
+
// `exemptEmptyFunctions` option is set)
|
|
438
|
+
exemptEmptyFunctions && info.isFunctionContext ||
|
|
439
|
+
// Avoid reporting param-less, return-less constructor methods (when
|
|
440
|
+
// `exemptEmptyConstructors` option is set)
|
|
441
|
+
exemptEmptyConstructors && (0, jsdocUtils_js_1.isConstructor)(node)) {
|
|
442
|
+
const functionParameterNames = (0, jsdocUtils_js_1.getFunctionParameterNames)(node);
|
|
443
|
+
if (!functionParameterNames.length && !(0, jsdocUtils_js_1.hasReturnValue)(node)) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
if (isExemptedImplementer(node, sourceCode, context, settings)) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
const fix = /** @type {import('eslint').Rule.ReportFixer} */ (fixer) => {
|
|
451
|
+
// Default to one line break if the `minLines`/`maxLines` settings allow
|
|
452
|
+
const lines = settings.minLines === 0 && settings.maxLines >= 1 ? 1 : settings.minLines;
|
|
453
|
+
/** @type {ESLintOrTSNode|import('@typescript-eslint/types').TSESTree.Decorator} */
|
|
454
|
+
let baseNode = (0, jsdoccomment_1.getReducedASTNode)(node, sourceCode);
|
|
455
|
+
const decorator = (0, jsdoccomment_1.getDecorator)(
|
|
456
|
+
/** @type {import('eslint').Rule.Node} */
|
|
457
|
+
(baseNode));
|
|
458
|
+
if (decorator) {
|
|
459
|
+
baseNode = decorator;
|
|
460
|
+
}
|
|
461
|
+
const indent = (0, jsdocUtils_js_1.getIndent)({
|
|
462
|
+
text: sourceCode.getText(
|
|
463
|
+
/** @type {import('eslint').Rule.Node} */ (baseNode),
|
|
464
|
+
/** @type {import('eslint').AST.SourceLocation} */
|
|
465
|
+
(
|
|
466
|
+
/** @type {import('eslint').Rule.Node} */ (baseNode).loc).start.column),
|
|
467
|
+
});
|
|
468
|
+
const { inlineCommentBlock, } =
|
|
469
|
+
/**
|
|
470
|
+
* @type {{
|
|
471
|
+
* context: string,
|
|
472
|
+
* inlineCommentBlock: boolean,
|
|
473
|
+
* minLineCount: import('../iterateJsdoc.js').Integer
|
|
474
|
+
* }}
|
|
475
|
+
*/ (contexts.find((contxt) => {
|
|
476
|
+
if (typeof contxt === 'string') {
|
|
477
|
+
return false;
|
|
478
|
+
}
|
|
479
|
+
const { context: ctxt, } = contxt;
|
|
480
|
+
return ctxt === node.type;
|
|
481
|
+
})) || {};
|
|
482
|
+
const insertion = (inlineCommentBlock ?
|
|
483
|
+
`/** ${fixerMessage}` :
|
|
484
|
+
`/**\n${indent}*${fixerMessage}\n${indent}`) +
|
|
485
|
+
`*/${'\n'.repeat(lines)}${indent.slice(0, -1)}`;
|
|
486
|
+
return fixer.insertTextBefore(
|
|
487
|
+
/** @type {import('eslint').Rule.Node} */
|
|
488
|
+
(baseNode), insertion);
|
|
489
|
+
};
|
|
490
|
+
const report = () => {
|
|
491
|
+
const { start, } = /** @type {import('eslint').AST.SourceLocation} */ (node.loc);
|
|
492
|
+
const loc = {
|
|
493
|
+
end: {
|
|
494
|
+
column: 0,
|
|
495
|
+
line: start.line + 1,
|
|
496
|
+
},
|
|
497
|
+
start,
|
|
498
|
+
};
|
|
499
|
+
context.report({
|
|
500
|
+
fix: enableFixer ? fix : null,
|
|
501
|
+
loc,
|
|
502
|
+
messageId: 'missingJsDoc',
|
|
503
|
+
node,
|
|
504
|
+
});
|
|
505
|
+
};
|
|
506
|
+
if (publicOnly) {
|
|
507
|
+
/** @type {RequireJsdocOpts} */
|
|
508
|
+
const opt = {
|
|
509
|
+
ancestorsOnly: Boolean(publicOnly?.ancestorsOnly ?? false),
|
|
510
|
+
esm: Boolean(publicOnly?.esm ?? true),
|
|
511
|
+
initModuleExports: Boolean(publicOnly?.cjs ?? true),
|
|
512
|
+
initWindow: Boolean(publicOnly?.window ?? false),
|
|
513
|
+
};
|
|
514
|
+
const exported = exportParser_js_1.default.isUncommentedExport(node, sourceCode, opt, settings);
|
|
515
|
+
if (exported) {
|
|
516
|
+
report();
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
report();
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
/**
|
|
524
|
+
* @param {string} prop
|
|
525
|
+
* @returns {boolean}
|
|
526
|
+
*/
|
|
527
|
+
const hasOption = (prop) => {
|
|
528
|
+
return requireOption[prop] || contexts.some((ctxt) => {
|
|
529
|
+
return typeof ctxt === 'object' ? ctxt.context === prop : ctxt === prop;
|
|
530
|
+
});
|
|
531
|
+
};
|
|
532
|
+
return {
|
|
533
|
+
...(0, jsdocUtils_js_1.getContextObject)((0, jsdocUtils_js_1.enforcedContexts)(context, [], settings), checkJsDoc),
|
|
534
|
+
ArrowFunctionExpression(node) {
|
|
535
|
+
if (!hasOption('ArrowFunctionExpression')) {
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
if ([
|
|
539
|
+
'AssignmentExpression', 'ExportDefaultDeclaration', 'VariableDeclarator',
|
|
540
|
+
].includes(node.parent.type) ||
|
|
541
|
+
[
|
|
542
|
+
'ClassProperty', 'ObjectProperty', 'Property', 'PropertyDefinition',
|
|
543
|
+
].includes(node.parent.type) &&
|
|
544
|
+
node ===
|
|
545
|
+
/**
|
|
546
|
+
* @type {import('@typescript-eslint/types').TSESTree.Property|
|
|
547
|
+
* import('@typescript-eslint/types').TSESTree.PropertyDefinition
|
|
548
|
+
* }
|
|
549
|
+
*/
|
|
550
|
+
(node.parent).value) {
|
|
551
|
+
checkJsDoc({
|
|
552
|
+
isFunctionContext: true,
|
|
553
|
+
}, null, node);
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
ClassDeclaration(node) {
|
|
557
|
+
if (!hasOption('ClassDeclaration')) {
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
checkJsDoc({
|
|
561
|
+
isFunctionContext: false,
|
|
562
|
+
}, null, node);
|
|
563
|
+
},
|
|
564
|
+
ClassExpression(node) {
|
|
565
|
+
if (!hasOption('ClassExpression')) {
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
checkJsDoc({
|
|
569
|
+
isFunctionContext: false,
|
|
570
|
+
}, null, node);
|
|
571
|
+
},
|
|
572
|
+
FunctionDeclaration(node) {
|
|
573
|
+
if (!hasOption('FunctionDeclaration')) {
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
checkJsDoc({
|
|
577
|
+
isFunctionContext: true,
|
|
578
|
+
}, null, node);
|
|
579
|
+
},
|
|
580
|
+
FunctionExpression(node) {
|
|
581
|
+
if (!hasOption('FunctionExpression')) {
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
if ([
|
|
585
|
+
'AssignmentExpression', 'ExportDefaultDeclaration', 'VariableDeclarator',
|
|
586
|
+
].includes(node.parent.type) ||
|
|
587
|
+
[
|
|
588
|
+
'ClassProperty', 'ObjectProperty', 'Property', 'PropertyDefinition',
|
|
589
|
+
].includes(node.parent.type) &&
|
|
590
|
+
node ===
|
|
591
|
+
/**
|
|
592
|
+
* @type {import('@typescript-eslint/types').TSESTree.Property|
|
|
593
|
+
* import('@typescript-eslint/types').TSESTree.PropertyDefinition
|
|
594
|
+
* }
|
|
595
|
+
*/
|
|
596
|
+
(node.parent).value) {
|
|
597
|
+
checkJsDoc({
|
|
598
|
+
isFunctionContext: true,
|
|
599
|
+
}, null, node);
|
|
600
|
+
}
|
|
601
|
+
},
|
|
602
|
+
MethodDefinition(node) {
|
|
603
|
+
if (!hasOption('MethodDefinition')) {
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
checkJsDoc({
|
|
607
|
+
isFunctionContext: true,
|
|
608
|
+
selector: 'MethodDefinition',
|
|
609
|
+
}, null, /** @type {import('eslint').Rule.Node} */ (node.value));
|
|
610
|
+
},
|
|
611
|
+
};
|
|
612
|
+
},
|
|
613
|
+
meta: {
|
|
614
|
+
docs: {
|
|
615
|
+
category: 'Stylistic Issues',
|
|
616
|
+
description: 'Require JSDoc comments',
|
|
617
|
+
recommended: true,
|
|
618
|
+
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-jsdoc.md#repos-sticky-header',
|
|
619
|
+
},
|
|
620
|
+
fixable: 'code',
|
|
621
|
+
messages: {
|
|
622
|
+
missingJsDoc: 'Missing JSDoc comment.',
|
|
623
|
+
},
|
|
624
|
+
schema: [
|
|
625
|
+
OPTIONS_SCHEMA,
|
|
626
|
+
],
|
|
627
|
+
type: 'suggestion',
|
|
628
|
+
},
|
|
629
|
+
};
|