eslint-plugin-jsdoc 52.0.4 → 53.0.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/WarnSettings.cjs +18 -35
- package/dist/WarnSettings.cjs.map +1 -1
- package/dist/WarnSettings.js +20 -0
- package/dist/WarnSettings.js.map +1 -0
- package/dist/_virtual/rolldown_runtime.cjs +32 -0
- package/dist/_virtual/rolldown_runtime.js +11 -0
- package/dist/alignTransform.cjs +224 -305
- package/dist/alignTransform.cjs.map +1 -1
- package/dist/alignTransform.js +241 -0
- package/dist/alignTransform.js.map +1 -0
- package/dist/defaultTagOrder.cjs +132 -43
- package/dist/defaultTagOrder.cjs.map +1 -1
- package/dist/defaultTagOrder.js +134 -0
- package/dist/defaultTagOrder.js.map +1 -0
- package/dist/exportParser.cjs +478 -696
- package/dist/exportParser.cjs.map +1 -1
- package/dist/exportParser.js +518 -0
- package/dist/exportParser.js.map +1 -0
- package/dist/getDefaultTagStructureForMode.cjs +184 -288
- package/dist/getDefaultTagStructureForMode.cjs.map +1 -1
- package/dist/getDefaultTagStructureForMode.js +188 -0
- package/dist/getDefaultTagStructureForMode.js.map +1 -0
- package/dist/getJsdocProcessorPlugin.cjs +364 -550
- package/dist/getJsdocProcessorPlugin.cjs.map +1 -1
- package/dist/getJsdocProcessorPlugin.d.cts +70 -0
- package/dist/getJsdocProcessorPlugin.d.cts.map +1 -0
- package/dist/getJsdocProcessorPlugin.d.ts +68 -65
- package/dist/getJsdocProcessorPlugin.d.ts.map +1 -1
- package/dist/getJsdocProcessorPlugin.js +383 -0
- package/dist/getJsdocProcessorPlugin.js.map +1 -0
- package/dist/index.cjs +2 -410
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -17
- package/dist/index.js +3 -0
- package/dist/iterateJsdoc.cjs +1539 -1988
- package/dist/iterateJsdoc.cjs.map +1 -1
- package/dist/iterateJsdoc.d.cts +472 -0
- package/dist/iterateJsdoc.d.cts.map +1 -0
- package/dist/iterateJsdoc.d.ts +359 -349
- package/dist/iterateJsdoc.d.ts.map +1 -1
- package/dist/iterateJsdoc.js +1628 -0
- package/dist/iterateJsdoc.js.map +1 -0
- package/dist/jsdocUtils.cjs +1009 -1376
- package/dist/jsdocUtils.cjs.map +1 -1
- package/dist/jsdocUtils.js +1123 -0
- package/dist/jsdocUtils.js.map +1 -0
- package/dist/plugin.cjs +427 -0
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.js +427 -0
- package/dist/plugin.js.map +1 -0
- package/dist/rules/checkAccess.cjs +29 -36
- package/dist/rules/checkAccess.cjs.map +1 -1
- package/dist/rules/checkAccess.js +33 -0
- package/dist/rules/checkAccess.js.map +1 -0
- package/dist/rules/checkAlignment.cjs +41 -54
- package/dist/rules/checkAlignment.cjs.map +1 -1
- package/dist/rules/checkAlignment.js +47 -0
- package/dist/rules/checkAlignment.js.map +1 -0
- package/dist/rules/checkExamples.cjs +327 -484
- package/dist/rules/checkExamples.cjs.map +1 -1
- package/dist/rules/checkExamples.js +348 -0
- package/dist/rules/checkExamples.js.map +1 -0
- package/dist/rules/checkIndentation.cjs +50 -65
- package/dist/rules/checkIndentation.cjs.map +1 -1
- package/dist/rules/checkIndentation.js +59 -0
- package/dist/rules/checkIndentation.js.map +1 -0
- package/dist/rules/checkLineAlignment.cjs +220 -311
- package/dist/rules/checkLineAlignment.cjs.map +1 -1
- package/dist/rules/checkLineAlignment.js +229 -0
- package/dist/rules/checkLineAlignment.js.map +1 -0
- package/dist/rules/checkParamNames.cjs +227 -335
- package/dist/rules/checkParamNames.cjs.map +1 -1
- package/dist/rules/checkParamNames.js +237 -0
- package/dist/rules/checkParamNames.js.map +1 -0
- package/dist/rules/checkPropertyNames.cjs +78 -106
- package/dist/rules/checkPropertyNames.cjs.map +1 -1
- package/dist/rules/checkPropertyNames.js +88 -0
- package/dist/rules/checkPropertyNames.js.map +1 -0
- package/dist/rules/checkSyntax.cjs +21 -34
- package/dist/rules/checkSyntax.cjs.map +1 -1
- package/dist/rules/checkSyntax.js +25 -0
- package/dist/rules/checkSyntax.js.map +1 -0
- package/dist/rules/checkTagNames.cjs +188 -210
- package/dist/rules/checkTagNames.cjs.map +1 -1
- package/dist/rules/checkTagNames.js +191 -0
- package/dist/rules/checkTagNames.js.map +1 -0
- package/dist/rules/checkTemplateNames.cjs +121 -178
- package/dist/rules/checkTemplateNames.cjs.map +1 -1
- package/dist/rules/checkTemplateNames.js +124 -0
- package/dist/rules/checkTemplateNames.js.map +1 -0
- package/dist/rules/checkTypes.cjs +291 -385
- package/dist/rules/checkTypes.cjs.map +1 -1
- package/dist/rules/checkTypes.js +299 -0
- package/dist/rules/checkTypes.js.map +1 -0
- package/dist/rules/checkValues.cjs +100 -146
- package/dist/rules/checkValues.cjs.map +1 -1
- package/dist/rules/checkValues.js +103 -0
- package/dist/rules/checkValues.js.map +1 -0
- package/dist/rules/convertToJsdocComments.cjs +228 -306
- package/dist/rules/convertToJsdocComments.cjs.map +1 -1
- package/dist/rules/convertToJsdocComments.js +231 -0
- package/dist/rules/convertToJsdocComments.js.map +1 -0
- package/dist/rules/emptyTags.cjs +62 -72
- package/dist/rules/emptyTags.cjs.map +1 -1
- package/dist/rules/emptyTags.js +67 -0
- package/dist/rules/emptyTags.js.map +1 -0
- package/dist/rules/implementsOnClasses.cjs +36 -56
- package/dist/rules/implementsOnClasses.cjs.map +1 -1
- package/dist/rules/implementsOnClasses.js +40 -0
- package/dist/rules/implementsOnClasses.js.map +1 -0
- package/dist/rules/importsAsDependencies.cjs +62 -99
- package/dist/rules/importsAsDependencies.cjs.map +1 -1
- package/dist/rules/importsAsDependencies.js +68 -0
- package/dist/rules/importsAsDependencies.js.map +1 -0
- package/dist/rules/informativeDocs.cjs +105 -142
- package/dist/rules/informativeDocs.cjs.map +1 -1
- package/dist/rules/informativeDocs.js +110 -0
- package/dist/rules/informativeDocs.js.map +1 -0
- package/dist/rules/linesBeforeBlock.cjs +70 -105
- package/dist/rules/linesBeforeBlock.cjs.map +1 -1
- package/dist/rules/linesBeforeBlock.js +75 -0
- package/dist/rules/linesBeforeBlock.js.map +1 -0
- package/dist/rules/matchDescription.cjs +160 -222
- package/dist/rules/matchDescription.cjs.map +1 -1
- package/dist/rules/matchDescription.js +167 -0
- package/dist/rules/matchDescription.js.map +1 -0
- package/dist/rules/matchName.cjs +73 -128
- package/dist/rules/matchName.cjs.map +1 -1
- package/dist/rules/matchName.js +77 -0
- package/dist/rules/matchName.js.map +1 -0
- package/dist/rules/multilineBlocks.cjs +235 -352
- package/dist/rules/multilineBlocks.cjs.map +1 -1
- package/dist/rules/multilineBlocks.js +245 -0
- package/dist/rules/multilineBlocks.js.map +1 -0
- package/dist/rules/noBadBlocks.cjs +63 -86
- package/dist/rules/noBadBlocks.cjs.map +1 -1
- package/dist/rules/noBadBlocks.js +68 -0
- package/dist/rules/noBadBlocks.js.map +1 -0
- package/dist/rules/noBlankBlockDescriptions.cjs +35 -57
- package/dist/rules/noBlankBlockDescriptions.cjs.map +1 -1
- package/dist/rules/noBlankBlockDescriptions.js +41 -0
- package/dist/rules/noBlankBlockDescriptions.js.map +1 -0
- package/dist/rules/noBlankBlocks.cjs +26 -48
- package/dist/rules/noBlankBlocks.cjs.map +1 -1
- package/dist/rules/noBlankBlocks.js +30 -0
- package/dist/rules/noBlankBlocks.js.map +1 -0
- package/dist/rules/noDefaults.cjs +52 -79
- package/dist/rules/noDefaults.cjs.map +1 -1
- package/dist/rules/noDefaults.js +56 -0
- package/dist/rules/noDefaults.js.map +1 -0
- package/dist/rules/noMissingSyntax.cjs +115 -165
- package/dist/rules/noMissingSyntax.cjs.map +1 -1
- package/dist/rules/noMissingSyntax.js +126 -0
- package/dist/rules/noMissingSyntax.js.map +1 -0
- package/dist/rules/noMultiAsterisks.cjs +48 -89
- package/dist/rules/noMultiAsterisks.cjs.map +1 -1
- package/dist/rules/noMultiAsterisks.js +58 -0
- package/dist/rules/noMultiAsterisks.js.map +1 -0
- package/dist/rules/noRestrictedSyntax.cjs +45 -79
- package/dist/rules/noRestrictedSyntax.cjs.map +1 -1
- package/dist/rules/noRestrictedSyntax.js +49 -0
- package/dist/rules/noRestrictedSyntax.js.map +1 -0
- package/dist/rules/noTypes.cjs +59 -80
- package/dist/rules/noTypes.cjs.map +1 -1
- package/dist/rules/noTypes.js +65 -0
- package/dist/rules/noTypes.js.map +1 -0
- package/dist/rules/noUndefinedTypes.cjs +297 -388
- package/dist/rules/noUndefinedTypes.cjs.map +1 -1
- package/dist/rules/noUndefinedTypes.js +303 -0
- package/dist/rules/noUndefinedTypes.js.map +1 -0
- package/dist/rules/requireAsteriskPrefix.cjs +108 -159
- package/dist/rules/requireAsteriskPrefix.cjs.map +1 -1
- package/dist/rules/requireAsteriskPrefix.js +112 -0
- package/dist/rules/requireAsteriskPrefix.js.map +1 -0
- package/dist/rules/requireDescription.cjs +89 -129
- package/dist/rules/requireDescription.cjs.map +1 -1
- package/dist/rules/requireDescription.js +95 -0
- package/dist/rules/requireDescription.js.map +1 -0
- package/dist/rules/requireDescriptionCompleteSentence.cjs +201 -262
- package/dist/rules/requireDescriptionCompleteSentence.cjs.map +1 -1
- package/dist/rules/requireDescriptionCompleteSentence.js +220 -0
- package/dist/rules/requireDescriptionCompleteSentence.js.map +1 -0
- package/dist/rules/requireExample.cjs +73 -104
- package/dist/rules/requireExample.cjs.map +1 -1
- package/dist/rules/requireExample.js +77 -0
- package/dist/rules/requireExample.js.map +1 -0
- package/dist/rules/requireFileOverview.cjs +75 -129
- package/dist/rules/requireFileOverview.cjs.map +1 -1
- package/dist/rules/requireFileOverview.js +81 -0
- package/dist/rules/requireFileOverview.js.map +1 -0
- package/dist/rules/requireHyphenBeforeParamDescription.cjs +85 -133
- package/dist/rules/requireHyphenBeforeParamDescription.cjs.map +1 -1
- package/dist/rules/requireHyphenBeforeParamDescription.js +89 -0
- package/dist/rules/requireHyphenBeforeParamDescription.js.map +1 -0
- package/dist/rules/requireJsdoc.cjs +384 -557
- package/dist/rules/requireJsdoc.cjs.map +1 -1
- package/dist/rules/requireJsdoc.js +404 -0
- package/dist/rules/requireJsdoc.js.map +1 -0
- package/dist/rules/requireParam.cjs +336 -526
- package/dist/rules/requireParam.cjs.map +1 -1
- package/dist/rules/requireParam.js +344 -0
- package/dist/rules/requireParam.js.map +1 -0
- package/dist/rules/requireParamDescription.cjs +55 -80
- package/dist/rules/requireParamDescription.cjs.map +1 -1
- package/dist/rules/requireParamDescription.js +59 -0
- package/dist/rules/requireParamDescription.js.map +1 -0
- package/dist/rules/requireParamName.cjs +32 -50
- package/dist/rules/requireParamName.cjs.map +1 -1
- package/dist/rules/requireParamName.js +36 -0
- package/dist/rules/requireParamName.js.map +1 -0
- package/dist/rules/requireParamType.cjs +55 -80
- package/dist/rules/requireParamType.cjs.map +1 -1
- package/dist/rules/requireParamType.js +59 -0
- package/dist/rules/requireParamType.js.map +1 -0
- package/dist/rules/requireProperty.cjs +31 -42
- package/dist/rules/requireProperty.cjs.map +1 -1
- package/dist/rules/requireProperty.js +35 -0
- package/dist/rules/requireProperty.js.map +1 -0
- package/dist/rules/requirePropertyDescription.cjs +17 -25
- package/dist/rules/requirePropertyDescription.cjs.map +1 -1
- package/dist/rules/requirePropertyDescription.js +21 -0
- package/dist/rules/requirePropertyDescription.js.map +1 -0
- package/dist/rules/requirePropertyName.cjs +17 -25
- package/dist/rules/requirePropertyName.cjs.map +1 -1
- package/dist/rules/requirePropertyName.js +21 -0
- package/dist/rules/requirePropertyName.js.map +1 -0
- package/dist/rules/requirePropertyType.cjs +17 -25
- package/dist/rules/requirePropertyType.cjs.map +1 -1
- package/dist/rules/requirePropertyType.js +21 -0
- package/dist/rules/requirePropertyType.js.map +1 -0
- package/dist/rules/requireReturns.cjs +125 -203
- package/dist/rules/requireReturns.cjs.map +1 -1
- package/dist/rules/requireReturns.js +131 -0
- package/dist/rules/requireReturns.js.map +1 -0
- package/dist/rules/requireReturnsCheck.cjs +60 -103
- package/dist/rules/requireReturnsCheck.cjs.map +1 -1
- package/dist/rules/requireReturnsCheck.js +66 -0
- package/dist/rules/requireReturnsCheck.js.map +1 -0
- package/dist/rules/requireReturnsDescription.cjs +39 -54
- package/dist/rules/requireReturnsDescription.cjs.map +1 -1
- package/dist/rules/requireReturnsDescription.js +43 -0
- package/dist/rules/requireReturnsDescription.js.map +1 -0
- package/dist/rules/requireReturnsType.cjs +32 -50
- package/dist/rules/requireReturnsType.cjs.map +1 -1
- package/dist/rules/requireReturnsType.js +36 -0
- package/dist/rules/requireReturnsType.js.map +1 -0
- package/dist/rules/requireTemplate.cjs +119 -178
- package/dist/rules/requireTemplate.cjs.map +1 -1
- package/dist/rules/requireTemplate.js +122 -0
- package/dist/rules/requireTemplate.js.map +1 -0
- package/dist/rules/requireThrows.cjs +61 -95
- package/dist/rules/requireThrows.cjs.map +1 -1
- package/dist/rules/requireThrows.js +67 -0
- package/dist/rules/requireThrows.js.map +1 -0
- package/dist/rules/requireYields.cjs +106 -166
- package/dist/rules/requireYields.cjs.map +1 -1
- package/dist/rules/requireYields.js +115 -0
- package/dist/rules/requireYields.js.map +1 -0
- package/dist/rules/requireYieldsCheck.cjs +96 -152
- package/dist/rules/requireYieldsCheck.cjs.map +1 -1
- package/dist/rules/requireYieldsCheck.js +105 -0
- package/dist/rules/requireYieldsCheck.js.map +1 -0
- package/dist/rules/sortTags.cjs +258 -444
- package/dist/rules/sortTags.cjs.map +1 -1
- package/dist/rules/sortTags.js +262 -0
- package/dist/rules/sortTags.js.map +1 -0
- package/dist/rules/tagLines.cjs +179 -266
- package/dist/rules/tagLines.cjs.map +1 -1
- package/dist/rules/tagLines.js +183 -0
- package/dist/rules/tagLines.js.map +1 -0
- package/dist/rules/textEscaping.cjs +92 -127
- package/dist/rules/textEscaping.cjs.map +1 -1
- package/dist/rules/textEscaping.js +102 -0
- package/dist/rules/textEscaping.js.map +1 -0
- package/dist/rules/validTypes.cjs +252 -265
- package/dist/rules/validTypes.cjs.map +1 -1
- package/dist/rules/validTypes.js +259 -0
- package/dist/rules/validTypes.js.map +1 -0
- package/dist/tagNames.cjs +134 -170
- package/dist/tagNames.cjs.map +1 -1
- package/dist/tagNames.js +144 -0
- package/dist/tagNames.js.map +1 -0
- package/dist/utils/hasReturnValue.cjs +246 -474
- package/dist/utils/hasReturnValue.cjs.map +1 -1
- package/dist/utils/hasReturnValue.js +265 -0
- package/dist/utils/hasReturnValue.js.map +1 -0
- package/package.json +40 -24
- package/dist/generateRule.cjs +0 -242
- package/dist/generateRule.cjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/src/WarnSettings.js +0 -34
- package/src/alignTransform.js +0 -358
- package/src/defaultTagOrder.js +0 -169
- package/src/exportParser.js +0 -978
- package/src/getDefaultTagStructureForMode.js +0 -969
- package/src/getJsdocProcessorPlugin.js +0 -672
- package/src/index.js +0 -530
- package/src/iterateJsdoc.js +0 -2518
- package/src/jsdocUtils.js +0 -1896
- package/src/rules/checkAccess.js +0 -45
- package/src/rules/checkAlignment.js +0 -63
- package/src/rules/checkExamples.js +0 -589
- package/src/rules/checkIndentation.js +0 -75
- package/src/rules/checkLineAlignment.js +0 -372
- package/src/rules/checkParamNames.js +0 -474
- package/src/rules/checkPropertyNames.js +0 -152
- package/src/rules/checkSyntax.js +0 -30
- package/src/rules/checkTagNames.js +0 -314
- package/src/rules/checkTemplateNames.js +0 -204
- package/src/rules/checkTypes.js +0 -535
- package/src/rules/checkValues.js +0 -248
- package/src/rules/convertToJsdocComments.js +0 -398
- package/src/rules/emptyTags.js +0 -98
- package/src/rules/implementsOnClasses.js +0 -64
- package/src/rules/importsAsDependencies.js +0 -133
- package/src/rules/informativeDocs.js +0 -189
- package/src/rules/linesBeforeBlock.js +0 -134
- package/src/rules/matchDescription.js +0 -286
- package/src/rules/matchName.js +0 -151
- package/src/rules/multilineBlocks.js +0 -493
- package/src/rules/noBadBlocks.js +0 -119
- package/src/rules/noBlankBlockDescriptions.js +0 -69
- package/src/rules/noBlankBlocks.js +0 -53
- package/src/rules/noDefaults.js +0 -85
- package/src/rules/noMissingSyntax.js +0 -195
- package/src/rules/noMultiAsterisks.js +0 -134
- package/src/rules/noRestrictedSyntax.js +0 -91
- package/src/rules/noTypes.js +0 -93
- package/src/rules/noUndefinedTypes.js +0 -543
- package/src/rules/requireAsteriskPrefix.js +0 -190
- package/src/rules/requireDescription.js +0 -161
- package/src/rules/requireDescriptionCompleteSentence.js +0 -335
- package/src/rules/requireExample.js +0 -118
- package/src/rules/requireFileOverview.js +0 -154
- package/src/rules/requireHyphenBeforeParamDescription.js +0 -176
- package/src/rules/requireJsdoc.js +0 -743
- package/src/rules/requireParam.js +0 -602
- package/src/rules/requireParamDescription.js +0 -89
- package/src/rules/requireParamName.js +0 -55
- package/src/rules/requireParamType.js +0 -89
- package/src/rules/requireProperty.js +0 -48
- package/src/rules/requirePropertyDescription.js +0 -25
- package/src/rules/requirePropertyName.js +0 -25
- package/src/rules/requirePropertyType.js +0 -25
- package/src/rules/requireReturns.js +0 -238
- package/src/rules/requireReturnsCheck.js +0 -145
- package/src/rules/requireReturnsDescription.js +0 -59
- package/src/rules/requireReturnsType.js +0 -51
- package/src/rules/requireTemplate.js +0 -201
- package/src/rules/requireThrows.js +0 -111
- package/src/rules/requireYields.js +0 -216
- package/src/rules/requireYieldsCheck.js +0 -208
- package/src/rules/sortTags.js +0 -558
- package/src/rules/tagLines.js +0 -359
- package/src/rules/textEscaping.js +0 -154
- package/src/rules/validTypes.js +0 -401
- package/src/tagNames.js +0 -238
- package/src/utils/hasReturnValue.js +0 -572
package/src/exportParser.js
DELETED
|
@@ -1,978 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
findJSDocComment,
|
|
3
|
-
} from '@es-joy/jsdoccomment';
|
|
4
|
-
import debugModule from 'debug';
|
|
5
|
-
|
|
6
|
-
const debug = debugModule('requireExportJsdoc');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @typedef {{
|
|
10
|
-
* value: string
|
|
11
|
-
* }} ValueObject
|
|
12
|
-
*/
|
|
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
|
-
/**
|
|
29
|
-
* @returns {CreatedNode}
|
|
30
|
-
*/
|
|
31
|
-
const createNode = function () {
|
|
32
|
-
return {
|
|
33
|
-
props: {},
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @param {CreatedNode|null} symbol
|
|
39
|
-
* @returns {string|null}
|
|
40
|
-
*/
|
|
41
|
-
const getSymbolValue = function (symbol) {
|
|
42
|
-
/* c8 ignore next 3 */
|
|
43
|
-
if (!symbol) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/* c8 ignore else */
|
|
48
|
-
if (symbol.type === 'literal') {
|
|
49
|
-
return /** @type {ValueObject} */ (symbol.value).value;
|
|
50
|
-
}
|
|
51
|
-
/* c8 ignore next 2 */
|
|
52
|
-
// eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
|
|
53
|
-
return null;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
58
|
-
* @param {import('estree').Identifier} node
|
|
59
|
-
* @param {CreatedNode} globals
|
|
60
|
-
* @param {CreatedNode} scope
|
|
61
|
-
* @param {SymbolOptions} opts
|
|
62
|
-
* @returns {CreatedNode|null}
|
|
63
|
-
*/
|
|
64
|
-
const getIdentifier = function (node, globals, scope, opts) {
|
|
65
|
-
if (opts.simpleIdentifier) {
|
|
66
|
-
// Type is Identier for noncomputed properties
|
|
67
|
-
const identifierLiteral = createNode();
|
|
68
|
-
identifierLiteral.type = 'literal';
|
|
69
|
-
identifierLiteral.value = {
|
|
70
|
-
value: node.name,
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
return identifierLiteral;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/* c8 ignore next */
|
|
77
|
-
const block = scope || globals;
|
|
78
|
-
|
|
79
|
-
// As scopes are not currently supported, they are not traversed upwards recursively
|
|
80
|
-
if (block.props[node.name]) {
|
|
81
|
-
return block.props[node.name];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Seems this will only be entered once scopes added and entered
|
|
85
|
-
/* c8 ignore next 3 */
|
|
86
|
-
if (globals.props[node.name]) {
|
|
87
|
-
return globals.props[node.name];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return null;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* @callback CreateSymbol
|
|
95
|
-
* @param {import('eslint').Rule.Node|null} node
|
|
96
|
-
* @param {CreatedNode} globals
|
|
97
|
-
* @param {import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node|null} value
|
|
98
|
-
* @param {CreatedNode} [scope]
|
|
99
|
-
* @param {boolean|SymbolOptions} [isGlobal]
|
|
100
|
-
* @returns {CreatedNode|null}
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
/** @type {CreateSymbol} */
|
|
104
|
-
let createSymbol; // eslint-disable-line prefer-const
|
|
105
|
-
|
|
106
|
-
/* eslint-disable complexity -- Temporary */
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* @typedef {{
|
|
110
|
-
* simpleIdentifier?: boolean
|
|
111
|
-
* }} SymbolOptions
|
|
112
|
-
*/
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
*
|
|
116
|
-
* @param {import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node} node
|
|
117
|
-
* @param {CreatedNode} globals
|
|
118
|
-
* @param {CreatedNode} scope
|
|
119
|
-
* @param {SymbolOptions} [opt]
|
|
120
|
-
* @returns {CreatedNode|null}
|
|
121
|
-
*/
|
|
122
|
-
const getSymbol = function (node, globals, scope, opt) {
|
|
123
|
-
/* eslint-enable complexity -- Temporary */
|
|
124
|
-
const opts = opt || {};
|
|
125
|
-
/* c8 ignore next */
|
|
126
|
-
switch (node.type) {
|
|
127
|
-
/* c8 ignore next 4 -- No longer needed? */
|
|
128
|
-
case 'ArrowFunctionExpression':
|
|
129
|
-
|
|
130
|
-
// Fallthrough
|
|
131
|
-
case 'ClassDeclaration':
|
|
132
|
-
|
|
133
|
-
case 'FunctionDeclaration':
|
|
134
|
-
|
|
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;
|
|
144
|
-
|
|
145
|
-
return val;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
case 'AssignmentExpression': {
|
|
149
|
-
return createSymbol(
|
|
150
|
-
/** @type {import('eslint').Rule.Node} */
|
|
151
|
-
(node.left),
|
|
152
|
-
globals,
|
|
153
|
-
/** @type {import('eslint').Rule.Node} */
|
|
154
|
-
(node.right),
|
|
155
|
-
scope,
|
|
156
|
-
opts,
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
case 'ClassBody': {
|
|
161
|
-
const val = createNode();
|
|
162
|
-
for (const method of node.body) {
|
|
163
|
-
// StaticBlock
|
|
164
|
-
if (!('key' in method)) {
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
val.props[
|
|
169
|
-
/** @type {import('estree').Identifier} */ (
|
|
170
|
-
/** @type {import('estree').MethodDefinition} */ (
|
|
171
|
-
method
|
|
172
|
-
).key
|
|
173
|
-
).name
|
|
174
|
-
] = createNode();
|
|
175
|
-
/** @type {{[key: string]: CreatedNode}} */ (val.props)[
|
|
176
|
-
/** @type {import('estree').Identifier} */ (
|
|
177
|
-
/** @type {import('estree').MethodDefinition} */ (
|
|
178
|
-
method
|
|
179
|
-
).key
|
|
180
|
-
).name
|
|
181
|
-
].type = 'object';
|
|
182
|
-
/** @type {{[key: string]: CreatedNode}} */ (val.props)[
|
|
183
|
-
/** @type {import('estree').Identifier} */ (
|
|
184
|
-
/** @type {import('estree').MethodDefinition} */ (
|
|
185
|
-
method
|
|
186
|
-
).key
|
|
187
|
-
).name
|
|
188
|
-
].value = /** @type {import('eslint').Rule.Node} */ (
|
|
189
|
-
/** @type {import('estree').MethodDefinition} */ (method).value
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
val.type = 'object';
|
|
194
|
-
val.value = node.parent;
|
|
195
|
-
|
|
196
|
-
return val;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
case 'ClassExpression': {
|
|
200
|
-
return getSymbol(
|
|
201
|
-
/** @type {import('eslint').Rule.Node} */
|
|
202
|
-
(node.body),
|
|
203
|
-
globals,
|
|
204
|
-
scope,
|
|
205
|
-
opts,
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
case 'Identifier': {
|
|
210
|
-
return getIdentifier(node, globals, scope, opts);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
case 'Literal': {
|
|
214
|
-
const val = createNode();
|
|
215
|
-
val.type = 'literal';
|
|
216
|
-
val.value = node;
|
|
217
|
-
|
|
218
|
-
return val;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
case 'MemberExpression': {
|
|
222
|
-
const obj = getSymbol(
|
|
223
|
-
/** @type {import('eslint').Rule.Node} */
|
|
224
|
-
(node.object),
|
|
225
|
-
globals,
|
|
226
|
-
scope,
|
|
227
|
-
opts,
|
|
228
|
-
);
|
|
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;
|
|
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;
|
|
260
|
-
}
|
|
261
|
-
|
|
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',
|
|
269
|
-
|
|
270
|
-
// typescript-eslint, espree, acorn, etc.
|
|
271
|
-
'SpreadElement',
|
|
272
|
-
].includes(prop.type)) {
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
|
|
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
|
-
}
|
|
298
|
-
}
|
|
299
|
-
/* c8 ignore next 2 */
|
|
300
|
-
// eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
|
|
301
|
-
return null;
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
*
|
|
306
|
-
* @param {CreatedNode} block
|
|
307
|
-
* @param {string} name
|
|
308
|
-
* @param {CreatedNode|null} value
|
|
309
|
-
* @param {CreatedNode} globals
|
|
310
|
-
* @param {boolean|SymbolOptions|undefined} isGlobal
|
|
311
|
-
* @returns {void}
|
|
312
|
-
*/
|
|
313
|
-
const createBlockSymbol = function (block, name, value, globals, isGlobal) {
|
|
314
|
-
block.props[name] = value;
|
|
315
|
-
if (isGlobal && globals.props.window && globals.props.window.special) {
|
|
316
|
-
globals.props.window.props[name] = value;
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
createSymbol = function (node, globals, value, scope, isGlobal) {
|
|
321
|
-
const block = scope || globals;
|
|
322
|
-
/* c8 ignore next 3 */
|
|
323
|
-
if (!node) {
|
|
324
|
-
return null;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
let symbol;
|
|
328
|
-
switch (node.type) {
|
|
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(
|
|
342
|
-
/** @type {import('eslint').Rule.Node} */ (nde.id),
|
|
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;
|
|
351
|
-
}
|
|
352
|
-
|
|
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);
|
|
368
|
-
|
|
369
|
-
return block.props[nde.name];
|
|
370
|
-
}
|
|
371
|
-
/* c8 ignore next 3 */
|
|
372
|
-
// eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
|
|
373
|
-
break;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
case 'MemberExpression': {
|
|
377
|
-
const nde = /** @type {import('estree').MemberExpression} */ (node);
|
|
378
|
-
symbol = getSymbol(
|
|
379
|
-
/** @type {import('eslint').Rule.Node} */ (nde.object), globals, block,
|
|
380
|
-
);
|
|
381
|
-
|
|
382
|
-
const propertySymbol = getSymbol(
|
|
383
|
-
/** @type {import('eslint').Rule.Node} */ (nde.property),
|
|
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(
|
|
393
|
-
/** @type {import('eslint').Rule.Node} */
|
|
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
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
return null;
|
|
410
|
-
};
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* Creates variables from variable definitions
|
|
414
|
-
* @param {import('eslint').Rule.Node} node
|
|
415
|
-
* @param {CreatedNode} globals
|
|
416
|
-
* @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opts
|
|
417
|
-
* @returns {void}
|
|
418
|
-
*/
|
|
419
|
-
const initVariables = function (node, globals, opts) {
|
|
420
|
-
switch (node.type) {
|
|
421
|
-
case 'ExportNamedDeclaration': {
|
|
422
|
-
if (node.declaration) {
|
|
423
|
-
initVariables(
|
|
424
|
-
/** @type {import('eslint').Rule.Node} */
|
|
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),
|
|
438
|
-
globals,
|
|
439
|
-
opts,
|
|
440
|
-
);
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
|
|
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
|
-
}
|
|
453
|
-
|
|
454
|
-
break;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
case 'VariableDeclaration': {
|
|
458
|
-
for (const declaration of node.declarations) {
|
|
459
|
-
// let and const
|
|
460
|
-
const symbol = createSymbol(
|
|
461
|
-
/** @type {import('eslint').Rule.Node} */
|
|
462
|
-
(declaration.id),
|
|
463
|
-
globals,
|
|
464
|
-
null,
|
|
465
|
-
globals,
|
|
466
|
-
);
|
|
467
|
-
if (opts.initWindow && node.kind === 'var' && globals.props.window) {
|
|
468
|
-
// If var, also add to window
|
|
469
|
-
globals.props.window.props[
|
|
470
|
-
/** @type {import('estree').Identifier} */
|
|
471
|
-
(declaration.id).name
|
|
472
|
-
] = symbol;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
break;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
};
|
|
480
|
-
|
|
481
|
-
/* eslint-disable complexity -- Temporary */
|
|
482
|
-
|
|
483
|
-
/**
|
|
484
|
-
* Populates variable maps using AST
|
|
485
|
-
* @param {import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node} node
|
|
486
|
-
* @param {CreatedNode} globals
|
|
487
|
-
* @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opt
|
|
488
|
-
* @param {true} [isExport]
|
|
489
|
-
* @returns {boolean}
|
|
490
|
-
*/
|
|
491
|
-
const mapVariables = function (node, globals, opt, isExport) {
|
|
492
|
-
/* eslint-enable complexity -- Temporary */
|
|
493
|
-
/* c8 ignore next */
|
|
494
|
-
const opts = opt || {};
|
|
495
|
-
/* c8 ignore next */
|
|
496
|
-
switch (node.type) {
|
|
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;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
case 'ClassDeclaration': {
|
|
509
|
-
createSymbol(
|
|
510
|
-
/** @type {import('eslint').Rule.Node|null} */ (node.id),
|
|
511
|
-
globals,
|
|
512
|
-
/** @type {import('eslint').Rule.Node} */ (node.body),
|
|
513
|
-
globals,
|
|
514
|
-
);
|
|
515
|
-
break;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
case 'ExportDefaultDeclaration': {
|
|
519
|
-
const symbol = createSymbol(
|
|
520
|
-
/** @type {import('eslint').Rule.Node} */
|
|
521
|
-
(node.declaration),
|
|
522
|
-
globals,
|
|
523
|
-
/** @type {import('eslint').Rule.Node} */
|
|
524
|
-
(node.declaration),
|
|
525
|
-
);
|
|
526
|
-
if (symbol) {
|
|
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
|
-
);
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
break;
|
|
537
|
-
}
|
|
538
|
-
|
|
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
|
-
}
|
|
563
|
-
|
|
564
|
-
for (const specifier of node.specifiers) {
|
|
565
|
-
mapVariables(
|
|
566
|
-
/** @type {import('eslint').Rule.Node} */
|
|
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),
|
|
580
|
-
globals,
|
|
581
|
-
globals,
|
|
582
|
-
);
|
|
583
|
-
/* c8 ignore next 3 */
|
|
584
|
-
if (symbol) {
|
|
585
|
-
symbol.exported = true;
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
break;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
case 'ExpressionStatement': {
|
|
592
|
-
mapVariables(
|
|
593
|
-
/** @type {import('eslint').Rule.Node} */
|
|
594
|
-
(node.expression),
|
|
595
|
-
globals,
|
|
596
|
-
opts,
|
|
597
|
-
);
|
|
598
|
-
break;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
case 'FunctionDeclaration':
|
|
602
|
-
|
|
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) {
|
|
625
|
-
mapVariables(
|
|
626
|
-
/** @type {import('eslint').Rule.Node} */
|
|
627
|
-
(childNode),
|
|
628
|
-
globals,
|
|
629
|
-
opts,
|
|
630
|
-
);
|
|
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);
|
|
639
|
-
const symbol = createSymbol(
|
|
640
|
-
/** @type {import('eslint').Rule.Node} */
|
|
641
|
-
(declaration.id),
|
|
642
|
-
globals,
|
|
643
|
-
/** @type {import('eslint').Rule.Node} */
|
|
644
|
-
(declaration.init),
|
|
645
|
-
globals,
|
|
646
|
-
isGlobal,
|
|
647
|
-
);
|
|
648
|
-
if (symbol && isExport) {
|
|
649
|
-
symbol.exported = true;
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
break;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
default: {
|
|
657
|
-
/* c8 ignore next */
|
|
658
|
-
return false;
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
return true;
|
|
663
|
-
};
|
|
664
|
-
|
|
665
|
-
/**
|
|
666
|
-
*
|
|
667
|
-
* @param {import('eslint').Rule.Node} node
|
|
668
|
-
* @param {CreatedNode|ValueObject|string|undefined|
|
|
669
|
-
* import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node} block
|
|
670
|
-
* @param {(CreatedNode|ValueObject|string|
|
|
671
|
-
* import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node)[]} [cache]
|
|
672
|
-
* @returns {boolean}
|
|
673
|
-
*/
|
|
674
|
-
const findNode = function (node, block, cache) {
|
|
675
|
-
let blockCache = cache || [];
|
|
676
|
-
if (!block || blockCache.includes(block)) {
|
|
677
|
-
return false;
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
blockCache = blockCache.slice();
|
|
681
|
-
blockCache.push(block);
|
|
682
|
-
|
|
683
|
-
if (
|
|
684
|
-
typeof block === 'object' &&
|
|
685
|
-
'type' in block &&
|
|
686
|
-
(block.type === 'object' || block.type === 'MethodDefinition') &&
|
|
687
|
-
block.value === node
|
|
688
|
-
) {
|
|
689
|
-
return true;
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
if (typeof block !== 'object') {
|
|
693
|
-
return false;
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
const props = ('props' in block && block.props) || ('body' in block && block.body);
|
|
697
|
-
for (const propval of Object.values(props || {})) {
|
|
698
|
-
if (Array.isArray(propval)) {
|
|
699
|
-
/* c8 ignore next 5 */
|
|
700
|
-
if (propval.some((val) => {
|
|
701
|
-
return findNode(node, val, blockCache);
|
|
702
|
-
})) {
|
|
703
|
-
return true;
|
|
704
|
-
}
|
|
705
|
-
} else if (findNode(node, propval, blockCache)) {
|
|
706
|
-
return true;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
return false;
|
|
711
|
-
};
|
|
712
|
-
|
|
713
|
-
const exportTypes = new Set([
|
|
714
|
-
'ExportDefaultDeclaration', 'ExportNamedDeclaration',
|
|
715
|
-
]);
|
|
716
|
-
const ignorableNestedTypes = new Set([
|
|
717
|
-
'ArrowFunctionExpression', 'FunctionDeclaration', 'FunctionExpression',
|
|
718
|
-
]);
|
|
719
|
-
|
|
720
|
-
/**
|
|
721
|
-
* @param {import('eslint').Rule.Node} nde
|
|
722
|
-
* @returns {import('eslint').Rule.Node|false}
|
|
723
|
-
*/
|
|
724
|
-
const getExportAncestor = function (nde) {
|
|
725
|
-
let node = nde;
|
|
726
|
-
let idx = 0;
|
|
727
|
-
const ignorableIfDeep = ignorableNestedTypes.has(nde?.type);
|
|
728
|
-
while (node) {
|
|
729
|
-
// Ignore functions nested more deeply than say `export default function () {}`
|
|
730
|
-
if (idx >= 2 && ignorableIfDeep) {
|
|
731
|
-
break;
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
if (exportTypes.has(node.type)) {
|
|
735
|
-
return node;
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
node = node.parent;
|
|
739
|
-
idx++;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
return false;
|
|
743
|
-
};
|
|
744
|
-
|
|
745
|
-
const canBeExportedByAncestorType = new Set([
|
|
746
|
-
'ClassProperty',
|
|
747
|
-
'Method',
|
|
748
|
-
'PropertyDefinition',
|
|
749
|
-
'TSMethodSignature',
|
|
750
|
-
'TSPropertySignature',
|
|
751
|
-
]);
|
|
752
|
-
|
|
753
|
-
const canExportChildrenType = new Set([
|
|
754
|
-
'ClassBody',
|
|
755
|
-
'ClassDeclaration',
|
|
756
|
-
'ClassDefinition',
|
|
757
|
-
'ClassExpression',
|
|
758
|
-
'Program',
|
|
759
|
-
'TSInterfaceBody',
|
|
760
|
-
'TSInterfaceDeclaration',
|
|
761
|
-
'TSTypeAliasDeclaration',
|
|
762
|
-
'TSTypeLiteral',
|
|
763
|
-
'TSTypeParameterInstantiation',
|
|
764
|
-
'TSTypeReference',
|
|
765
|
-
]);
|
|
766
|
-
|
|
767
|
-
/**
|
|
768
|
-
* @param {import('eslint').Rule.Node} nde
|
|
769
|
-
* @returns {false|import('eslint').Rule.Node}
|
|
770
|
-
*/
|
|
771
|
-
const isExportByAncestor = function (nde) {
|
|
772
|
-
if (!canBeExportedByAncestorType.has(nde.type)) {
|
|
773
|
-
return false;
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
let node = nde.parent;
|
|
777
|
-
while (node) {
|
|
778
|
-
if (exportTypes.has(node.type)) {
|
|
779
|
-
return node;
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
if (!canExportChildrenType.has(node.type)) {
|
|
783
|
-
return false;
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
node = node.parent;
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
return false;
|
|
790
|
-
};
|
|
791
|
-
|
|
792
|
-
/**
|
|
793
|
-
*
|
|
794
|
-
* @param {CreatedNode} block
|
|
795
|
-
* @param {import('eslint').Rule.Node} node
|
|
796
|
-
* @param {CreatedNode[]} [cache] Currently unused
|
|
797
|
-
* @returns {boolean}
|
|
798
|
-
*/
|
|
799
|
-
const findExportedNode = function (block, node, cache) {
|
|
800
|
-
/* c8 ignore next 3 */
|
|
801
|
-
if (block === null) {
|
|
802
|
-
return false;
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
const blockCache = cache || [];
|
|
806
|
-
const {
|
|
807
|
-
props,
|
|
808
|
-
} = block;
|
|
809
|
-
for (const propval of Object.values(props)) {
|
|
810
|
-
const pval = /** @type {CreatedNode} */ (propval);
|
|
811
|
-
blockCache.push(pval);
|
|
812
|
-
if (pval.exported && (node === pval.value || findNode(node, pval.value))) {
|
|
813
|
-
return true;
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
// No need to check `propval` for exported nodes as ESM
|
|
817
|
-
// exports are only global
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
return false;
|
|
821
|
-
};
|
|
822
|
-
|
|
823
|
-
/**
|
|
824
|
-
*
|
|
825
|
-
* @param {import('eslint').Rule.Node} node
|
|
826
|
-
* @param {CreatedNode} globals
|
|
827
|
-
* @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opt
|
|
828
|
-
* @returns {boolean}
|
|
829
|
-
*/
|
|
830
|
-
const isNodeExported = function (node, globals, opt) {
|
|
831
|
-
const moduleExports = globals.props.module?.props?.exports;
|
|
832
|
-
if (
|
|
833
|
-
opt.initModuleExports && moduleExports && findNode(node, moduleExports)
|
|
834
|
-
) {
|
|
835
|
-
return true;
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
if (opt.initWindow && globals.props.window && findNode(node, globals.props.window)) {
|
|
839
|
-
return true;
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
if (opt.esm && findExportedNode(globals, node)) {
|
|
843
|
-
return true;
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
return false;
|
|
847
|
-
};
|
|
848
|
-
|
|
849
|
-
/**
|
|
850
|
-
*
|
|
851
|
-
* @param {import('eslint').Rule.Node} node
|
|
852
|
-
* @param {CreatedNode} globalVars
|
|
853
|
-
* @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opts
|
|
854
|
-
* @returns {boolean}
|
|
855
|
-
*/
|
|
856
|
-
const parseRecursive = function (node, globalVars, opts) {
|
|
857
|
-
// Iterate from top using recursion - stop at first processed node from top
|
|
858
|
-
if (node.parent && parseRecursive(node.parent, globalVars, opts)) {
|
|
859
|
-
return true;
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
return mapVariables(node, globalVars, opts);
|
|
863
|
-
};
|
|
864
|
-
|
|
865
|
-
/**
|
|
866
|
-
*
|
|
867
|
-
* @param {import('eslint').Rule.Node} ast
|
|
868
|
-
* @param {import('eslint').Rule.Node} node
|
|
869
|
-
* @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opt
|
|
870
|
-
* @returns {CreatedNode}
|
|
871
|
-
*/
|
|
872
|
-
const parse = function (ast, node, opt) {
|
|
873
|
-
/* c8 ignore next 6 */
|
|
874
|
-
const opts = opt || {
|
|
875
|
-
ancestorsOnly: false,
|
|
876
|
-
esm: true,
|
|
877
|
-
initModuleExports: true,
|
|
878
|
-
initWindow: true,
|
|
879
|
-
};
|
|
880
|
-
|
|
881
|
-
const globalVars = createNode();
|
|
882
|
-
if (opts.initModuleExports) {
|
|
883
|
-
globalVars.props.module = createNode();
|
|
884
|
-
globalVars.props.module.props.exports = createNode();
|
|
885
|
-
globalVars.props.exports = globalVars.props.module.props.exports;
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
if (opts.initWindow) {
|
|
889
|
-
globalVars.props.window = createNode();
|
|
890
|
-
globalVars.props.window.special = true;
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
if (opts.ancestorsOnly) {
|
|
894
|
-
parseRecursive(node, globalVars, opts);
|
|
895
|
-
} else {
|
|
896
|
-
initVariables(ast, globalVars, opts);
|
|
897
|
-
mapVariables(ast, globalVars, opts);
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
return {
|
|
901
|
-
globalVars,
|
|
902
|
-
props: {},
|
|
903
|
-
};
|
|
904
|
-
};
|
|
905
|
-
|
|
906
|
-
const accessibilityNodes = new Set([
|
|
907
|
-
'MethodDefinition',
|
|
908
|
-
'PropertyDefinition',
|
|
909
|
-
]);
|
|
910
|
-
|
|
911
|
-
/**
|
|
912
|
-
*
|
|
913
|
-
* @param {import('eslint').Rule.Node} node
|
|
914
|
-
* @returns {boolean}
|
|
915
|
-
*/
|
|
916
|
-
const isPrivate = (node) => {
|
|
917
|
-
return accessibilityNodes.has(node.type) &&
|
|
918
|
-
(
|
|
919
|
-
'accessibility' in node &&
|
|
920
|
-
node.accessibility !== 'public' && node.accessibility !== undefined
|
|
921
|
-
) ||
|
|
922
|
-
'key' in node &&
|
|
923
|
-
node.key.type === 'PrivateIdentifier';
|
|
924
|
-
};
|
|
925
|
-
|
|
926
|
-
/**
|
|
927
|
-
*
|
|
928
|
-
* @param {import('eslint').Rule.Node} node
|
|
929
|
-
* @param {import('eslint').SourceCode} sourceCode
|
|
930
|
-
* @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opt
|
|
931
|
-
* @param {import('./iterateJsdoc.js').Settings} settings
|
|
932
|
-
* @returns {boolean}
|
|
933
|
-
*/
|
|
934
|
-
const isUncommentedExport = function (node, sourceCode, opt, settings) {
|
|
935
|
-
// console.log({node});
|
|
936
|
-
// Optimize with ancestor check for esm
|
|
937
|
-
if (opt.esm) {
|
|
938
|
-
if (isPrivate(node) ||
|
|
939
|
-
node.parent && isPrivate(node.parent)) {
|
|
940
|
-
return false;
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
const exportNode = getExportAncestor(node);
|
|
944
|
-
|
|
945
|
-
// Is export node comment
|
|
946
|
-
if (exportNode && !findJSDocComment(exportNode, sourceCode, settings)) {
|
|
947
|
-
return true;
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
/**
|
|
951
|
-
* Some typescript types are not in variable map, but inherit exported (interface property and method)
|
|
952
|
-
*/
|
|
953
|
-
if (
|
|
954
|
-
isExportByAncestor(node) &&
|
|
955
|
-
!findJSDocComment(node, sourceCode, settings)
|
|
956
|
-
) {
|
|
957
|
-
return true;
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
const ast = /** @type {unknown} */ (sourceCode.ast);
|
|
962
|
-
|
|
963
|
-
const parseResult = parse(
|
|
964
|
-
/** @type {import('eslint').Rule.Node} */
|
|
965
|
-
(ast),
|
|
966
|
-
node,
|
|
967
|
-
opt,
|
|
968
|
-
);
|
|
969
|
-
|
|
970
|
-
return isNodeExported(
|
|
971
|
-
node, /** @type {CreatedNode} */ (parseResult.globalVars), opt,
|
|
972
|
-
);
|
|
973
|
-
};
|
|
974
|
-
|
|
975
|
-
export default {
|
|
976
|
-
isUncommentedExport,
|
|
977
|
-
parse,
|
|
978
|
-
};
|