eslint-plugin-jsdoc 50.6.17 → 50.7.1
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/alignTransform.cjs +10 -10
- package/dist/alignTransform.cjs.map +1 -1
- package/dist/exportParser.cjs +141 -135
- package/dist/exportParser.cjs.map +1 -1
- package/dist/generateRule.cjs +10 -12
- package/dist/generateRule.cjs.map +1 -1
- package/dist/getDefaultTagStructureForMode.cjs +73 -73
- package/dist/getDefaultTagStructureForMode.cjs.map +1 -1
- package/dist/getJsdocProcessorPlugin.cjs +121 -110
- package/dist/getJsdocProcessorPlugin.cjs.map +1 -1
- package/dist/index.cjs +17 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/iterateJsdoc.cjs +87 -66
- package/dist/iterateJsdoc.cjs.map +1 -1
- package/dist/jsdocUtils.cjs +144 -142
- package/dist/jsdocUtils.cjs.map +1 -1
- package/dist/rules/checkAlignment.cjs +2 -2
- package/dist/rules/checkAlignment.cjs.map +1 -1
- package/dist/rules/checkExamples.cjs +22 -28
- package/dist/rules/checkExamples.cjs.map +1 -1
- package/dist/rules/checkIndentation.cjs +2 -2
- package/dist/rules/checkIndentation.cjs.map +1 -1
- package/dist/rules/checkLineAlignment.cjs +14 -14
- package/dist/rules/checkLineAlignment.cjs.map +1 -1
- package/dist/rules/checkParamNames.cjs +21 -15
- package/dist/rules/checkParamNames.cjs.map +1 -1
- package/dist/rules/checkPropertyNames.cjs +2 -2
- package/dist/rules/checkPropertyNames.cjs.map +1 -1
- package/dist/rules/checkTagNames.cjs +11 -11
- package/dist/rules/checkTagNames.cjs.map +1 -1
- package/dist/rules/checkTemplateNames.cjs +21 -22
- package/dist/rules/checkTemplateNames.cjs.map +1 -1
- package/dist/rules/checkTypes.cjs +10 -10
- package/dist/rules/checkTypes.cjs.map +1 -1
- package/dist/rules/checkValues.cjs +11 -14
- package/dist/rules/checkValues.cjs.map +1 -1
- package/dist/rules/convertToJsdocComments.cjs +26 -27
- package/dist/rules/convertToJsdocComments.cjs.map +1 -1
- package/dist/rules/emptyTags.cjs +6 -6
- package/dist/rules/emptyTags.cjs.map +1 -1
- package/dist/rules/importsAsDependencies.cjs.map +1 -1
- package/dist/rules/informativeDocs.cjs +12 -12
- package/dist/rules/informativeDocs.cjs.map +1 -1
- package/dist/rules/linesBeforeBlock.cjs +12 -12
- package/dist/rules/linesBeforeBlock.cjs.map +1 -1
- package/dist/rules/matchDescription.cjs +1 -1
- package/dist/rules/matchDescription.cjs.map +1 -1
- package/dist/rules/matchName.cjs +4 -4
- package/dist/rules/matchName.cjs.map +1 -1
- package/dist/rules/multilineBlocks.cjs +10 -10
- package/dist/rules/multilineBlocks.cjs.map +1 -1
- package/dist/rules/noBadBlocks.cjs +3 -3
- package/dist/rules/noBadBlocks.cjs.map +1 -1
- package/dist/rules/noMultiAsterisks.cjs +6 -6
- package/dist/rules/noMultiAsterisks.cjs.map +1 -1
- package/dist/rules/noRestrictedSyntax.cjs +2 -2
- package/dist/rules/noRestrictedSyntax.cjs.map +1 -1
- package/dist/rules/noTypes.cjs.map +1 -1
- package/dist/rules/noUndefinedTypes.cjs +17 -20
- package/dist/rules/noUndefinedTypes.cjs.map +1 -1
- package/dist/rules/requireAsteriskPrefix.cjs +4 -4
- package/dist/rules/requireAsteriskPrefix.cjs.map +1 -1
- package/dist/rules/requireDescription.cjs +2 -2
- package/dist/rules/requireDescription.cjs.map +1 -1
- package/dist/rules/requireDescriptionCompleteSentence.cjs +8 -8
- package/dist/rules/requireDescriptionCompleteSentence.cjs.map +1 -1
- package/dist/rules/requireFileOverview.cjs +6 -6
- package/dist/rules/requireFileOverview.cjs.map +1 -1
- package/dist/rules/requireHyphenBeforeParamDescription.cjs +1 -4
- package/dist/rules/requireHyphenBeforeParamDescription.cjs.map +1 -1
- package/dist/rules/requireJsdoc.cjs +19 -19
- package/dist/rules/requireJsdoc.cjs.map +1 -1
- package/dist/rules/requireParam.cjs +12 -12
- package/dist/rules/requireParam.cjs.map +1 -1
- package/dist/rules/requireProperty.cjs +1 -1
- package/dist/rules/requireProperty.cjs.map +1 -1
- package/dist/rules/requireReturns.cjs +3 -3
- package/dist/rules/requireReturns.cjs.map +1 -1
- package/dist/rules/requireReturnsCheck.cjs +1 -1
- package/dist/rules/requireReturnsCheck.cjs.map +1 -1
- package/dist/rules/requireReturnsDescription.cjs +1 -1
- package/dist/rules/requireReturnsDescription.cjs.map +1 -1
- package/dist/rules/requireTemplate.cjs +16 -15
- package/dist/rules/requireTemplate.cjs.map +1 -1
- package/dist/rules/requireYields.cjs +4 -4
- package/dist/rules/requireYields.cjs.map +1 -1
- package/dist/rules/requireYieldsCheck.cjs +6 -6
- package/dist/rules/requireYieldsCheck.cjs.map +1 -1
- package/dist/rules/sortTags.cjs +13 -13
- package/dist/rules/sortTags.cjs.map +1 -1
- package/dist/rules/tagLines.cjs +11 -11
- package/dist/rules/tagLines.cjs.map +1 -1
- package/dist/rules/textEscaping.cjs +2 -2
- package/dist/rules/textEscaping.cjs.map +1 -1
- package/dist/rules/validTypes.cjs +15 -15
- package/dist/rules/validTypes.cjs.map +1 -1
- package/dist/tagNames.cjs +1 -1
- package/dist/tagNames.cjs.map +1 -1
- package/dist/utils/hasReturnValue.cjs +176 -176
- package/dist/utils/hasReturnValue.cjs.map +1 -1
- package/eslint.config.js +36 -32
- package/package.json +29 -29
- package/pnpm-workspace.yaml +1 -0
- package/src/alignTransform.js +15 -15
- package/src/exportParser.js +386 -373
- package/src/getDefaultTagStructureForMode.js +45 -45
- package/src/getJsdocProcessorPlugin.js +175 -128
- package/src/index.js +66 -37
- package/src/iterateJsdoc.js +61 -28
- package/src/jsdocUtils.js +354 -338
- package/src/rules/checkAlignment.js +2 -2
- package/src/rules/checkExamples.js +16 -20
- package/src/rules/checkIndentation.js +2 -2
- package/src/rules/checkLineAlignment.js +10 -10
- package/src/rules/checkParamNames.js +22 -14
- package/src/rules/checkPropertyNames.js +1 -1
- package/src/rules/checkTagNames.js +7 -7
- package/src/rules/checkTemplateNames.js +52 -38
- package/src/rules/checkTypes.js +7 -7
- package/src/rules/checkValues.js +16 -17
- package/src/rules/convertToJsdocComments.js +47 -37
- package/src/rules/emptyTags.js +14 -7
- package/src/rules/importsAsDependencies.js +3 -1
- package/src/rules/informativeDocs.js +58 -58
- package/src/rules/linesBeforeBlock.js +25 -17
- package/src/rules/matchDescription.js +1 -1
- package/src/rules/matchName.js +2 -2
- package/src/rules/multilineBlocks.js +10 -10
- package/src/rules/noBadBlocks.js +3 -3
- package/src/rules/noMultiAsterisks.js +4 -4
- package/src/rules/noRestrictedSyntax.js +1 -1
- package/src/rules/noTypes.js +1 -1
- package/src/rules/noUndefinedTypes.js +29 -23
- package/src/rules/requireAsteriskPrefix.js +3 -3
- package/src/rules/requireDescription.js +1 -1
- package/src/rules/requireDescriptionCompleteSentence.js +6 -6
- package/src/rules/requireFileOverview.js +3 -3
- package/src/rules/requireHyphenBeforeParamDescription.js +2 -5
- package/src/rules/requireJsdoc.js +14 -14
- package/src/rules/requireParam.js +9 -9
- package/src/rules/requireProperty.js +1 -1
- package/src/rules/requireReturns.js +1 -1
- package/src/rules/requireReturnsCheck.js +1 -1
- package/src/rules/requireReturnsDescription.js +1 -1
- package/src/rules/requireTemplate.js +59 -38
- package/src/rules/requireYields.js +3 -3
- package/src/rules/requireYieldsCheck.js +1 -1
- package/src/rules/sortTags.js +7 -7
- package/src/rules/tagLines.js +8 -8
- package/src/rules/textEscaping.js +2 -0
- package/src/rules/validTypes.js +29 -29
- package/src/tagNames.js +2 -2
- package/src/utils/hasReturnValue.js +298 -283
package/src/exportParser.js
CHANGED
|
@@ -48,7 +48,8 @@ const getSymbolValue = function (symbol) {
|
|
|
48
48
|
if (symbol.type === 'literal') {
|
|
49
49
|
return /** @type {ValueObject} */ (symbol.value).value;
|
|
50
50
|
}
|
|
51
|
-
/* c8 ignore next */
|
|
51
|
+
/* c8 ignore next 2 */
|
|
52
|
+
// eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
|
|
52
53
|
return null;
|
|
53
54
|
};
|
|
54
55
|
|
|
@@ -123,172 +124,180 @@ const getSymbol = function (node, globals, scope, opt) {
|
|
|
123
124
|
const opts = opt || {};
|
|
124
125
|
/* c8 ignore next */
|
|
125
126
|
switch (node.type) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
127
|
+
/* c8 ignore next 4 -- No longer needed? */
|
|
128
|
+
case 'ArrowFunctionExpression':
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
/** @type {import('eslint').Rule.Node} */
|
|
133
|
-
(node.object),
|
|
134
|
-
globals,
|
|
135
|
-
scope,
|
|
136
|
-
opts,
|
|
137
|
-
);
|
|
138
|
-
const propertySymbol = getSymbol(
|
|
139
|
-
/** @type {import('eslint').Rule.Node} */
|
|
140
|
-
(node.property),
|
|
141
|
-
globals,
|
|
142
|
-
scope,
|
|
143
|
-
{
|
|
144
|
-
simpleIdentifier: !node.computed,
|
|
145
|
-
},
|
|
146
|
-
);
|
|
147
|
-
const propertyValue = getSymbolValue(propertySymbol);
|
|
130
|
+
// Fallthrough
|
|
131
|
+
case 'ClassDeclaration':
|
|
148
132
|
|
|
149
|
-
|
|
150
|
-
if (obj && propertyValue && obj.props[propertyValue]) {
|
|
151
|
-
const block = obj.props[propertyValue];
|
|
133
|
+
case 'FunctionDeclaration':
|
|
152
134
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
135
|
+
case 'FunctionExpression':
|
|
136
|
+
case 'TSEnumDeclaration':
|
|
137
|
+
case 'TSInterfaceDeclaration':
|
|
138
|
+
case 'TSTypeAliasDeclaration': {
|
|
139
|
+
const val = createNode();
|
|
140
|
+
val.props.prototype = createNode();
|
|
141
|
+
val.props.prototype.type = 'object';
|
|
142
|
+
val.type = 'object';
|
|
143
|
+
val.value = node;
|
|
159
144
|
|
|
160
|
-
return
|
|
145
|
+
return val;
|
|
161
146
|
}
|
|
162
|
-
*/
|
|
163
|
-
debug(`MemberExpression: Missing property ${
|
|
164
|
-
/** @type {import('estree').PrivateIdentifier} */ (node.property).name
|
|
165
|
-
}`);
|
|
166
|
-
/* c8 ignore next 2 */
|
|
167
|
-
return null;
|
|
168
|
-
}
|
|
169
147
|
|
|
170
|
-
|
|
171
|
-
|
|
148
|
+
case 'AssignmentExpression': {
|
|
149
|
+
return createSymbol(
|
|
172
150
|
/** @type {import('eslint').Rule.Node} */
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
case 'TSTypeAliasDeclaration':
|
|
182
|
-
// Fallthrough
|
|
183
|
-
case 'TSEnumDeclaration':
|
|
184
|
-
case 'TSInterfaceDeclaration':
|
|
185
|
-
case 'ClassDeclaration':
|
|
186
|
-
case 'FunctionExpression': case 'FunctionDeclaration':
|
|
187
|
-
case 'ArrowFunctionExpression': {
|
|
188
|
-
const val = createNode();
|
|
189
|
-
val.props.prototype = createNode();
|
|
190
|
-
val.props.prototype.type = 'object';
|
|
191
|
-
val.type = 'object';
|
|
192
|
-
val.value = node;
|
|
193
|
-
|
|
194
|
-
return val;
|
|
195
|
-
}
|
|
151
|
+
(node.left),
|
|
152
|
+
globals,
|
|
153
|
+
/** @type {import('eslint').Rule.Node} */
|
|
154
|
+
(node.right),
|
|
155
|
+
scope,
|
|
156
|
+
opts,
|
|
157
|
+
);
|
|
158
|
+
}
|
|
196
159
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
scope,
|
|
205
|
-
opts,
|
|
206
|
-
);
|
|
207
|
-
}
|
|
160
|
+
case 'ClassBody': {
|
|
161
|
+
const val = createNode();
|
|
162
|
+
for (const method of node.body) {
|
|
163
|
+
// StaticBlock
|
|
164
|
+
if (!('key' in method)) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
208
167
|
|
|
209
|
-
|
|
210
|
-
const val = createNode();
|
|
211
|
-
for (const method of node.body) {
|
|
212
|
-
if (!('key' in method)) { // StaticBlock
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
val.props[
|
|
168
|
+
val.props[
|
|
216
169
|
/** @type {import('estree').Identifier} */ (
|
|
217
170
|
/** @type {import('estree').MethodDefinition} */ (
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
171
|
+
method
|
|
172
|
+
).key
|
|
173
|
+
).name
|
|
174
|
+
] = createNode();
|
|
175
|
+
/** @type {{[key: string]: CreatedNode}} */ (val.props)[
|
|
223
176
|
/** @type {import('estree').Identifier} */ (
|
|
224
177
|
/** @type {import('estree').MethodDefinition} */ (
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
178
|
+
method
|
|
179
|
+
).key
|
|
180
|
+
).name
|
|
181
|
+
].type = 'object';
|
|
182
|
+
/** @type {{[key: string]: CreatedNode}} */ (val.props)[
|
|
230
183
|
/** @type {import('estree').Identifier} */ (
|
|
231
184
|
/** @type {import('estree').MethodDefinition} */ (
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
185
|
+
method
|
|
186
|
+
).key
|
|
187
|
+
).name
|
|
188
|
+
].value = /** @type {import('eslint').Rule.Node} */ (
|
|
236
189
|
/** @type {import('estree').MethodDefinition} */ (method).value
|
|
237
|
-
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
val.type = 'object';
|
|
194
|
+
val.value = node.parent;
|
|
195
|
+
|
|
196
|
+
return val;
|
|
238
197
|
}
|
|
239
198
|
|
|
240
|
-
|
|
241
|
-
|
|
199
|
+
case 'ClassExpression': {
|
|
200
|
+
return getSymbol(
|
|
201
|
+
/** @type {import('eslint').Rule.Node} */
|
|
202
|
+
(node.body),
|
|
203
|
+
globals,
|
|
204
|
+
scope,
|
|
205
|
+
opts,
|
|
206
|
+
);
|
|
207
|
+
}
|
|
242
208
|
|
|
243
|
-
|
|
244
|
-
|
|
209
|
+
case 'Identifier': {
|
|
210
|
+
return getIdentifier(node, globals, scope, opts);
|
|
211
|
+
}
|
|
245
212
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if ([
|
|
251
|
-
// typescript-eslint, espree, acorn, etc.
|
|
252
|
-
'SpreadElement',
|
|
213
|
+
case 'Literal': {
|
|
214
|
+
const val = createNode();
|
|
215
|
+
val.type = 'literal';
|
|
216
|
+
val.value = node;
|
|
253
217
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
].includes(prop.type)) {
|
|
257
|
-
continue;
|
|
258
|
-
}
|
|
218
|
+
return val;
|
|
219
|
+
}
|
|
259
220
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
),
|
|
221
|
+
case 'MemberExpression': {
|
|
222
|
+
const obj = getSymbol(
|
|
223
|
+
/** @type {import('eslint').Rule.Node} */
|
|
224
|
+
(node.object),
|
|
265
225
|
globals,
|
|
266
226
|
scope,
|
|
267
227
|
opts,
|
|
268
228
|
);
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
229
|
+
const propertySymbol = getSymbol(
|
|
230
|
+
/** @type {import('eslint').Rule.Node} */
|
|
231
|
+
(node.property),
|
|
232
|
+
globals,
|
|
233
|
+
scope,
|
|
234
|
+
{
|
|
235
|
+
simpleIdentifier: !node.computed,
|
|
236
|
+
},
|
|
237
|
+
);
|
|
238
|
+
const propertyValue = getSymbolValue(propertySymbol);
|
|
239
|
+
|
|
240
|
+
/* c8 ignore else */
|
|
241
|
+
if (obj && propertyValue && obj.props[propertyValue]) {
|
|
242
|
+
const block = obj.props[propertyValue];
|
|
243
|
+
|
|
244
|
+
return block;
|
|
277
245
|
}
|
|
246
|
+
/* c8 ignore next 11 */
|
|
247
|
+
/*
|
|
248
|
+
if (opts.createMissingProps && propertyValue) {
|
|
249
|
+
obj.props[propertyValue] = createNode();
|
|
250
|
+
|
|
251
|
+
return obj.props[propertyValue];
|
|
252
|
+
}
|
|
253
|
+
*/
|
|
254
|
+
// eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
|
|
255
|
+
debug(`MemberExpression: Missing property ${
|
|
256
|
+
/** @type {import('estree').PrivateIdentifier} */ (node.property).name
|
|
257
|
+
}`);
|
|
258
|
+
/* c8 ignore next 2 */
|
|
259
|
+
return null;
|
|
278
260
|
}
|
|
279
261
|
|
|
280
|
-
|
|
281
|
-
|
|
262
|
+
case 'ObjectExpression': {
|
|
263
|
+
const val = createNode();
|
|
264
|
+
val.type = 'object';
|
|
265
|
+
for (const prop of node.properties) {
|
|
266
|
+
if ([
|
|
267
|
+
// @babel/eslint-parser
|
|
268
|
+
'ExperimentalSpreadProperty',
|
|
282
269
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
270
|
+
// typescript-eslint, espree, acorn, etc.
|
|
271
|
+
'SpreadElement',
|
|
272
|
+
].includes(prop.type)) {
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
287
275
|
|
|
288
|
-
|
|
289
|
-
|
|
276
|
+
const propVal = getSymbol(
|
|
277
|
+
/** @type {import('eslint').Rule.Node} */ (
|
|
278
|
+
/** @type {import('estree').Property} */
|
|
279
|
+
(prop).value
|
|
280
|
+
),
|
|
281
|
+
globals,
|
|
282
|
+
scope,
|
|
283
|
+
opts,
|
|
284
|
+
);
|
|
285
|
+
/* c8 ignore next 8 */
|
|
286
|
+
if (propVal) {
|
|
287
|
+
val.props[
|
|
288
|
+
/** @type {import('estree').PrivateIdentifier} */
|
|
289
|
+
(
|
|
290
|
+
/** @type {import('estree').Property} */ (prop).key
|
|
291
|
+
).name
|
|
292
|
+
] = propVal;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return val;
|
|
297
|
+
}
|
|
290
298
|
}
|
|
291
|
-
/* c8 ignore next */
|
|
299
|
+
/* c8 ignore next 2 */
|
|
300
|
+
// eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
|
|
292
301
|
return null;
|
|
293
302
|
};
|
|
294
303
|
|
|
@@ -317,81 +326,84 @@ createSymbol = function (node, globals, value, scope, isGlobal) {
|
|
|
317
326
|
|
|
318
327
|
let symbol;
|
|
319
328
|
switch (node.type) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
329
|
+
case 'ClassDeclaration':
|
|
330
|
+
/* c8 ignore next */
|
|
331
|
+
// @ts-expect-error TS OK
|
|
332
|
+
// Fall through
|
|
333
|
+
case 'FunctionDeclaration': case 'TSEnumDeclaration':
|
|
334
|
+
/* c8 ignore next */
|
|
335
|
+
// @ts-expect-error TS OK
|
|
336
|
+
// Fall through
|
|
337
|
+
case 'TSInterfaceDeclaration': case 'TSTypeAliasDeclaration': {
|
|
338
|
+
const nde = /** @type {import('estree').ClassDeclaration} */ (node);
|
|
339
|
+
/* c8 ignore else */
|
|
340
|
+
if (nde.id && nde.id.type === 'Identifier') {
|
|
341
|
+
return createSymbol(
|
|
333
342
|
/** @type {import('eslint').Rule.Node} */ (nde.id),
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
343
|
+
globals,
|
|
344
|
+
node,
|
|
345
|
+
globals,
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
/* c8 ignore next 3 */
|
|
349
|
+
// eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
|
|
350
|
+
break;
|
|
338
351
|
}
|
|
339
|
-
/* c8 ignore next 2 */
|
|
340
|
-
break;
|
|
341
|
-
}
|
|
342
352
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
353
|
+
case 'Identifier': {
|
|
354
|
+
const nde = /** @type {import('estree').Identifier} */ (node);
|
|
355
|
+
if (value) {
|
|
356
|
+
const valueSymbol = getSymbol(value, globals, block);
|
|
357
|
+
/* c8 ignore else */
|
|
358
|
+
if (valueSymbol) {
|
|
359
|
+
createBlockSymbol(block, nde.name, valueSymbol, globals, isGlobal);
|
|
360
|
+
|
|
361
|
+
return block.props[nde.name];
|
|
362
|
+
}
|
|
363
|
+
/* c8 ignore next 2 */
|
|
364
|
+
// eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
|
|
365
|
+
debug('Identifier: Missing value symbol for %s', nde.name);
|
|
366
|
+
} else {
|
|
367
|
+
createBlockSymbol(block, nde.name, createNode(), globals, isGlobal);
|
|
350
368
|
|
|
351
369
|
return block.props[nde.name];
|
|
352
370
|
}
|
|
353
|
-
/* c8 ignore next */
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
createBlockSymbol(block, nde.name, createNode(), globals, isGlobal);
|
|
357
|
-
|
|
358
|
-
return block.props[nde.name];
|
|
371
|
+
/* c8 ignore next 3 */
|
|
372
|
+
// eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
|
|
373
|
+
break;
|
|
359
374
|
}
|
|
360
|
-
/* c8 ignore next 2 */
|
|
361
|
-
break;
|
|
362
|
-
}
|
|
363
375
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
376
|
+
case 'MemberExpression': {
|
|
377
|
+
const nde = /** @type {import('estree').MemberExpression} */ (node);
|
|
378
|
+
symbol = getSymbol(
|
|
367
379
|
/** @type {import('eslint').Rule.Node} */ (nde.object), globals, block,
|
|
368
|
-
|
|
380
|
+
);
|
|
369
381
|
|
|
370
|
-
|
|
382
|
+
const propertySymbol = getSymbol(
|
|
371
383
|
/** @type {import('eslint').Rule.Node} */ (nde.property),
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
384
|
+
globals,
|
|
385
|
+
block,
|
|
386
|
+
{
|
|
387
|
+
simpleIdentifier: !nde.computed,
|
|
388
|
+
},
|
|
389
|
+
);
|
|
390
|
+
const propertyValue = getSymbolValue(propertySymbol);
|
|
391
|
+
if (symbol && propertyValue) {
|
|
392
|
+
createBlockSymbol(symbol, propertyValue, getSymbol(
|
|
381
393
|
/** @type {import('eslint').Rule.Node} */
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
394
|
+
(value), globals, block,
|
|
395
|
+
), globals, isGlobal);
|
|
396
|
+
return symbol.props[propertyValue];
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
debug(
|
|
400
|
+
'MemberExpression: Missing symbol: %s',
|
|
401
|
+
/** @type {import('estree').Identifier} */ (
|
|
402
|
+
nde.property
|
|
403
|
+
).name,
|
|
404
|
+
);
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
395
407
|
}
|
|
396
408
|
|
|
397
409
|
return null;
|
|
@@ -406,63 +418,63 @@ createSymbol = function (node, globals, value, scope, isGlobal) {
|
|
|
406
418
|
*/
|
|
407
419
|
const initVariables = function (node, globals, opts) {
|
|
408
420
|
switch (node.type) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
421
|
+
case 'ExportNamedDeclaration': {
|
|
422
|
+
if (node.declaration) {
|
|
423
|
+
initVariables(
|
|
412
424
|
/** @type {import('eslint').Rule.Node} */
|
|
413
|
-
|
|
425
|
+
(node.declaration),
|
|
426
|
+
globals,
|
|
427
|
+
opts,
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
case 'ExpressionStatement': {
|
|
435
|
+
initVariables(
|
|
436
|
+
/** @type {import('eslint').Rule.Node} */
|
|
437
|
+
(node.expression),
|
|
414
438
|
globals,
|
|
415
439
|
opts,
|
|
416
440
|
);
|
|
441
|
+
break;
|
|
417
442
|
}
|
|
418
443
|
|
|
419
|
-
|
|
420
|
-
|
|
444
|
+
case 'Program': {
|
|
445
|
+
for (const childNode of node.body) {
|
|
446
|
+
initVariables(
|
|
447
|
+
/** @type {import('eslint').Rule.Node} */
|
|
448
|
+
(childNode),
|
|
449
|
+
globals,
|
|
450
|
+
opts,
|
|
451
|
+
);
|
|
452
|
+
}
|
|
421
453
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
/** @type {import('eslint').Rule.Node} */
|
|
425
|
-
(node.expression),
|
|
426
|
-
globals,
|
|
427
|
-
opts,
|
|
428
|
-
);
|
|
429
|
-
break;
|
|
430
|
-
}
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
431
456
|
|
|
432
|
-
|
|
433
|
-
|
|
457
|
+
case 'VariableDeclaration': {
|
|
458
|
+
for (const declaration of node.declarations) {
|
|
434
459
|
// let and const
|
|
435
|
-
|
|
460
|
+
const symbol = createSymbol(
|
|
436
461
|
/** @type {import('eslint').Rule.Node} */
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
462
|
+
(declaration.id),
|
|
463
|
+
globals,
|
|
464
|
+
null,
|
|
465
|
+
globals,
|
|
466
|
+
);
|
|
467
|
+
if (opts.initWindow && node.kind === 'var' && globals.props.window) {
|
|
443
468
|
// If var, also add to window
|
|
444
|
-
|
|
469
|
+
globals.props.window.props[
|
|
445
470
|
/** @type {import('estree').Identifier} */
|
|
446
|
-
|
|
447
|
-
|
|
471
|
+
(declaration.id).name
|
|
472
|
+
] = symbol;
|
|
473
|
+
}
|
|
448
474
|
}
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
break;
|
|
452
|
-
}
|
|
453
475
|
|
|
454
|
-
|
|
455
|
-
if (node.declaration) {
|
|
456
|
-
initVariables(
|
|
457
|
-
/** @type {import('eslint').Rule.Node} */
|
|
458
|
-
(node.declaration),
|
|
459
|
-
globals,
|
|
460
|
-
opts,
|
|
461
|
-
);
|
|
476
|
+
break;
|
|
462
477
|
}
|
|
463
|
-
|
|
464
|
-
break;
|
|
465
|
-
}
|
|
466
478
|
}
|
|
467
479
|
};
|
|
468
480
|
|
|
@@ -482,168 +494,169 @@ const mapVariables = function (node, globals, opt, isExport) {
|
|
|
482
494
|
const opts = opt || {};
|
|
483
495
|
/* c8 ignore next */
|
|
484
496
|
switch (node.type) {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
497
|
+
case 'AssignmentExpression': {
|
|
498
|
+
createSymbol(
|
|
499
|
+
/** @type {import('eslint').Rule.Node} */
|
|
500
|
+
(node.left),
|
|
501
|
+
globals,
|
|
502
|
+
/** @type {import('eslint').Rule.Node} */
|
|
503
|
+
(node.right),
|
|
504
|
+
);
|
|
505
|
+
break;
|
|
488
506
|
}
|
|
489
507
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
508
|
+
case 'ClassDeclaration': {
|
|
509
|
+
createSymbol(
|
|
510
|
+
/** @type {import('eslint').Rule.Node|null} */ (node.id),
|
|
511
|
+
globals,
|
|
512
|
+
/** @type {import('eslint').Rule.Node} */ (node.body),
|
|
494
513
|
globals,
|
|
495
|
-
opts,
|
|
496
514
|
);
|
|
515
|
+
break;
|
|
497
516
|
}
|
|
498
517
|
|
|
499
|
-
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
case 'ExpressionStatement': {
|
|
503
|
-
mapVariables(
|
|
504
|
-
/** @type {import('eslint').Rule.Node} */
|
|
505
|
-
(node.expression),
|
|
506
|
-
globals,
|
|
507
|
-
opts,
|
|
508
|
-
);
|
|
509
|
-
break;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
case 'AssignmentExpression': {
|
|
513
|
-
createSymbol(
|
|
514
|
-
/** @type {import('eslint').Rule.Node} */
|
|
515
|
-
(node.left),
|
|
516
|
-
globals,
|
|
517
|
-
/** @type {import('eslint').Rule.Node} */
|
|
518
|
-
(node.right),
|
|
519
|
-
);
|
|
520
|
-
break;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
case 'VariableDeclaration': {
|
|
524
|
-
for (const declaration of node.declarations) {
|
|
525
|
-
const isGlobal = Boolean(opts.initWindow && node.kind === 'var' && globals.props.window);
|
|
518
|
+
case 'ExportDefaultDeclaration': {
|
|
526
519
|
const symbol = createSymbol(
|
|
527
|
-
|
|
528
|
-
(declaration
|
|
520
|
+
/** @type {import('eslint').Rule.Node} */
|
|
521
|
+
(node.declaration),
|
|
529
522
|
globals,
|
|
530
523
|
/** @type {import('eslint').Rule.Node} */
|
|
531
|
-
(declaration
|
|
532
|
-
globals,
|
|
533
|
-
isGlobal,
|
|
524
|
+
(node.declaration),
|
|
534
525
|
);
|
|
535
|
-
if (symbol
|
|
526
|
+
if (symbol) {
|
|
536
527
|
symbol.exported = true;
|
|
528
|
+
/* c8 ignore next 6 */
|
|
529
|
+
} else {
|
|
530
|
+
// if (!node.id) {
|
|
531
|
+
globals.ANONYMOUS_DEFAULT = /** @type {import('eslint').Rule.Node} */ (
|
|
532
|
+
node.declaration
|
|
533
|
+
);
|
|
537
534
|
}
|
|
535
|
+
|
|
536
|
+
break;
|
|
538
537
|
}
|
|
539
538
|
|
|
540
|
-
|
|
541
|
-
|
|
539
|
+
case 'ExportNamedDeclaration': {
|
|
540
|
+
if (node.declaration) {
|
|
541
|
+
if (node.declaration.type === 'VariableDeclaration') {
|
|
542
|
+
mapVariables(
|
|
543
|
+
/** @type {import('eslint').Rule.Node} */
|
|
544
|
+
(node.declaration),
|
|
545
|
+
globals,
|
|
546
|
+
opts,
|
|
547
|
+
true,
|
|
548
|
+
);
|
|
549
|
+
} else {
|
|
550
|
+
const symbol = createSymbol(
|
|
551
|
+
/** @type {import('eslint').Rule.Node} */
|
|
552
|
+
(node.declaration),
|
|
553
|
+
globals,
|
|
554
|
+
/** @type {import('eslint').Rule.Node} */
|
|
555
|
+
(node.declaration),
|
|
556
|
+
);
|
|
557
|
+
/* c8 ignore next 3 */
|
|
558
|
+
if (symbol) {
|
|
559
|
+
symbol.exported = true;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
542
563
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
/* c8 ignore next 10 */
|
|
546
|
-
if (/** @type {import('estree').Identifier} */ (node.id).type === 'Identifier') {
|
|
547
|
-
createSymbol(
|
|
564
|
+
for (const specifier of node.specifiers) {
|
|
565
|
+
mapVariables(
|
|
548
566
|
/** @type {import('eslint').Rule.Node} */
|
|
549
|
-
|
|
567
|
+
(specifier),
|
|
568
|
+
globals,
|
|
569
|
+
opts,
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
break;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
case 'ExportSpecifier': {
|
|
577
|
+
const symbol = getSymbol(
|
|
578
|
+
/** @type {import('eslint').Rule.Node} */
|
|
579
|
+
(node.local),
|
|
550
580
|
globals,
|
|
551
|
-
node,
|
|
552
581
|
globals,
|
|
553
|
-
true,
|
|
554
582
|
);
|
|
555
|
-
|
|
583
|
+
/* c8 ignore next 3 */
|
|
584
|
+
if (symbol) {
|
|
585
|
+
symbol.exported = true;
|
|
586
|
+
}
|
|
556
587
|
|
|
557
|
-
|
|
558
|
-
|
|
588
|
+
break;
|
|
589
|
+
}
|
|
559
590
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
/** @type {import('eslint').Rule.Node} */
|
|
563
|
-
(node.declaration),
|
|
564
|
-
globals,
|
|
591
|
+
case 'ExpressionStatement': {
|
|
592
|
+
mapVariables(
|
|
565
593
|
/** @type {import('eslint').Rule.Node} */
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
symbol.exported = true;
|
|
570
|
-
/* c8 ignore next 6 */
|
|
571
|
-
} else {
|
|
572
|
-
// if (!node.id) {
|
|
573
|
-
globals.ANONYMOUS_DEFAULT = /** @type {import('eslint').Rule.Node} */ (
|
|
574
|
-
node.declaration
|
|
594
|
+
(node.expression),
|
|
595
|
+
globals,
|
|
596
|
+
opts,
|
|
575
597
|
);
|
|
598
|
+
break;
|
|
576
599
|
}
|
|
577
600
|
|
|
578
|
-
|
|
579
|
-
}
|
|
601
|
+
case 'FunctionDeclaration':
|
|
580
602
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
if (node.
|
|
603
|
+
case 'TSTypeAliasDeclaration': {
|
|
604
|
+
/* c8 ignore next 10 */
|
|
605
|
+
if (/** @type {import('estree').Identifier} */ (node.id).type === 'Identifier') {
|
|
606
|
+
createSymbol(
|
|
607
|
+
/** @type {import('eslint').Rule.Node} */
|
|
608
|
+
(node.id),
|
|
609
|
+
globals,
|
|
610
|
+
node,
|
|
611
|
+
globals,
|
|
612
|
+
true,
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
break;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
case 'Program': {
|
|
620
|
+
if (opts.ancestorsOnly) {
|
|
621
|
+
return false;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
for (const childNode of node.body) {
|
|
584
625
|
mapVariables(
|
|
585
|
-
|
|
586
|
-
(
|
|
626
|
+
/** @type {import('eslint').Rule.Node} */
|
|
627
|
+
(childNode),
|
|
587
628
|
globals,
|
|
588
629
|
opts,
|
|
589
|
-
true,
|
|
590
630
|
);
|
|
591
|
-
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
break;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
case 'VariableDeclaration': {
|
|
637
|
+
for (const declaration of node.declarations) {
|
|
638
|
+
const isGlobal = Boolean(opts.initWindow && node.kind === 'var' && globals.props.window);
|
|
592
639
|
const symbol = createSymbol(
|
|
593
|
-
|
|
594
|
-
(
|
|
640
|
+
/** @type {import('eslint').Rule.Node} */
|
|
641
|
+
(declaration.id),
|
|
595
642
|
globals,
|
|
596
643
|
/** @type {import('eslint').Rule.Node} */
|
|
597
|
-
(
|
|
644
|
+
(declaration.init),
|
|
645
|
+
globals,
|
|
646
|
+
isGlobal,
|
|
598
647
|
);
|
|
599
|
-
|
|
600
|
-
if (symbol) {
|
|
648
|
+
if (symbol && isExport) {
|
|
601
649
|
symbol.exported = true;
|
|
602
650
|
}
|
|
603
651
|
}
|
|
604
|
-
}
|
|
605
652
|
|
|
606
|
-
|
|
607
|
-
mapVariables(
|
|
608
|
-
/** @type {import('eslint').Rule.Node} */
|
|
609
|
-
(specifier),
|
|
610
|
-
globals,
|
|
611
|
-
opts,
|
|
612
|
-
);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
break;
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
case 'ExportSpecifier': {
|
|
619
|
-
const symbol = getSymbol(
|
|
620
|
-
/** @type {import('eslint').Rule.Node} */
|
|
621
|
-
(node.local),
|
|
622
|
-
globals,
|
|
623
|
-
globals,
|
|
624
|
-
);
|
|
625
|
-
/* c8 ignore next 3 */
|
|
626
|
-
if (symbol) {
|
|
627
|
-
symbol.exported = true;
|
|
653
|
+
break;
|
|
628
654
|
}
|
|
629
655
|
|
|
630
|
-
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
case 'ClassDeclaration': {
|
|
634
|
-
createSymbol(
|
|
635
|
-
/** @type {import('eslint').Rule.Node|null} */ (node.id),
|
|
636
|
-
globals,
|
|
637
|
-
/** @type {import('eslint').Rule.Node} */ (node.body),
|
|
638
|
-
globals,
|
|
639
|
-
);
|
|
640
|
-
break;
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
default: {
|
|
656
|
+
default: {
|
|
644
657
|
/* c8 ignore next */
|
|
645
|
-
|
|
646
|
-
|
|
658
|
+
return false;
|
|
659
|
+
}
|
|
647
660
|
}
|
|
648
661
|
|
|
649
662
|
return true;
|
|
@@ -698,10 +711,10 @@ const findNode = function (node, block, cache) {
|
|
|
698
711
|
};
|
|
699
712
|
|
|
700
713
|
const exportTypes = new Set([
|
|
701
|
-
'
|
|
714
|
+
'ExportDefaultDeclaration', 'ExportNamedDeclaration',
|
|
702
715
|
]);
|
|
703
716
|
const ignorableNestedTypes = new Set([
|
|
704
|
-
'
|
|
717
|
+
'ArrowFunctionExpression', 'FunctionDeclaration', 'FunctionExpression',
|
|
705
718
|
]);
|
|
706
719
|
|
|
707
720
|
/**
|
|
@@ -730,25 +743,25 @@ const getExportAncestor = function (nde) {
|
|
|
730
743
|
};
|
|
731
744
|
|
|
732
745
|
const canBeExportedByAncestorType = new Set([
|
|
733
|
-
'TSPropertySignature',
|
|
734
|
-
'TSMethodSignature',
|
|
735
746
|
'ClassProperty',
|
|
736
|
-
'PropertyDefinition',
|
|
737
747
|
'Method',
|
|
748
|
+
'PropertyDefinition',
|
|
749
|
+
'TSMethodSignature',
|
|
750
|
+
'TSPropertySignature',
|
|
738
751
|
]);
|
|
739
752
|
|
|
740
753
|
const canExportChildrenType = new Set([
|
|
754
|
+
'ClassBody',
|
|
755
|
+
'ClassDeclaration',
|
|
756
|
+
'ClassDefinition',
|
|
757
|
+
'ClassExpression',
|
|
758
|
+
'Program',
|
|
741
759
|
'TSInterfaceBody',
|
|
742
760
|
'TSInterfaceDeclaration',
|
|
743
|
-
'TSTypeLiteral',
|
|
744
761
|
'TSTypeAliasDeclaration',
|
|
762
|
+
'TSTypeLiteral',
|
|
745
763
|
'TSTypeParameterInstantiation',
|
|
746
764
|
'TSTypeReference',
|
|
747
|
-
'ClassDeclaration',
|
|
748
|
-
'ClassBody',
|
|
749
|
-
'ClassDefinition',
|
|
750
|
-
'ClassExpression',
|
|
751
|
-
'Program',
|
|
752
765
|
]);
|
|
753
766
|
|
|
754
767
|
/**
|
|
@@ -891,8 +904,8 @@ const parse = function (ast, node, opt) {
|
|
|
891
904
|
};
|
|
892
905
|
|
|
893
906
|
const accessibilityNodes = new Set([
|
|
894
|
-
'PropertyDefinition',
|
|
895
907
|
'MethodDefinition',
|
|
908
|
+
'PropertyDefinition',
|
|
896
909
|
]);
|
|
897
910
|
|
|
898
911
|
/**
|