eslint-plugin-jsdoc 56.0.0 → 56.0.2
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/getJsdocProcessorPlugin.d.cts +5 -1
- package/dist/cjs/iterateJsdoc.d.cts +6 -2
- package/dist/getJsdocProcessorPlugin.cts +3 -1
- package/dist/iterateJsdoc.cts +9 -4
- package/package.json +4 -4
- package/src/getJsdocProcessorPlugin.cts +3 -1
- package/src/iterateJsdoc.cts +9 -4
- package/dist/cjs/WarnSettings.js +0 -30
- package/dist/cjs/alignTransform.js +0 -285
- package/dist/cjs/defaultTagOrder.js +0 -152
- package/dist/cjs/exportParser.js +0 -754
- package/dist/cjs/getDefaultTagStructureForMode.js +0 -840
- package/dist/cjs/getJsdocProcessorPlugin.cjs +0 -4
- package/dist/cjs/getJsdocProcessorPlugin.js +0 -553
- package/dist/cjs/index-cjs.js +0 -492
- package/dist/cjs/index.cjs.cjs +0 -6
- package/dist/cjs/iterateJsdoc.cjs +0 -38
- package/dist/cjs/iterateJsdoc.js +0 -1981
- package/dist/cjs/jsdocUtils.js +0 -1470
- package/dist/cjs/rules/checkAccess.js +0 -35
- package/dist/cjs/rules/checkAlignment.js +0 -63
- package/dist/cjs/rules/checkExamples.js +0 -486
- package/dist/cjs/rules/checkIndentation.js +0 -66
- package/dist/cjs/rules/checkLineAlignment.js +0 -297
- package/dist/cjs/rules/checkParamNames.js +0 -320
- package/dist/cjs/rules/checkPropertyNames.js +0 -105
- package/dist/cjs/rules/checkSyntax.js +0 -27
- package/dist/cjs/rules/checkTagNames.js +0 -252
- package/dist/cjs/rules/checkTemplateNames.js +0 -189
- package/dist/cjs/rules/checkTypes.js +0 -421
- package/dist/cjs/rules/checkValues.js +0 -163
- package/dist/cjs/rules/convertToJsdocComments.js +0 -313
- package/dist/cjs/rules/emptyTags.js +0 -79
- package/dist/cjs/rules/implementsOnClasses.js +0 -63
- package/dist/cjs/rules/importsAsDependencies.js +0 -105
- package/dist/cjs/rules/informativeDocs.js +0 -153
- package/dist/cjs/rules/linesBeforeBlock.js +0 -106
- package/dist/cjs/rules/matchDescription.js +0 -240
- package/dist/cjs/rules/matchName.js +0 -122
- package/dist/cjs/rules/multilineBlocks.js +0 -339
- package/dist/cjs/rules/noBadBlocks.js +0 -88
- package/dist/cjs/rules/noBlankBlockDescriptions.js +0 -56
- package/dist/cjs/rules/noBlankBlocks.js +0 -41
- package/dist/cjs/rules/noDefaults.js +0 -84
- package/dist/cjs/rules/noMissingSyntax.js +0 -164
- package/dist/cjs/rules/noMultiAsterisks.js +0 -83
- package/dist/cjs/rules/noRestrictedSyntax.js +0 -75
- package/dist/cjs/rules/noTypes.js +0 -88
- package/dist/cjs/rules/noUndefinedTypes.js +0 -451
- package/dist/cjs/rules/requireAsteriskPrefix.js +0 -144
- package/dist/cjs/rules/requireDescription.js +0 -136
- package/dist/cjs/rules/requireDescriptionCompleteSentence.js +0 -258
- package/dist/cjs/rules/requireExample.js +0 -103
- package/dist/cjs/rules/requireFileOverview.js +0 -117
- package/dist/cjs/rules/requireHyphenBeforeParamDescription.js +0 -144
- package/dist/cjs/rules/requireJsdoc.js +0 -629
- package/dist/cjs/rules/requireParam.js +0 -480
- package/dist/cjs/rules/requireParamDescription.js +0 -77
- package/dist/cjs/rules/requireParamName.js +0 -52
- package/dist/cjs/rules/requireParamType.js +0 -77
- package/dist/cjs/rules/requireProperty.js +0 -44
- package/dist/cjs/rules/requirePropertyDescription.js +0 -22
- package/dist/cjs/rules/requirePropertyName.js +0 -22
- package/dist/cjs/rules/requirePropertyType.js +0 -22
- package/dist/cjs/rules/requireReturns.js +0 -197
- package/dist/cjs/rules/requireReturnsCheck.js +0 -108
- package/dist/cjs/rules/requireReturnsDescription.js +0 -58
- package/dist/cjs/rules/requireReturnsType.js +0 -52
- package/dist/cjs/rules/requireTemplate.js +0 -173
- package/dist/cjs/rules/requireThrows.js +0 -101
- package/dist/cjs/rules/requireYields.js +0 -172
- package/dist/cjs/rules/requireYieldsCheck.js +0 -164
- package/dist/cjs/rules/sortTags.js +0 -392
- package/dist/cjs/rules/tagLines.js +0 -259
- package/dist/cjs/rules/textEscaping.js +0 -125
- package/dist/cjs/rules/typeFormatting.js +0 -328
- package/dist/cjs/rules/validTypes.js +0 -333
- package/dist/cjs/tagNames.js +0 -209
- package/dist/cjs/utils/hasReturnValue.js +0 -469
package/dist/cjs/exportParser.js
DELETED
|
@@ -1,754 +0,0 @@
|
|
|
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 jsdoccomment_1 = require("@es-joy/jsdoccomment");
|
|
7
|
-
const debug_1 = __importDefault(require("debug"));
|
|
8
|
-
const debug = (0, debug_1.default)('requireExportJsdoc');
|
|
9
|
-
/**
|
|
10
|
-
* @typedef {{
|
|
11
|
-
* value: string
|
|
12
|
-
* }} ValueObject
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* @typedef {{
|
|
16
|
-
* type?: string,
|
|
17
|
-
* value?: ValueObject|import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node,
|
|
18
|
-
* props: {
|
|
19
|
-
* [key: string]: CreatedNode|null,
|
|
20
|
-
* },
|
|
21
|
-
* special?: true,
|
|
22
|
-
* globalVars?: CreatedNode,
|
|
23
|
-
* exported?: boolean,
|
|
24
|
-
* ANONYMOUS_DEFAULT?: import('eslint').Rule.Node
|
|
25
|
-
* }} CreatedNode
|
|
26
|
-
*/
|
|
27
|
-
/**
|
|
28
|
-
* @returns {CreatedNode}
|
|
29
|
-
*/
|
|
30
|
-
const createNode = function () {
|
|
31
|
-
return {
|
|
32
|
-
props: {},
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* @param {CreatedNode|null} symbol
|
|
37
|
-
* @returns {string|null}
|
|
38
|
-
*/
|
|
39
|
-
const getSymbolValue = function (symbol) {
|
|
40
|
-
/* c8 ignore next 3 */
|
|
41
|
-
if (!symbol) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
/* c8 ignore else */
|
|
45
|
-
if (symbol.type === 'literal') {
|
|
46
|
-
return /** @type {ValueObject} */ (symbol.value).value;
|
|
47
|
-
}
|
|
48
|
-
/* c8 ignore next 2 */
|
|
49
|
-
// eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
|
|
50
|
-
return null;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
*
|
|
54
|
-
* @param {import('estree').Identifier} node
|
|
55
|
-
* @param {CreatedNode} globals
|
|
56
|
-
* @param {CreatedNode} scope
|
|
57
|
-
* @param {SymbolOptions} opts
|
|
58
|
-
* @returns {CreatedNode|null}
|
|
59
|
-
*/
|
|
60
|
-
const getIdentifier = function (node, globals, scope, opts) {
|
|
61
|
-
if (opts.simpleIdentifier) {
|
|
62
|
-
// Type is Identier for noncomputed properties
|
|
63
|
-
const identifierLiteral = createNode();
|
|
64
|
-
identifierLiteral.type = 'literal';
|
|
65
|
-
identifierLiteral.value = {
|
|
66
|
-
value: node.name,
|
|
67
|
-
};
|
|
68
|
-
return identifierLiteral;
|
|
69
|
-
}
|
|
70
|
-
/* c8 ignore next */
|
|
71
|
-
const block = scope || globals;
|
|
72
|
-
// As scopes are not currently supported, they are not traversed upwards recursively
|
|
73
|
-
if (block.props[node.name]) {
|
|
74
|
-
return block.props[node.name];
|
|
75
|
-
}
|
|
76
|
-
// Seems this will only be entered once scopes added and entered
|
|
77
|
-
/* c8 ignore next 3 */
|
|
78
|
-
if (globals.props[node.name]) {
|
|
79
|
-
return globals.props[node.name];
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* @callback CreateSymbol
|
|
85
|
-
* @param {import('eslint').Rule.Node|null} node
|
|
86
|
-
* @param {CreatedNode} globals
|
|
87
|
-
* @param {import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node|null} value
|
|
88
|
-
* @param {CreatedNode} [scope]
|
|
89
|
-
* @param {boolean|SymbolOptions} [isGlobal]
|
|
90
|
-
* @returns {CreatedNode|null}
|
|
91
|
-
*/
|
|
92
|
-
/** @type {CreateSymbol} */
|
|
93
|
-
let createSymbol; // eslint-disable-line prefer-const
|
|
94
|
-
/* eslint-disable complexity -- Temporary */
|
|
95
|
-
/**
|
|
96
|
-
* @typedef {{
|
|
97
|
-
* simpleIdentifier?: boolean
|
|
98
|
-
* }} SymbolOptions
|
|
99
|
-
*/
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
* @param {import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node} node
|
|
103
|
-
* @param {CreatedNode} globals
|
|
104
|
-
* @param {CreatedNode} scope
|
|
105
|
-
* @param {SymbolOptions} [opt]
|
|
106
|
-
* @returns {CreatedNode|null}
|
|
107
|
-
*/
|
|
108
|
-
const getSymbol = function (node, globals, scope, opt) {
|
|
109
|
-
/* eslint-enable complexity -- Temporary */
|
|
110
|
-
const opts = opt || {};
|
|
111
|
-
/* c8 ignore next */
|
|
112
|
-
switch (node.type) {
|
|
113
|
-
/* c8 ignore next 4 -- No longer needed? */
|
|
114
|
-
case 'ArrowFunctionExpression':
|
|
115
|
-
// Fallthrough
|
|
116
|
-
case 'ClassDeclaration':
|
|
117
|
-
case 'FunctionDeclaration':
|
|
118
|
-
case 'FunctionExpression':
|
|
119
|
-
case 'TSEnumDeclaration':
|
|
120
|
-
case 'TSInterfaceDeclaration':
|
|
121
|
-
case 'TSTypeAliasDeclaration': {
|
|
122
|
-
const val = createNode();
|
|
123
|
-
val.props.prototype = createNode();
|
|
124
|
-
val.props.prototype.type = 'object';
|
|
125
|
-
val.type = 'object';
|
|
126
|
-
val.value = node;
|
|
127
|
-
return val;
|
|
128
|
-
}
|
|
129
|
-
case 'AssignmentExpression': {
|
|
130
|
-
return createSymbol(
|
|
131
|
-
/** @type {import('eslint').Rule.Node} */
|
|
132
|
-
(node.left), globals,
|
|
133
|
-
/** @type {import('eslint').Rule.Node} */
|
|
134
|
-
(node.right), scope, opts);
|
|
135
|
-
}
|
|
136
|
-
case 'ClassBody': {
|
|
137
|
-
const val = createNode();
|
|
138
|
-
for (const method of node.body) {
|
|
139
|
-
// StaticBlock
|
|
140
|
-
if (!('key' in method)) {
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
val.props[
|
|
144
|
-
/** @type {import('estree').Identifier} */ (
|
|
145
|
-
/** @type {import('estree').MethodDefinition} */ (method).key).name] = createNode();
|
|
146
|
-
/** @type {{[key: string]: CreatedNode}} */ (val.props)[
|
|
147
|
-
/** @type {import('estree').Identifier} */ (
|
|
148
|
-
/** @type {import('estree').MethodDefinition} */ (method).key).name].type = 'object';
|
|
149
|
-
/** @type {{[key: string]: CreatedNode}} */ (val.props)[
|
|
150
|
-
/** @type {import('estree').Identifier} */ (
|
|
151
|
-
/** @type {import('estree').MethodDefinition} */ (method).key).name].value = /** @type {import('eslint').Rule.Node} */ (
|
|
152
|
-
/** @type {import('estree').MethodDefinition} */ (method).value);
|
|
153
|
-
}
|
|
154
|
-
val.type = 'object';
|
|
155
|
-
val.value = node.parent;
|
|
156
|
-
return val;
|
|
157
|
-
}
|
|
158
|
-
case 'ClassExpression': {
|
|
159
|
-
return getSymbol(
|
|
160
|
-
/** @type {import('eslint').Rule.Node} */
|
|
161
|
-
(node.body), globals, scope, opts);
|
|
162
|
-
}
|
|
163
|
-
case 'Identifier': {
|
|
164
|
-
return getIdentifier(node, globals, scope, opts);
|
|
165
|
-
}
|
|
166
|
-
case 'Literal': {
|
|
167
|
-
const val = createNode();
|
|
168
|
-
val.type = 'literal';
|
|
169
|
-
val.value = node;
|
|
170
|
-
return val;
|
|
171
|
-
}
|
|
172
|
-
case 'MemberExpression': {
|
|
173
|
-
const obj = getSymbol(
|
|
174
|
-
/** @type {import('eslint').Rule.Node} */
|
|
175
|
-
(node.object), globals, scope, opts);
|
|
176
|
-
const propertySymbol = getSymbol(
|
|
177
|
-
/** @type {import('eslint').Rule.Node} */
|
|
178
|
-
(node.property), globals, scope, {
|
|
179
|
-
simpleIdentifier: !node.computed,
|
|
180
|
-
});
|
|
181
|
-
const propertyValue = getSymbolValue(propertySymbol);
|
|
182
|
-
/* c8 ignore else */
|
|
183
|
-
if (obj && propertyValue && obj.props[propertyValue]) {
|
|
184
|
-
const block = obj.props[propertyValue];
|
|
185
|
-
return block;
|
|
186
|
-
}
|
|
187
|
-
/* c8 ignore next 11 */
|
|
188
|
-
/*
|
|
189
|
-
if (opts.createMissingProps && propertyValue) {
|
|
190
|
-
obj.props[propertyValue] = createNode();
|
|
191
|
-
|
|
192
|
-
return obj.props[propertyValue];
|
|
193
|
-
}
|
|
194
|
-
*/
|
|
195
|
-
// eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
|
|
196
|
-
debug(`MemberExpression: Missing property ${
|
|
197
|
-
/** @type {import('estree').PrivateIdentifier} */ (node.property).name}`);
|
|
198
|
-
/* c8 ignore next 2 */
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
case 'ObjectExpression': {
|
|
202
|
-
const val = createNode();
|
|
203
|
-
val.type = 'object';
|
|
204
|
-
for (const prop of node.properties) {
|
|
205
|
-
if ([
|
|
206
|
-
// @babel/eslint-parser
|
|
207
|
-
'ExperimentalSpreadProperty',
|
|
208
|
-
// typescript-eslint, espree, acorn, etc.
|
|
209
|
-
'SpreadElement',
|
|
210
|
-
].includes(prop.type)) {
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
const propVal = getSymbol(
|
|
214
|
-
/** @type {import('eslint').Rule.Node} */ (
|
|
215
|
-
/** @type {import('estree').Property} */
|
|
216
|
-
(prop).value), globals, scope, opts);
|
|
217
|
-
/* c8 ignore next 8 */
|
|
218
|
-
if (propVal) {
|
|
219
|
-
val.props[
|
|
220
|
-
/** @type {import('estree').PrivateIdentifier} */
|
|
221
|
-
(
|
|
222
|
-
/** @type {import('estree').Property} */ (prop).key).name] = propVal;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return val;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
/* c8 ignore next 2 */
|
|
229
|
-
// eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
|
|
230
|
-
return null;
|
|
231
|
-
};
|
|
232
|
-
/**
|
|
233
|
-
*
|
|
234
|
-
* @param {CreatedNode} block
|
|
235
|
-
* @param {string} name
|
|
236
|
-
* @param {CreatedNode|null} value
|
|
237
|
-
* @param {CreatedNode} globals
|
|
238
|
-
* @param {boolean|SymbolOptions|undefined} isGlobal
|
|
239
|
-
* @returns {void}
|
|
240
|
-
*/
|
|
241
|
-
const createBlockSymbol = function (block, name, value, globals, isGlobal) {
|
|
242
|
-
block.props[name] = value;
|
|
243
|
-
if (isGlobal && globals.props.window && globals.props.window.special) {
|
|
244
|
-
globals.props.window.props[name] = value;
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
createSymbol = function (node, globals, value, scope, isGlobal) {
|
|
248
|
-
const block = scope || globals;
|
|
249
|
-
/* c8 ignore next 3 */
|
|
250
|
-
if (!node) {
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
253
|
-
let symbol;
|
|
254
|
-
switch (node.type) {
|
|
255
|
-
case 'ClassDeclaration':
|
|
256
|
-
/* c8 ignore next */
|
|
257
|
-
// @ts-expect-error TS OK
|
|
258
|
-
// Fall through
|
|
259
|
-
case 'FunctionDeclaration':
|
|
260
|
-
case 'TSEnumDeclaration':
|
|
261
|
-
/* c8 ignore next */
|
|
262
|
-
// @ts-expect-error TS OK
|
|
263
|
-
// Fall through
|
|
264
|
-
case 'TSInterfaceDeclaration':
|
|
265
|
-
case 'TSTypeAliasDeclaration': {
|
|
266
|
-
const nde = /** @type {import('estree').ClassDeclaration} */ (node);
|
|
267
|
-
/* c8 ignore else */
|
|
268
|
-
if (nde.id && nde.id.type === 'Identifier') {
|
|
269
|
-
return createSymbol(
|
|
270
|
-
/** @type {import('eslint').Rule.Node} */ (nde.id), globals, node, globals);
|
|
271
|
-
}
|
|
272
|
-
/* c8 ignore next 3 */
|
|
273
|
-
// eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
case 'Identifier': {
|
|
277
|
-
const nde = /** @type {import('estree').Identifier} */ (node);
|
|
278
|
-
if (value) {
|
|
279
|
-
const valueSymbol = getSymbol(value, globals, block);
|
|
280
|
-
/* c8 ignore else */
|
|
281
|
-
if (valueSymbol) {
|
|
282
|
-
createBlockSymbol(block, nde.name, valueSymbol, globals, isGlobal);
|
|
283
|
-
return block.props[nde.name];
|
|
284
|
-
}
|
|
285
|
-
/* c8 ignore next 2 */
|
|
286
|
-
// eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
|
|
287
|
-
debug('Identifier: Missing value symbol for %s', nde.name);
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
createBlockSymbol(block, nde.name, createNode(), globals, isGlobal);
|
|
291
|
-
return block.props[nde.name];
|
|
292
|
-
}
|
|
293
|
-
/* c8 ignore next 3 */
|
|
294
|
-
// eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
297
|
-
case 'MemberExpression': {
|
|
298
|
-
const nde = /** @type {import('estree').MemberExpression} */ (node);
|
|
299
|
-
symbol = getSymbol(
|
|
300
|
-
/** @type {import('eslint').Rule.Node} */ (nde.object), globals, block);
|
|
301
|
-
const propertySymbol = getSymbol(
|
|
302
|
-
/** @type {import('eslint').Rule.Node} */ (nde.property), globals, block, {
|
|
303
|
-
simpleIdentifier: !nde.computed,
|
|
304
|
-
});
|
|
305
|
-
const propertyValue = getSymbolValue(propertySymbol);
|
|
306
|
-
if (symbol && propertyValue) {
|
|
307
|
-
createBlockSymbol(symbol, propertyValue, getSymbol(
|
|
308
|
-
/** @type {import('eslint').Rule.Node} */
|
|
309
|
-
(value), globals, block), globals, isGlobal);
|
|
310
|
-
return symbol.props[propertyValue];
|
|
311
|
-
}
|
|
312
|
-
debug('MemberExpression: Missing symbol: %s',
|
|
313
|
-
/** @type {import('estree').Identifier} */ (nde.property).name);
|
|
314
|
-
break;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
return null;
|
|
318
|
-
};
|
|
319
|
-
/**
|
|
320
|
-
* Creates variables from variable definitions
|
|
321
|
-
* @param {import('eslint').Rule.Node} node
|
|
322
|
-
* @param {CreatedNode} globals
|
|
323
|
-
* @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opts
|
|
324
|
-
* @returns {void}
|
|
325
|
-
*/
|
|
326
|
-
const initVariables = function (node, globals, opts) {
|
|
327
|
-
switch (node.type) {
|
|
328
|
-
case 'ExportNamedDeclaration': {
|
|
329
|
-
if (node.declaration) {
|
|
330
|
-
initVariables(
|
|
331
|
-
/** @type {import('eslint').Rule.Node} */
|
|
332
|
-
(node.declaration), globals, opts);
|
|
333
|
-
}
|
|
334
|
-
break;
|
|
335
|
-
}
|
|
336
|
-
case 'ExpressionStatement': {
|
|
337
|
-
initVariables(
|
|
338
|
-
/** @type {import('eslint').Rule.Node} */
|
|
339
|
-
(node.expression), globals, opts);
|
|
340
|
-
break;
|
|
341
|
-
}
|
|
342
|
-
case 'Program': {
|
|
343
|
-
for (const childNode of node.body) {
|
|
344
|
-
initVariables(
|
|
345
|
-
/** @type {import('eslint').Rule.Node} */
|
|
346
|
-
(childNode), globals, opts);
|
|
347
|
-
}
|
|
348
|
-
break;
|
|
349
|
-
}
|
|
350
|
-
case 'VariableDeclaration': {
|
|
351
|
-
for (const declaration of node.declarations) {
|
|
352
|
-
// let and const
|
|
353
|
-
const symbol = createSymbol(
|
|
354
|
-
/** @type {import('eslint').Rule.Node} */
|
|
355
|
-
(declaration.id), globals, null, globals);
|
|
356
|
-
if (opts.initWindow && node.kind === 'var' && globals.props.window) {
|
|
357
|
-
// If var, also add to window
|
|
358
|
-
globals.props.window.props[
|
|
359
|
-
/** @type {import('estree').Identifier} */
|
|
360
|
-
(declaration.id).name] = symbol;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
break;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
/* eslint-disable complexity -- Temporary */
|
|
368
|
-
/**
|
|
369
|
-
* Populates variable maps using AST
|
|
370
|
-
* @param {import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node} node
|
|
371
|
-
* @param {CreatedNode} globals
|
|
372
|
-
* @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opt
|
|
373
|
-
* @param {true} [isExport]
|
|
374
|
-
* @returns {boolean}
|
|
375
|
-
*/
|
|
376
|
-
const mapVariables = function (node, globals, opt, isExport) {
|
|
377
|
-
/* eslint-enable complexity -- Temporary */
|
|
378
|
-
/* c8 ignore next */
|
|
379
|
-
const opts = opt || {};
|
|
380
|
-
/* c8 ignore next */
|
|
381
|
-
switch (node.type) {
|
|
382
|
-
case 'AssignmentExpression': {
|
|
383
|
-
createSymbol(
|
|
384
|
-
/** @type {import('eslint').Rule.Node} */
|
|
385
|
-
(node.left), globals,
|
|
386
|
-
/** @type {import('eslint').Rule.Node} */
|
|
387
|
-
(node.right));
|
|
388
|
-
break;
|
|
389
|
-
}
|
|
390
|
-
case 'ClassDeclaration': {
|
|
391
|
-
createSymbol(
|
|
392
|
-
/** @type {import('eslint').Rule.Node|null} */ (node.id), globals,
|
|
393
|
-
/** @type {import('eslint').Rule.Node} */ (node.body), globals);
|
|
394
|
-
break;
|
|
395
|
-
}
|
|
396
|
-
case 'ExportDefaultDeclaration': {
|
|
397
|
-
const symbol = createSymbol(
|
|
398
|
-
/** @type {import('eslint').Rule.Node} */
|
|
399
|
-
(node.declaration), globals,
|
|
400
|
-
/** @type {import('eslint').Rule.Node} */
|
|
401
|
-
(node.declaration));
|
|
402
|
-
if (symbol) {
|
|
403
|
-
symbol.exported = true;
|
|
404
|
-
/* c8 ignore next 6 */
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
// if (!node.id) {
|
|
408
|
-
globals.ANONYMOUS_DEFAULT = /** @type {import('eslint').Rule.Node} */ (node.declaration);
|
|
409
|
-
}
|
|
410
|
-
break;
|
|
411
|
-
}
|
|
412
|
-
case 'ExportNamedDeclaration': {
|
|
413
|
-
if (node.declaration) {
|
|
414
|
-
if (node.declaration.type === 'VariableDeclaration') {
|
|
415
|
-
mapVariables(
|
|
416
|
-
/** @type {import('eslint').Rule.Node} */
|
|
417
|
-
(node.declaration), globals, opts, true);
|
|
418
|
-
}
|
|
419
|
-
else {
|
|
420
|
-
const symbol = createSymbol(
|
|
421
|
-
/** @type {import('eslint').Rule.Node} */
|
|
422
|
-
(node.declaration), globals,
|
|
423
|
-
/** @type {import('eslint').Rule.Node} */
|
|
424
|
-
(node.declaration));
|
|
425
|
-
/* c8 ignore next 3 */
|
|
426
|
-
if (symbol) {
|
|
427
|
-
symbol.exported = true;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
for (const specifier of node.specifiers) {
|
|
432
|
-
mapVariables(
|
|
433
|
-
/** @type {import('eslint').Rule.Node} */
|
|
434
|
-
(specifier), globals, opts);
|
|
435
|
-
}
|
|
436
|
-
break;
|
|
437
|
-
}
|
|
438
|
-
case 'ExportSpecifier': {
|
|
439
|
-
const symbol = getSymbol(
|
|
440
|
-
/** @type {import('eslint').Rule.Node} */
|
|
441
|
-
(node.local), globals, globals);
|
|
442
|
-
/* c8 ignore next 3 */
|
|
443
|
-
if (symbol) {
|
|
444
|
-
symbol.exported = true;
|
|
445
|
-
}
|
|
446
|
-
break;
|
|
447
|
-
}
|
|
448
|
-
case 'ExpressionStatement': {
|
|
449
|
-
mapVariables(
|
|
450
|
-
/** @type {import('eslint').Rule.Node} */
|
|
451
|
-
(node.expression), globals, opts);
|
|
452
|
-
break;
|
|
453
|
-
}
|
|
454
|
-
case 'FunctionDeclaration':
|
|
455
|
-
case 'TSTypeAliasDeclaration': {
|
|
456
|
-
/* c8 ignore next 10 */
|
|
457
|
-
if ( /** @type {import('estree').Identifier} */(node.id).type === 'Identifier') {
|
|
458
|
-
createSymbol(
|
|
459
|
-
/** @type {import('eslint').Rule.Node} */
|
|
460
|
-
(node.id), globals, node, globals, true);
|
|
461
|
-
}
|
|
462
|
-
break;
|
|
463
|
-
}
|
|
464
|
-
case 'Program': {
|
|
465
|
-
if (opts.ancestorsOnly) {
|
|
466
|
-
return false;
|
|
467
|
-
}
|
|
468
|
-
for (const childNode of node.body) {
|
|
469
|
-
mapVariables(
|
|
470
|
-
/** @type {import('eslint').Rule.Node} */
|
|
471
|
-
(childNode), globals, opts);
|
|
472
|
-
}
|
|
473
|
-
break;
|
|
474
|
-
}
|
|
475
|
-
case 'VariableDeclaration': {
|
|
476
|
-
for (const declaration of node.declarations) {
|
|
477
|
-
const isGlobal = Boolean(opts.initWindow && node.kind === 'var' && globals.props.window);
|
|
478
|
-
const symbol = createSymbol(
|
|
479
|
-
/** @type {import('eslint').Rule.Node} */
|
|
480
|
-
(declaration.id), globals,
|
|
481
|
-
/** @type {import('eslint').Rule.Node} */
|
|
482
|
-
(declaration.init), globals, isGlobal);
|
|
483
|
-
if (symbol && isExport) {
|
|
484
|
-
symbol.exported = true;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
break;
|
|
488
|
-
}
|
|
489
|
-
default: {
|
|
490
|
-
/* c8 ignore next */
|
|
491
|
-
return false;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
return true;
|
|
495
|
-
};
|
|
496
|
-
/**
|
|
497
|
-
*
|
|
498
|
-
* @param {import('eslint').Rule.Node} node
|
|
499
|
-
* @param {CreatedNode|ValueObject|string|undefined|
|
|
500
|
-
* import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node} block
|
|
501
|
-
* @param {(CreatedNode|ValueObject|string|
|
|
502
|
-
* import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node)[]} [cache]
|
|
503
|
-
* @returns {boolean}
|
|
504
|
-
*/
|
|
505
|
-
const findNode = function (node, block, cache) {
|
|
506
|
-
let blockCache = cache || [];
|
|
507
|
-
if (!block || blockCache.includes(block)) {
|
|
508
|
-
return false;
|
|
509
|
-
}
|
|
510
|
-
blockCache = blockCache.slice();
|
|
511
|
-
blockCache.push(block);
|
|
512
|
-
if (typeof block === 'object' &&
|
|
513
|
-
'type' in block &&
|
|
514
|
-
(block.type === 'object' || block.type === 'MethodDefinition') &&
|
|
515
|
-
block.value === node) {
|
|
516
|
-
return true;
|
|
517
|
-
}
|
|
518
|
-
if (typeof block !== 'object') {
|
|
519
|
-
return false;
|
|
520
|
-
}
|
|
521
|
-
const props = ('props' in block && block.props) || ('body' in block && block.body);
|
|
522
|
-
for (const propval of Object.values(props || {})) {
|
|
523
|
-
if (Array.isArray(propval)) {
|
|
524
|
-
/* c8 ignore next 5 */
|
|
525
|
-
if (propval.some((val) => {
|
|
526
|
-
return findNode(node, val, blockCache);
|
|
527
|
-
})) {
|
|
528
|
-
return true;
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
else if (findNode(node, propval, blockCache)) {
|
|
532
|
-
return true;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
return false;
|
|
536
|
-
};
|
|
537
|
-
const exportTypes = new Set([
|
|
538
|
-
'ExportDefaultDeclaration', 'ExportNamedDeclaration',
|
|
539
|
-
]);
|
|
540
|
-
const ignorableNestedTypes = new Set([
|
|
541
|
-
'ArrowFunctionExpression', 'FunctionDeclaration', 'FunctionExpression',
|
|
542
|
-
]);
|
|
543
|
-
/**
|
|
544
|
-
* @param {import('eslint').Rule.Node} nde
|
|
545
|
-
* @returns {import('eslint').Rule.Node|false}
|
|
546
|
-
*/
|
|
547
|
-
const getExportAncestor = function (nde) {
|
|
548
|
-
let node = nde;
|
|
549
|
-
let idx = 0;
|
|
550
|
-
const ignorableIfDeep = ignorableNestedTypes.has(nde?.type);
|
|
551
|
-
while (node) {
|
|
552
|
-
// Ignore functions nested more deeply than say `export default function () {}`
|
|
553
|
-
if (idx >= 2 && ignorableIfDeep) {
|
|
554
|
-
break;
|
|
555
|
-
}
|
|
556
|
-
if (exportTypes.has(node.type)) {
|
|
557
|
-
return node;
|
|
558
|
-
}
|
|
559
|
-
node = node.parent;
|
|
560
|
-
idx++;
|
|
561
|
-
}
|
|
562
|
-
return false;
|
|
563
|
-
};
|
|
564
|
-
const canBeExportedByAncestorType = new Set([
|
|
565
|
-
'ClassProperty',
|
|
566
|
-
'Method',
|
|
567
|
-
'PropertyDefinition',
|
|
568
|
-
'TSMethodSignature',
|
|
569
|
-
'TSPropertySignature',
|
|
570
|
-
]);
|
|
571
|
-
const canExportChildrenType = new Set([
|
|
572
|
-
'ClassBody',
|
|
573
|
-
'ClassDeclaration',
|
|
574
|
-
'ClassDefinition',
|
|
575
|
-
'ClassExpression',
|
|
576
|
-
'Program',
|
|
577
|
-
'TSInterfaceBody',
|
|
578
|
-
'TSInterfaceDeclaration',
|
|
579
|
-
'TSTypeAliasDeclaration',
|
|
580
|
-
'TSTypeLiteral',
|
|
581
|
-
'TSTypeParameterInstantiation',
|
|
582
|
-
'TSTypeReference',
|
|
583
|
-
]);
|
|
584
|
-
/**
|
|
585
|
-
* @param {import('eslint').Rule.Node} nde
|
|
586
|
-
* @returns {false|import('eslint').Rule.Node}
|
|
587
|
-
*/
|
|
588
|
-
const isExportByAncestor = function (nde) {
|
|
589
|
-
if (!canBeExportedByAncestorType.has(nde.type)) {
|
|
590
|
-
return false;
|
|
591
|
-
}
|
|
592
|
-
let node = nde.parent;
|
|
593
|
-
while (node) {
|
|
594
|
-
if (exportTypes.has(node.type)) {
|
|
595
|
-
return node;
|
|
596
|
-
}
|
|
597
|
-
if (!canExportChildrenType.has(node.type)) {
|
|
598
|
-
return false;
|
|
599
|
-
}
|
|
600
|
-
node = node.parent;
|
|
601
|
-
}
|
|
602
|
-
return false;
|
|
603
|
-
};
|
|
604
|
-
/**
|
|
605
|
-
*
|
|
606
|
-
* @param {CreatedNode} block
|
|
607
|
-
* @param {import('eslint').Rule.Node} node
|
|
608
|
-
* @param {CreatedNode[]} [cache] Currently unused
|
|
609
|
-
* @returns {boolean}
|
|
610
|
-
*/
|
|
611
|
-
const findExportedNode = function (block, node, cache) {
|
|
612
|
-
/* c8 ignore next 3 */
|
|
613
|
-
if (block === null) {
|
|
614
|
-
return false;
|
|
615
|
-
}
|
|
616
|
-
const blockCache = cache || [];
|
|
617
|
-
const { props, } = block;
|
|
618
|
-
for (const propval of Object.values(props)) {
|
|
619
|
-
const pval = /** @type {CreatedNode} */ (propval);
|
|
620
|
-
blockCache.push(pval);
|
|
621
|
-
if (pval.exported && (node === pval.value || findNode(node, pval.value))) {
|
|
622
|
-
return true;
|
|
623
|
-
}
|
|
624
|
-
// No need to check `propval` for exported nodes as ESM
|
|
625
|
-
// exports are only global
|
|
626
|
-
}
|
|
627
|
-
return false;
|
|
628
|
-
};
|
|
629
|
-
/**
|
|
630
|
-
*
|
|
631
|
-
* @param {import('eslint').Rule.Node} node
|
|
632
|
-
* @param {CreatedNode} globals
|
|
633
|
-
* @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opt
|
|
634
|
-
* @returns {boolean}
|
|
635
|
-
*/
|
|
636
|
-
const isNodeExported = function (node, globals, opt) {
|
|
637
|
-
const moduleExports = globals.props.module?.props?.exports;
|
|
638
|
-
if (opt.initModuleExports && moduleExports && findNode(node, moduleExports)) {
|
|
639
|
-
return true;
|
|
640
|
-
}
|
|
641
|
-
if (opt.initWindow && globals.props.window && findNode(node, globals.props.window)) {
|
|
642
|
-
return true;
|
|
643
|
-
}
|
|
644
|
-
if (opt.esm && findExportedNode(globals, node)) {
|
|
645
|
-
return true;
|
|
646
|
-
}
|
|
647
|
-
return false;
|
|
648
|
-
};
|
|
649
|
-
/**
|
|
650
|
-
*
|
|
651
|
-
* @param {import('eslint').Rule.Node} node
|
|
652
|
-
* @param {CreatedNode} globalVars
|
|
653
|
-
* @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opts
|
|
654
|
-
* @returns {boolean}
|
|
655
|
-
*/
|
|
656
|
-
const parseRecursive = function (node, globalVars, opts) {
|
|
657
|
-
// Iterate from top using recursion - stop at first processed node from top
|
|
658
|
-
if (node.parent && parseRecursive(node.parent, globalVars, opts)) {
|
|
659
|
-
return true;
|
|
660
|
-
}
|
|
661
|
-
return mapVariables(node, globalVars, opts);
|
|
662
|
-
};
|
|
663
|
-
/**
|
|
664
|
-
*
|
|
665
|
-
* @param {import('eslint').Rule.Node} ast
|
|
666
|
-
* @param {import('eslint').Rule.Node} node
|
|
667
|
-
* @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opt
|
|
668
|
-
* @returns {CreatedNode}
|
|
669
|
-
*/
|
|
670
|
-
const parse = function (ast, node, opt) {
|
|
671
|
-
/* c8 ignore next 6 */
|
|
672
|
-
const opts = opt || {
|
|
673
|
-
ancestorsOnly: false,
|
|
674
|
-
esm: true,
|
|
675
|
-
initModuleExports: true,
|
|
676
|
-
initWindow: true,
|
|
677
|
-
};
|
|
678
|
-
const globalVars = createNode();
|
|
679
|
-
if (opts.initModuleExports) {
|
|
680
|
-
globalVars.props.module = createNode();
|
|
681
|
-
globalVars.props.module.props.exports = createNode();
|
|
682
|
-
globalVars.props.exports = globalVars.props.module.props.exports;
|
|
683
|
-
}
|
|
684
|
-
if (opts.initWindow) {
|
|
685
|
-
globalVars.props.window = createNode();
|
|
686
|
-
globalVars.props.window.special = true;
|
|
687
|
-
}
|
|
688
|
-
if (opts.ancestorsOnly) {
|
|
689
|
-
parseRecursive(node, globalVars, opts);
|
|
690
|
-
}
|
|
691
|
-
else {
|
|
692
|
-
initVariables(ast, globalVars, opts);
|
|
693
|
-
mapVariables(ast, globalVars, opts);
|
|
694
|
-
}
|
|
695
|
-
return {
|
|
696
|
-
globalVars,
|
|
697
|
-
props: {},
|
|
698
|
-
};
|
|
699
|
-
};
|
|
700
|
-
const accessibilityNodes = new Set([
|
|
701
|
-
'MethodDefinition',
|
|
702
|
-
'PropertyDefinition',
|
|
703
|
-
]);
|
|
704
|
-
/**
|
|
705
|
-
*
|
|
706
|
-
* @param {import('eslint').Rule.Node} node
|
|
707
|
-
* @returns {boolean}
|
|
708
|
-
*/
|
|
709
|
-
const isPrivate = (node) => {
|
|
710
|
-
return accessibilityNodes.has(node.type) &&
|
|
711
|
-
('accessibility' in node &&
|
|
712
|
-
node.accessibility !== 'public' && node.accessibility !== undefined) ||
|
|
713
|
-
'key' in node &&
|
|
714
|
-
node.key.type === 'PrivateIdentifier';
|
|
715
|
-
};
|
|
716
|
-
/**
|
|
717
|
-
*
|
|
718
|
-
* @param {import('eslint').Rule.Node} node
|
|
719
|
-
* @param {import('eslint').SourceCode} sourceCode
|
|
720
|
-
* @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opt
|
|
721
|
-
* @param {import('./iterateJsdoc.js').Settings} settings
|
|
722
|
-
* @returns {boolean}
|
|
723
|
-
*/
|
|
724
|
-
const isUncommentedExport = function (node, sourceCode, opt, settings) {
|
|
725
|
-
// console.log({node});
|
|
726
|
-
// Optimize with ancestor check for esm
|
|
727
|
-
if (opt.esm) {
|
|
728
|
-
if (isPrivate(node) ||
|
|
729
|
-
node.parent && isPrivate(node.parent)) {
|
|
730
|
-
return false;
|
|
731
|
-
}
|
|
732
|
-
const exportNode = getExportAncestor(node);
|
|
733
|
-
// Is export node comment
|
|
734
|
-
if (exportNode && !(0, jsdoccomment_1.findJSDocComment)(exportNode, sourceCode, settings)) {
|
|
735
|
-
return true;
|
|
736
|
-
}
|
|
737
|
-
/**
|
|
738
|
-
* Some typescript types are not in variable map, but inherit exported (interface property and method)
|
|
739
|
-
*/
|
|
740
|
-
if (isExportByAncestor(node) &&
|
|
741
|
-
!(0, jsdoccomment_1.findJSDocComment)(node, sourceCode, settings)) {
|
|
742
|
-
return true;
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
const ast = /** @type {unknown} */ (sourceCode.ast);
|
|
746
|
-
const parseResult = parse(
|
|
747
|
-
/** @type {import('eslint').Rule.Node} */
|
|
748
|
-
(ast), node, opt);
|
|
749
|
-
return isNodeExported(node, /** @type {CreatedNode} */ (parseResult.globalVars), opt);
|
|
750
|
-
};
|
|
751
|
-
exports.default = {
|
|
752
|
-
isUncommentedExport,
|
|
753
|
-
parse,
|
|
754
|
-
};
|