eslint-plugin-jsdoc 53.0.1 → 54.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/WarnSettings.cjs +35 -18
- package/dist/WarnSettings.cjs.map +1 -1
- package/dist/alignTransform.cjs +305 -224
- package/dist/alignTransform.cjs.map +1 -1
- package/dist/defaultTagOrder.cjs +43 -132
- package/dist/defaultTagOrder.cjs.map +1 -1
- package/dist/exportParser.cjs +696 -478
- package/dist/exportParser.cjs.map +1 -1
- package/dist/generateRule.cjs +242 -0
- package/dist/generateRule.cjs.map +1 -0
- package/dist/getDefaultTagStructureForMode.cjs +288 -184
- package/dist/getDefaultTagStructureForMode.cjs.map +1 -1
- package/dist/getJsdocProcessorPlugin.cjs +550 -364
- package/dist/getJsdocProcessorPlugin.cjs.map +1 -1
- package/dist/getJsdocProcessorPlugin.d.ts +65 -68
- package/dist/getJsdocProcessorPlugin.d.ts.map +1 -1
- package/dist/index.cjs +410 -2
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +17 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/iterateJsdoc.cjs +2005 -1539
- package/dist/iterateJsdoc.cjs.map +1 -1
- package/dist/iterateJsdoc.d.ts +350 -359
- package/dist/iterateJsdoc.d.ts.map +1 -1
- package/dist/jsdocUtils.cjs +1376 -1009
- package/dist/jsdocUtils.cjs.map +1 -1
- package/dist/rules/checkAccess.cjs +36 -29
- package/dist/rules/checkAccess.cjs.map +1 -1
- package/dist/rules/checkAlignment.cjs +54 -41
- package/dist/rules/checkAlignment.cjs.map +1 -1
- package/dist/rules/checkExamples.cjs +484 -327
- package/dist/rules/checkExamples.cjs.map +1 -1
- package/dist/rules/checkIndentation.cjs +65 -50
- package/dist/rules/checkIndentation.cjs.map +1 -1
- package/dist/rules/checkLineAlignment.cjs +311 -220
- package/dist/rules/checkLineAlignment.cjs.map +1 -1
- package/dist/rules/checkParamNames.cjs +335 -227
- package/dist/rules/checkParamNames.cjs.map +1 -1
- package/dist/rules/checkPropertyNames.cjs +106 -78
- package/dist/rules/checkPropertyNames.cjs.map +1 -1
- package/dist/rules/checkSyntax.cjs +34 -21
- package/dist/rules/checkSyntax.cjs.map +1 -1
- package/dist/rules/checkTagNames.cjs +210 -188
- package/dist/rules/checkTagNames.cjs.map +1 -1
- package/dist/rules/checkTemplateNames.cjs +178 -121
- package/dist/rules/checkTemplateNames.cjs.map +1 -1
- package/dist/rules/checkTypes.cjs +385 -291
- package/dist/rules/checkTypes.cjs.map +1 -1
- package/dist/rules/checkValues.cjs +146 -100
- package/dist/rules/checkValues.cjs.map +1 -1
- package/dist/rules/convertToJsdocComments.cjs +306 -228
- package/dist/rules/convertToJsdocComments.cjs.map +1 -1
- package/dist/rules/emptyTags.cjs +72 -62
- package/dist/rules/emptyTags.cjs.map +1 -1
- package/dist/rules/implementsOnClasses.cjs +56 -36
- package/dist/rules/implementsOnClasses.cjs.map +1 -1
- package/dist/rules/importsAsDependencies.cjs +99 -62
- package/dist/rules/importsAsDependencies.cjs.map +1 -1
- package/dist/rules/informativeDocs.cjs +142 -105
- package/dist/rules/informativeDocs.cjs.map +1 -1
- package/dist/rules/linesBeforeBlock.cjs +105 -70
- package/dist/rules/linesBeforeBlock.cjs.map +1 -1
- package/dist/rules/matchDescription.cjs +222 -160
- package/dist/rules/matchDescription.cjs.map +1 -1
- package/dist/rules/matchName.cjs +128 -73
- package/dist/rules/matchName.cjs.map +1 -1
- package/dist/rules/multilineBlocks.cjs +352 -235
- package/dist/rules/multilineBlocks.cjs.map +1 -1
- package/dist/rules/noBadBlocks.cjs +86 -63
- package/dist/rules/noBadBlocks.cjs.map +1 -1
- package/dist/rules/noBlankBlockDescriptions.cjs +57 -35
- package/dist/rules/noBlankBlockDescriptions.cjs.map +1 -1
- package/dist/rules/noBlankBlocks.cjs +48 -26
- package/dist/rules/noBlankBlocks.cjs.map +1 -1
- package/dist/rules/noDefaults.cjs +79 -52
- package/dist/rules/noDefaults.cjs.map +1 -1
- package/dist/rules/noMissingSyntax.cjs +165 -115
- package/dist/rules/noMissingSyntax.cjs.map +1 -1
- package/dist/rules/noMultiAsterisks.cjs +89 -48
- package/dist/rules/noMultiAsterisks.cjs.map +1 -1
- package/dist/rules/noRestrictedSyntax.cjs +79 -45
- package/dist/rules/noRestrictedSyntax.cjs.map +1 -1
- package/dist/rules/noTypes.cjs +80 -59
- package/dist/rules/noTypes.cjs.map +1 -1
- package/dist/rules/noUndefinedTypes.cjs +388 -297
- package/dist/rules/noUndefinedTypes.cjs.map +1 -1
- package/dist/rules/requireAsteriskPrefix.cjs +159 -108
- package/dist/rules/requireAsteriskPrefix.cjs.map +1 -1
- package/dist/rules/requireDescription.cjs +129 -89
- package/dist/rules/requireDescription.cjs.map +1 -1
- package/dist/rules/requireDescriptionCompleteSentence.cjs +262 -201
- package/dist/rules/requireDescriptionCompleteSentence.cjs.map +1 -1
- package/dist/rules/requireExample.cjs +104 -73
- package/dist/rules/requireExample.cjs.map +1 -1
- package/dist/rules/requireFileOverview.cjs +129 -75
- package/dist/rules/requireFileOverview.cjs.map +1 -1
- package/dist/rules/requireHyphenBeforeParamDescription.cjs +133 -85
- package/dist/rules/requireHyphenBeforeParamDescription.cjs.map +1 -1
- package/dist/rules/requireJsdoc.cjs +557 -384
- package/dist/rules/requireJsdoc.cjs.map +1 -1
- package/dist/rules/requireParam.cjs +526 -336
- package/dist/rules/requireParam.cjs.map +1 -1
- package/dist/rules/requireParamDescription.cjs +80 -55
- package/dist/rules/requireParamDescription.cjs.map +1 -1
- package/dist/rules/requireParamName.cjs +50 -32
- package/dist/rules/requireParamName.cjs.map +1 -1
- package/dist/rules/requireParamType.cjs +80 -55
- package/dist/rules/requireParamType.cjs.map +1 -1
- package/dist/rules/requireProperty.cjs +42 -31
- package/dist/rules/requireProperty.cjs.map +1 -1
- package/dist/rules/requirePropertyDescription.cjs +25 -17
- package/dist/rules/requirePropertyDescription.cjs.map +1 -1
- package/dist/rules/requirePropertyName.cjs +25 -17
- package/dist/rules/requirePropertyName.cjs.map +1 -1
- package/dist/rules/requirePropertyType.cjs +25 -17
- package/dist/rules/requirePropertyType.cjs.map +1 -1
- package/dist/rules/requireReturns.cjs +203 -125
- package/dist/rules/requireReturns.cjs.map +1 -1
- package/dist/rules/requireReturnsCheck.cjs +103 -60
- package/dist/rules/requireReturnsCheck.cjs.map +1 -1
- package/dist/rules/requireReturnsDescription.cjs +54 -39
- package/dist/rules/requireReturnsDescription.cjs.map +1 -1
- package/dist/rules/requireReturnsType.cjs +50 -32
- package/dist/rules/requireReturnsType.cjs.map +1 -1
- package/dist/rules/requireTemplate.cjs +178 -119
- package/dist/rules/requireTemplate.cjs.map +1 -1
- package/dist/rules/requireThrows.cjs +95 -61
- package/dist/rules/requireThrows.cjs.map +1 -1
- package/dist/rules/requireYields.cjs +166 -106
- package/dist/rules/requireYields.cjs.map +1 -1
- package/dist/rules/requireYieldsCheck.cjs +152 -96
- package/dist/rules/requireYieldsCheck.cjs.map +1 -1
- package/dist/rules/sortTags.cjs +444 -258
- package/dist/rules/sortTags.cjs.map +1 -1
- package/dist/rules/tagLines.cjs +266 -179
- package/dist/rules/tagLines.cjs.map +1 -1
- package/dist/rules/textEscaping.cjs +127 -92
- package/dist/rules/textEscaping.cjs.map +1 -1
- package/dist/rules/validTypes.cjs +265 -252
- package/dist/rules/validTypes.cjs.map +1 -1
- package/dist/tagNames.cjs +170 -134
- package/dist/tagNames.cjs.map +1 -1
- package/dist/utils/hasReturnValue.cjs +474 -246
- package/dist/utils/hasReturnValue.cjs.map +1 -1
- package/package.json +24 -40
- package/src/WarnSettings.js +34 -0
- package/src/alignTransform.js +358 -0
- package/src/defaultTagOrder.js +169 -0
- package/src/exportParser.js +978 -0
- package/src/getDefaultTagStructureForMode.js +969 -0
- package/src/getJsdocProcessorPlugin.js +672 -0
- package/src/index.js +530 -0
- package/src/iterateJsdoc.js +2541 -0
- package/src/jsdocUtils.js +1896 -0
- package/src/rules/checkAccess.js +45 -0
- package/src/rules/checkAlignment.js +63 -0
- package/src/rules/checkExamples.js +589 -0
- package/src/rules/checkIndentation.js +75 -0
- package/src/rules/checkLineAlignment.js +372 -0
- package/src/rules/checkParamNames.js +474 -0
- package/src/rules/checkPropertyNames.js +152 -0
- package/src/rules/checkSyntax.js +30 -0
- package/src/rules/checkTagNames.js +314 -0
- package/src/rules/checkTemplateNames.js +204 -0
- package/src/rules/checkTypes.js +535 -0
- package/src/rules/checkValues.js +248 -0
- package/src/rules/convertToJsdocComments.js +398 -0
- package/src/rules/emptyTags.js +98 -0
- package/src/rules/implementsOnClasses.js +64 -0
- package/src/rules/importsAsDependencies.js +133 -0
- package/src/rules/informativeDocs.js +189 -0
- package/src/rules/linesBeforeBlock.js +134 -0
- package/src/rules/matchDescription.js +286 -0
- package/src/rules/matchName.js +151 -0
- package/src/rules/multilineBlocks.js +493 -0
- package/src/rules/noBadBlocks.js +119 -0
- package/src/rules/noBlankBlockDescriptions.js +69 -0
- package/src/rules/noBlankBlocks.js +53 -0
- package/src/rules/noDefaults.js +85 -0
- package/src/rules/noMissingSyntax.js +195 -0
- package/src/rules/noMultiAsterisks.js +134 -0
- package/src/rules/noRestrictedSyntax.js +91 -0
- package/src/rules/noTypes.js +93 -0
- package/src/rules/noUndefinedTypes.js +543 -0
- package/src/rules/requireAsteriskPrefix.js +190 -0
- package/src/rules/requireDescription.js +161 -0
- package/src/rules/requireDescriptionCompleteSentence.js +335 -0
- package/src/rules/requireExample.js +118 -0
- package/src/rules/requireFileOverview.js +154 -0
- package/src/rules/requireHyphenBeforeParamDescription.js +176 -0
- package/src/rules/requireJsdoc.js +743 -0
- package/src/rules/requireParam.js +602 -0
- package/src/rules/requireParamDescription.js +89 -0
- package/src/rules/requireParamName.js +55 -0
- package/src/rules/requireParamType.js +89 -0
- package/src/rules/requireProperty.js +48 -0
- package/src/rules/requirePropertyDescription.js +25 -0
- package/src/rules/requirePropertyName.js +25 -0
- package/src/rules/requirePropertyType.js +25 -0
- package/src/rules/requireReturns.js +238 -0
- package/src/rules/requireReturnsCheck.js +145 -0
- package/src/rules/requireReturnsDescription.js +59 -0
- package/src/rules/requireReturnsType.js +51 -0
- package/src/rules/requireTemplate.js +201 -0
- package/src/rules/requireThrows.js +111 -0
- package/src/rules/requireYields.js +216 -0
- package/src/rules/requireYieldsCheck.js +208 -0
- package/src/rules/sortTags.js +558 -0
- package/src/rules/tagLines.js +359 -0
- package/src/rules/textEscaping.js +154 -0
- package/src/rules/validTypes.js +401 -0
- package/src/tagNames.js +238 -0
- package/src/utils/hasReturnValue.js +572 -0
- package/dist/WarnSettings.js +0 -20
- package/dist/WarnSettings.js.map +0 -1
- package/dist/_virtual/rolldown_runtime.cjs +0 -32
- package/dist/_virtual/rolldown_runtime.js +0 -11
- package/dist/alignTransform.js +0 -241
- package/dist/alignTransform.js.map +0 -1
- package/dist/defaultTagOrder.js +0 -134
- package/dist/defaultTagOrder.js.map +0 -1
- package/dist/exportParser.js +0 -518
- package/dist/exportParser.js.map +0 -1
- package/dist/getDefaultTagStructureForMode.js +0 -188
- package/dist/getDefaultTagStructureForMode.js.map +0 -1
- package/dist/getJsdocProcessorPlugin.d.cts +0 -70
- package/dist/getJsdocProcessorPlugin.d.cts.map +0 -1
- package/dist/getJsdocProcessorPlugin.js +0 -383
- package/dist/getJsdocProcessorPlugin.js.map +0 -1
- package/dist/index.d.cts +0 -2
- package/dist/index.js +0 -3
- package/dist/iterateJsdoc.d.cts +0 -472
- package/dist/iterateJsdoc.d.cts.map +0 -1
- package/dist/iterateJsdoc.js +0 -1628
- package/dist/iterateJsdoc.js.map +0 -1
- package/dist/jsdocUtils.js +0 -1123
- package/dist/jsdocUtils.js.map +0 -1
- package/dist/plugin.cjs +0 -427
- package/dist/plugin.cjs.map +0 -1
- package/dist/plugin.js +0 -427
- package/dist/plugin.js.map +0 -1
- package/dist/rules/checkAccess.js +0 -33
- package/dist/rules/checkAccess.js.map +0 -1
- package/dist/rules/checkAlignment.js +0 -47
- package/dist/rules/checkAlignment.js.map +0 -1
- package/dist/rules/checkExamples.js +0 -348
- package/dist/rules/checkExamples.js.map +0 -1
- package/dist/rules/checkIndentation.js +0 -59
- package/dist/rules/checkIndentation.js.map +0 -1
- package/dist/rules/checkLineAlignment.js +0 -229
- package/dist/rules/checkLineAlignment.js.map +0 -1
- package/dist/rules/checkParamNames.js +0 -237
- package/dist/rules/checkParamNames.js.map +0 -1
- package/dist/rules/checkPropertyNames.js +0 -88
- package/dist/rules/checkPropertyNames.js.map +0 -1
- package/dist/rules/checkSyntax.js +0 -25
- package/dist/rules/checkSyntax.js.map +0 -1
- package/dist/rules/checkTagNames.js +0 -191
- package/dist/rules/checkTagNames.js.map +0 -1
- package/dist/rules/checkTemplateNames.js +0 -124
- package/dist/rules/checkTemplateNames.js.map +0 -1
- package/dist/rules/checkTypes.js +0 -299
- package/dist/rules/checkTypes.js.map +0 -1
- package/dist/rules/checkValues.js +0 -103
- package/dist/rules/checkValues.js.map +0 -1
- package/dist/rules/convertToJsdocComments.js +0 -231
- package/dist/rules/convertToJsdocComments.js.map +0 -1
- package/dist/rules/emptyTags.js +0 -67
- package/dist/rules/emptyTags.js.map +0 -1
- package/dist/rules/implementsOnClasses.js +0 -40
- package/dist/rules/implementsOnClasses.js.map +0 -1
- package/dist/rules/importsAsDependencies.js +0 -68
- package/dist/rules/importsAsDependencies.js.map +0 -1
- package/dist/rules/informativeDocs.js +0 -110
- package/dist/rules/informativeDocs.js.map +0 -1
- package/dist/rules/linesBeforeBlock.js +0 -75
- package/dist/rules/linesBeforeBlock.js.map +0 -1
- package/dist/rules/matchDescription.js +0 -167
- package/dist/rules/matchDescription.js.map +0 -1
- package/dist/rules/matchName.js +0 -77
- package/dist/rules/matchName.js.map +0 -1
- package/dist/rules/multilineBlocks.js +0 -245
- package/dist/rules/multilineBlocks.js.map +0 -1
- package/dist/rules/noBadBlocks.js +0 -68
- package/dist/rules/noBadBlocks.js.map +0 -1
- package/dist/rules/noBlankBlockDescriptions.js +0 -41
- package/dist/rules/noBlankBlockDescriptions.js.map +0 -1
- package/dist/rules/noBlankBlocks.js +0 -30
- package/dist/rules/noBlankBlocks.js.map +0 -1
- package/dist/rules/noDefaults.js +0 -56
- package/dist/rules/noDefaults.js.map +0 -1
- package/dist/rules/noMissingSyntax.js +0 -126
- package/dist/rules/noMissingSyntax.js.map +0 -1
- package/dist/rules/noMultiAsterisks.js +0 -58
- package/dist/rules/noMultiAsterisks.js.map +0 -1
- package/dist/rules/noRestrictedSyntax.js +0 -49
- package/dist/rules/noRestrictedSyntax.js.map +0 -1
- package/dist/rules/noTypes.js +0 -65
- package/dist/rules/noTypes.js.map +0 -1
- package/dist/rules/noUndefinedTypes.js +0 -303
- package/dist/rules/noUndefinedTypes.js.map +0 -1
- package/dist/rules/requireAsteriskPrefix.js +0 -112
- package/dist/rules/requireAsteriskPrefix.js.map +0 -1
- package/dist/rules/requireDescription.js +0 -95
- package/dist/rules/requireDescription.js.map +0 -1
- package/dist/rules/requireDescriptionCompleteSentence.js +0 -220
- package/dist/rules/requireDescriptionCompleteSentence.js.map +0 -1
- package/dist/rules/requireExample.js +0 -77
- package/dist/rules/requireExample.js.map +0 -1
- package/dist/rules/requireFileOverview.js +0 -81
- package/dist/rules/requireFileOverview.js.map +0 -1
- package/dist/rules/requireHyphenBeforeParamDescription.js +0 -89
- package/dist/rules/requireHyphenBeforeParamDescription.js.map +0 -1
- package/dist/rules/requireJsdoc.js +0 -404
- package/dist/rules/requireJsdoc.js.map +0 -1
- package/dist/rules/requireParam.js +0 -344
- package/dist/rules/requireParam.js.map +0 -1
- package/dist/rules/requireParamDescription.js +0 -59
- package/dist/rules/requireParamDescription.js.map +0 -1
- package/dist/rules/requireParamName.js +0 -36
- package/dist/rules/requireParamName.js.map +0 -1
- package/dist/rules/requireParamType.js +0 -59
- package/dist/rules/requireParamType.js.map +0 -1
- package/dist/rules/requireProperty.js +0 -35
- package/dist/rules/requireProperty.js.map +0 -1
- package/dist/rules/requirePropertyDescription.js +0 -21
- package/dist/rules/requirePropertyDescription.js.map +0 -1
- package/dist/rules/requirePropertyName.js +0 -21
- package/dist/rules/requirePropertyName.js.map +0 -1
- package/dist/rules/requirePropertyType.js +0 -21
- package/dist/rules/requirePropertyType.js.map +0 -1
- package/dist/rules/requireReturns.js +0 -131
- package/dist/rules/requireReturns.js.map +0 -1
- package/dist/rules/requireReturnsCheck.js +0 -66
- package/dist/rules/requireReturnsCheck.js.map +0 -1
- package/dist/rules/requireReturnsDescription.js +0 -43
- package/dist/rules/requireReturnsDescription.js.map +0 -1
- package/dist/rules/requireReturnsType.js +0 -36
- package/dist/rules/requireReturnsType.js.map +0 -1
- package/dist/rules/requireTemplate.js +0 -122
- package/dist/rules/requireTemplate.js.map +0 -1
- package/dist/rules/requireThrows.js +0 -67
- package/dist/rules/requireThrows.js.map +0 -1
- package/dist/rules/requireYields.js +0 -115
- package/dist/rules/requireYields.js.map +0 -1
- package/dist/rules/requireYieldsCheck.js +0 -105
- package/dist/rules/requireYieldsCheck.js.map +0 -1
- package/dist/rules/sortTags.js +0 -262
- package/dist/rules/sortTags.js.map +0 -1
- package/dist/rules/tagLines.js +0 -183
- package/dist/rules/tagLines.js.map +0 -1
- package/dist/rules/textEscaping.js +0 -102
- package/dist/rules/textEscaping.js.map +0 -1
- package/dist/rules/validTypes.js +0 -259
- package/dist/rules/validTypes.js.map +0 -1
- package/dist/tagNames.js +0 -144
- package/dist/tagNames.js.map +0 -1
- package/dist/utils/hasReturnValue.js +0 -265
- package/dist/utils/hasReturnValue.js.map +0 -1
package/dist/jsdocUtils.js
DELETED
|
@@ -1,1123 +0,0 @@
|
|
|
1
|
-
import { __export } from "./_virtual/rolldown_runtime.js";
|
|
2
|
-
import getDefaultTagStructureForMode_default from "./getDefaultTagStructureForMode.js";
|
|
3
|
-
import { closureTags, jsdocTags, typeScriptTags } from "./tagNames.js";
|
|
4
|
-
import WarnSettings_default from "./WarnSettings.js";
|
|
5
|
-
import { hasReturnValue, hasValueOrExecutorHasNonEmptyResolveValue } from "./utils/hasReturnValue.js";
|
|
6
|
-
import { tryParse } from "@es-joy/jsdoccomment";
|
|
7
|
-
|
|
8
|
-
//#region src/jsdocUtils.js
|
|
9
|
-
var jsdocUtils_exports = {};
|
|
10
|
-
__export(jsdocUtils_exports, {
|
|
11
|
-
comparePaths: () => comparePaths,
|
|
12
|
-
dropPathSegmentQuotes: () => dropPathSegmentQuotes,
|
|
13
|
-
enforcedContexts: () => enforcedContexts,
|
|
14
|
-
exemptSpeciaMethods: () => exemptSpeciaMethods,
|
|
15
|
-
filterTags: () => filterTags,
|
|
16
|
-
flattenRoots: () => flattenRoots,
|
|
17
|
-
forEachPreferredTag: () => forEachPreferredTag,
|
|
18
|
-
getAllTags: () => getAllTags,
|
|
19
|
-
getContextObject: () => getContextObject,
|
|
20
|
-
getFunctionParameterNames: () => getFunctionParameterNames,
|
|
21
|
-
getIndent: () => getIndent,
|
|
22
|
-
getJsdocTagsDeep: () => getJsdocTagsDeep,
|
|
23
|
-
getPreferredTagName: () => getPreferredTagName,
|
|
24
|
-
getPreferredTagNameSimple: () => getPreferredTagNameSimple,
|
|
25
|
-
getRegexFromString: () => getRegexFromString,
|
|
26
|
-
getTagDescription: () => getTagDescription,
|
|
27
|
-
getTagStructureForMode: () => getTagStructureForMode,
|
|
28
|
-
getTags: () => getTags,
|
|
29
|
-
getTagsByType: () => getTagsByType,
|
|
30
|
-
hasATag: () => hasATag,
|
|
31
|
-
hasParams: () => hasParams,
|
|
32
|
-
hasReturnValue: () => hasReturnValue,
|
|
33
|
-
hasTag: () => hasTag,
|
|
34
|
-
hasThrowValue: () => hasThrowValue,
|
|
35
|
-
hasValueOrExecutorHasNonEmptyResolveValue: () => hasValueOrExecutorHasNonEmptyResolveValue,
|
|
36
|
-
hasYieldValue: () => hasYieldValue,
|
|
37
|
-
isConstructor: () => isConstructor,
|
|
38
|
-
isGetter: () => isGetter,
|
|
39
|
-
isNamepathDefiningTag: () => isNamepathDefiningTag,
|
|
40
|
-
isNamepathOrUrlReferencingTag: () => isNamepathOrUrlReferencingTag,
|
|
41
|
-
isNamepathReferencingTag: () => isNamepathReferencingTag,
|
|
42
|
-
isSetter: () => isSetter,
|
|
43
|
-
isValidTag: () => isValidTag,
|
|
44
|
-
mayBeUndefinedTypeTag: () => mayBeUndefinedTypeTag,
|
|
45
|
-
overrideTagStructure: () => overrideTagStructure,
|
|
46
|
-
parseClosureTemplateTag: () => parseClosureTemplateTag,
|
|
47
|
-
pathDoesNotBeginWith: () => pathDoesNotBeginWith,
|
|
48
|
-
setTagStructure: () => setTagStructure,
|
|
49
|
-
tagMightHaveEitherTypeOrNamePosition: () => tagMightHaveEitherTypeOrNamePosition,
|
|
50
|
-
tagMightHaveNamePosition: () => tagMightHaveNamePosition,
|
|
51
|
-
tagMightHaveNamepath: () => tagMightHaveNamepath,
|
|
52
|
-
tagMightHaveTypePosition: () => tagMightHaveTypePosition,
|
|
53
|
-
tagMissingRequiredTypeOrNamepath: () => tagMissingRequiredTypeOrNamepath,
|
|
54
|
-
tagMustHaveNamePosition: () => tagMustHaveNamePosition,
|
|
55
|
-
tagMustHaveTypePosition: () => tagMustHaveTypePosition
|
|
56
|
-
});
|
|
57
|
-
/**
|
|
58
|
-
* @typedef {number} Integer
|
|
59
|
-
*/
|
|
60
|
-
/**
|
|
61
|
-
* @typedef {import('./utils/hasReturnValue.js').ESTreeOrTypeScriptNode} ESTreeOrTypeScriptNode
|
|
62
|
-
*/
|
|
63
|
-
/**
|
|
64
|
-
* @typedef {"jsdoc"|"typescript"|"closure"|"permissive"} ParserMode
|
|
65
|
-
*/
|
|
66
|
-
/**
|
|
67
|
-
* @type {import('./getDefaultTagStructureForMode.js').TagStructure}
|
|
68
|
-
*/
|
|
69
|
-
let tagStructure;
|
|
70
|
-
/**
|
|
71
|
-
* @param {ParserMode} mode
|
|
72
|
-
* @returns {void}
|
|
73
|
-
*/
|
|
74
|
-
const setTagStructure = (mode) => {
|
|
75
|
-
tagStructure = getDefaultTagStructureForMode_default(mode);
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* @typedef {undefined|string|{
|
|
79
|
-
* name: Integer,
|
|
80
|
-
* restElement: boolean
|
|
81
|
-
* }|{
|
|
82
|
-
* isRestProperty: boolean|undefined,
|
|
83
|
-
* name: string,
|
|
84
|
-
* restElement: boolean
|
|
85
|
-
* }|{
|
|
86
|
-
* name: string,
|
|
87
|
-
* restElement: boolean
|
|
88
|
-
* }} ParamCommon
|
|
89
|
-
*/
|
|
90
|
-
/**
|
|
91
|
-
* @typedef {ParamCommon|[string|undefined, (FlattendRootInfo & {
|
|
92
|
-
* annotationParamName?: string,
|
|
93
|
-
* })]|NestedParamInfo} ParamNameInfo
|
|
94
|
-
*/
|
|
95
|
-
/**
|
|
96
|
-
* @typedef {{
|
|
97
|
-
* hasPropertyRest: boolean,
|
|
98
|
-
* hasRestElement: boolean,
|
|
99
|
-
* names: string[],
|
|
100
|
-
* rests: boolean[],
|
|
101
|
-
* }} FlattendRootInfo
|
|
102
|
-
*/
|
|
103
|
-
/**
|
|
104
|
-
* @typedef {[string, (string[]|ParamInfo[])]} NestedParamInfo
|
|
105
|
-
*/
|
|
106
|
-
/**
|
|
107
|
-
* @typedef {ParamCommon|
|
|
108
|
-
* [string|undefined, (FlattendRootInfo & {
|
|
109
|
-
* annotationParamName?: string
|
|
110
|
-
* })]|
|
|
111
|
-
* NestedParamInfo} ParamInfo
|
|
112
|
-
*/
|
|
113
|
-
/**
|
|
114
|
-
* Given a nested array of property names, reduce them to a single array,
|
|
115
|
-
* appending the name of the root element along the way if present.
|
|
116
|
-
* @callback FlattenRoots
|
|
117
|
-
* @param {ParamInfo[]} params
|
|
118
|
-
* @param {string} [root]
|
|
119
|
-
* @returns {FlattendRootInfo}
|
|
120
|
-
*/
|
|
121
|
-
/** @type {FlattenRoots} */
|
|
122
|
-
const flattenRoots = (params, root = "") => {
|
|
123
|
-
let hasRestElement = false;
|
|
124
|
-
let hasPropertyRest = false;
|
|
125
|
-
/**
|
|
126
|
-
* @type {boolean[]}
|
|
127
|
-
*/
|
|
128
|
-
const rests = [];
|
|
129
|
-
const names = params.reduce(
|
|
130
|
-
/**
|
|
131
|
-
* @param {string[]} acc
|
|
132
|
-
* @param {ParamInfo} cur
|
|
133
|
-
* @returns {string[]}
|
|
134
|
-
*/
|
|
135
|
-
(acc, cur) => {
|
|
136
|
-
if (Array.isArray(cur)) {
|
|
137
|
-
let nms;
|
|
138
|
-
if (Array.isArray(cur[1])) nms = cur[1];
|
|
139
|
-
else {
|
|
140
|
-
if (cur[1].hasRestElement) hasRestElement = true;
|
|
141
|
-
if (cur[1].hasPropertyRest) hasPropertyRest = true;
|
|
142
|
-
nms = cur[1].names;
|
|
143
|
-
}
|
|
144
|
-
const flattened = flattenRoots(nms, root ? `${root}.${cur[0]}` : cur[0]);
|
|
145
|
-
if (flattened.hasRestElement) hasRestElement = true;
|
|
146
|
-
if (flattened.hasPropertyRest) hasPropertyRest = true;
|
|
147
|
-
const inner = [root ? `${root}.${cur[0]}` : cur[0], ...flattened.names].filter(Boolean);
|
|
148
|
-
rests.push(false, ...flattened.rests);
|
|
149
|
-
return acc.concat(inner);
|
|
150
|
-
}
|
|
151
|
-
if (typeof cur === "object") {
|
|
152
|
-
if ("isRestProperty" in cur && cur.isRestProperty) {
|
|
153
|
-
hasPropertyRest = true;
|
|
154
|
-
rests.push(true);
|
|
155
|
-
} else rests.push(false);
|
|
156
|
-
if ("restElement" in cur && cur.restElement) hasRestElement = true;
|
|
157
|
-
acc.push(root ? `${root}.${String(cur.name)}` : String(cur.name));
|
|
158
|
-
} else if (typeof cur !== "undefined") {
|
|
159
|
-
rests.push(false);
|
|
160
|
-
acc.push(root ? `${root}.${cur}` : cur);
|
|
161
|
-
}
|
|
162
|
-
return acc;
|
|
163
|
-
},
|
|
164
|
-
[]
|
|
165
|
-
);
|
|
166
|
-
return {
|
|
167
|
-
hasPropertyRest,
|
|
168
|
-
hasRestElement,
|
|
169
|
-
names,
|
|
170
|
-
rests
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
/**
|
|
174
|
-
* @param {import('@typescript-eslint/types').TSESTree.TSIndexSignature|
|
|
175
|
-
* import('@typescript-eslint/types').TSESTree.TSConstructSignatureDeclaration|
|
|
176
|
-
* import('@typescript-eslint/types').TSESTree.TSCallSignatureDeclaration|
|
|
177
|
-
* import('@typescript-eslint/types').TSESTree.TSPropertySignature} propSignature
|
|
178
|
-
* @returns {undefined|string|[string, string[]]}
|
|
179
|
-
*/
|
|
180
|
-
const getPropertiesFromPropertySignature = (propSignature) => {
|
|
181
|
-
if (propSignature.type === "TSIndexSignature" || propSignature.type === "TSConstructSignatureDeclaration" || propSignature.type === "TSCallSignatureDeclaration") return void 0;
|
|
182
|
-
if (propSignature.typeAnnotation && propSignature.typeAnnotation.typeAnnotation.type === "TSTypeLiteral") return [propSignature.key.name, propSignature.typeAnnotation.typeAnnotation.members.map((member) => {
|
|
183
|
-
return getPropertiesFromPropertySignature(member);
|
|
184
|
-
})];
|
|
185
|
-
return propSignature.key.name;
|
|
186
|
-
};
|
|
187
|
-
/**
|
|
188
|
-
* @param {ESTreeOrTypeScriptNode|null} functionNode
|
|
189
|
-
* @param {boolean} [checkDefaultObjects]
|
|
190
|
-
* @throws {Error}
|
|
191
|
-
* @returns {ParamNameInfo[]}
|
|
192
|
-
*/
|
|
193
|
-
const getFunctionParameterNames = (functionNode, checkDefaultObjects) => {
|
|
194
|
-
/**
|
|
195
|
-
* @param {import('estree').Identifier|import('estree').AssignmentPattern|
|
|
196
|
-
* import('estree').ObjectPattern|import('estree').Property|
|
|
197
|
-
* import('estree').RestElement|import('estree').ArrayPattern|
|
|
198
|
-
* import('@typescript-eslint/types').TSESTree.TSParameterProperty|
|
|
199
|
-
* import('@typescript-eslint/types').TSESTree.Property|
|
|
200
|
-
* import('@typescript-eslint/types').TSESTree.RestElement|
|
|
201
|
-
* import('@typescript-eslint/types').TSESTree.Identifier|
|
|
202
|
-
* import('@typescript-eslint/types').TSESTree.ObjectPattern|
|
|
203
|
-
* import('@typescript-eslint/types').TSESTree.BindingName|
|
|
204
|
-
* import('@typescript-eslint/types').TSESTree.Parameter
|
|
205
|
-
* } param
|
|
206
|
-
* @param {boolean} [isProperty]
|
|
207
|
-
* @returns {ParamNameInfo|[string, ParamNameInfo[]]}
|
|
208
|
-
*/
|
|
209
|
-
const getParamName = (param, isProperty) => {
|
|
210
|
-
const hasLeftTypeAnnotation = "left" in param && "typeAnnotation" in param.left;
|
|
211
|
-
if ("typeAnnotation" in param || hasLeftTypeAnnotation) {
|
|
212
|
-
const typeAnnotation = hasLeftTypeAnnotation ? param.left.typeAnnotation : param.typeAnnotation;
|
|
213
|
-
if (typeAnnotation?.typeAnnotation?.type === "TSTypeLiteral") {
|
|
214
|
-
const propertyNames = typeAnnotation.typeAnnotation.members.map((member) => {
|
|
215
|
-
return getPropertiesFromPropertySignature(member);
|
|
216
|
-
});
|
|
217
|
-
const flattened = {
|
|
218
|
-
...flattenRoots(propertyNames),
|
|
219
|
-
annotationParamName: "name" in param ? param.name : void 0
|
|
220
|
-
};
|
|
221
|
-
const hasLeftName = "left" in param && "name" in param.left;
|
|
222
|
-
if ("name" in param || hasLeftName) return [hasLeftName ? param.left.name : param.name, flattened];
|
|
223
|
-
return [void 0, flattened];
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
if ("name" in param) return param.name;
|
|
227
|
-
if ("left" in param && "name" in param.left) return param.left.name;
|
|
228
|
-
if (param.type === "ObjectPattern" || "left" in param && param.left.type === "ObjectPattern") {
|
|
229
|
-
const properties = param.properties || param.left?.properties;
|
|
230
|
-
const roots = properties.map((prop) => {
|
|
231
|
-
return getParamName(prop, true);
|
|
232
|
-
});
|
|
233
|
-
return [void 0, flattenRoots(roots)];
|
|
234
|
-
}
|
|
235
|
-
if (param.type === "Property") {
|
|
236
|
-
switch (param.value.type) {
|
|
237
|
-
case "ArrayPattern": return [param.key.name, param.value.elements.map((prop, idx) => {
|
|
238
|
-
return {
|
|
239
|
-
name: idx,
|
|
240
|
-
restElement: prop?.type === "RestElement"
|
|
241
|
-
};
|
|
242
|
-
})];
|
|
243
|
-
case "ObjectPattern": return [param.key.name, param.value.properties.map((prop) => {
|
|
244
|
-
return getParamName(prop, isProperty);
|
|
245
|
-
})];
|
|
246
|
-
case "AssignmentPattern": switch (param.value.left.type) {
|
|
247
|
-
case "ArrayPattern": return [param.key.name, param.value.left.elements.map((prop, idx) => {
|
|
248
|
-
return {
|
|
249
|
-
name: idx,
|
|
250
|
-
restElement: prop?.type === "RestElement"
|
|
251
|
-
};
|
|
252
|
-
})];
|
|
253
|
-
case "Identifier":
|
|
254
|
-
if (checkDefaultObjects && param.value.right.type === "ObjectExpression") return [param.key.name, param.value.right.properties.map((prop) => {
|
|
255
|
-
return getParamName(prop, isProperty);
|
|
256
|
-
})];
|
|
257
|
-
break;
|
|
258
|
-
case "ObjectPattern": return [param.key.name, param.value.left.properties.map((prop) => {
|
|
259
|
-
return getParamName(prop, isProperty);
|
|
260
|
-
})];
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
switch (param.key.type) {
|
|
264
|
-
case "Identifier": return param.key.name;
|
|
265
|
-
case "Literal":
|
|
266
|
-
/* c8 ignore next 2 -- `raw` may not be present in all parsers */
|
|
267
|
-
return param.key.raw || param.key.value;
|
|
268
|
-
default: return void 0;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
if (param.type === "ArrayPattern" || param.left?.type === "ArrayPattern") {
|
|
272
|
-
const elements = param.elements || param.left?.elements;
|
|
273
|
-
const roots = elements.map((prop, idx) => {
|
|
274
|
-
return {
|
|
275
|
-
name: `"${idx}"`,
|
|
276
|
-
restElement: prop?.type === "RestElement"
|
|
277
|
-
};
|
|
278
|
-
});
|
|
279
|
-
return [void 0, flattenRoots(roots)];
|
|
280
|
-
}
|
|
281
|
-
if (["ExperimentalRestProperty", "RestElement"].includes(param.type)) return {
|
|
282
|
-
isRestProperty: isProperty,
|
|
283
|
-
name: param.argument.name ?? param?.argument?.elements?.map(({ name }) => {
|
|
284
|
-
return name;
|
|
285
|
-
}),
|
|
286
|
-
restElement: true
|
|
287
|
-
};
|
|
288
|
-
if (param.type === "TSParameterProperty") return getParamName(
|
|
289
|
-
/** @type {import('@typescript-eslint/types').TSESTree.TSParameterProperty} */
|
|
290
|
-
param.parameter,
|
|
291
|
-
true
|
|
292
|
-
);
|
|
293
|
-
throw new Error(`Unsupported function signature format: \`${param.type}\`.`);
|
|
294
|
-
};
|
|
295
|
-
if (!functionNode) return [];
|
|
296
|
-
return (functionNode.params || functionNode.value?.params || []).map((param) => {
|
|
297
|
-
return getParamName(param);
|
|
298
|
-
});
|
|
299
|
-
};
|
|
300
|
-
/**
|
|
301
|
-
* @param {ESTreeOrTypeScriptNode} functionNode
|
|
302
|
-
* @returns {Integer}
|
|
303
|
-
*/
|
|
304
|
-
const hasParams = (functionNode) => {
|
|
305
|
-
return functionNode.params.length;
|
|
306
|
-
};
|
|
307
|
-
/**
|
|
308
|
-
* Gets all names of the target type, including those that refer to a path, e.g.
|
|
309
|
-
* `foo` or `foo.bar`.
|
|
310
|
-
* @param {import('comment-parser').Block} jsdoc
|
|
311
|
-
* @param {string} targetTagName
|
|
312
|
-
* @returns {{
|
|
313
|
-
* idx: Integer,
|
|
314
|
-
* name: string,
|
|
315
|
-
* type: string
|
|
316
|
-
* }[]}
|
|
317
|
-
*/
|
|
318
|
-
const getJsdocTagsDeep = (jsdoc, targetTagName) => {
|
|
319
|
-
const ret = [];
|
|
320
|
-
for (const [idx, { name, tag, type }] of jsdoc.tags.entries()) {
|
|
321
|
-
if (tag !== targetTagName) continue;
|
|
322
|
-
ret.push({
|
|
323
|
-
idx,
|
|
324
|
-
name,
|
|
325
|
-
type
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
return ret;
|
|
329
|
-
};
|
|
330
|
-
const modeWarnSettings = WarnSettings_default();
|
|
331
|
-
/**
|
|
332
|
-
* @param {ParserMode|undefined} mode
|
|
333
|
-
* @param {Reporter} context
|
|
334
|
-
* @returns {import('./tagNames.js').AliasedTags}
|
|
335
|
-
*/
|
|
336
|
-
const getTagNamesForMode = (mode, context) => {
|
|
337
|
-
switch (mode) {
|
|
338
|
-
case "closure":
|
|
339
|
-
case "permissive": return closureTags;
|
|
340
|
-
case "jsdoc": return jsdocTags;
|
|
341
|
-
case "typescript": return typeScriptTags;
|
|
342
|
-
default:
|
|
343
|
-
if (!modeWarnSettings.hasBeenWarned(context, "mode")) {
|
|
344
|
-
context.report({
|
|
345
|
-
loc: {
|
|
346
|
-
end: {
|
|
347
|
-
column: 1,
|
|
348
|
-
line: 1
|
|
349
|
-
},
|
|
350
|
-
start: {
|
|
351
|
-
column: 1,
|
|
352
|
-
line: 1
|
|
353
|
-
}
|
|
354
|
-
},
|
|
355
|
-
message: `Unrecognized value \`${mode}\` for \`settings.jsdoc.mode\`.`
|
|
356
|
-
});
|
|
357
|
-
modeWarnSettings.markSettingAsWarned(context, "mode");
|
|
358
|
-
}
|
|
359
|
-
return jsdocTags;
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
/**
|
|
363
|
-
* @param {import('comment-parser').Spec} tg
|
|
364
|
-
* @param {boolean} [returnArray]
|
|
365
|
-
* @returns {string[]|string}
|
|
366
|
-
*/
|
|
367
|
-
const getTagDescription = (tg, returnArray) => {
|
|
368
|
-
/**
|
|
369
|
-
* @type {string[]}
|
|
370
|
-
*/
|
|
371
|
-
const descriptions = [];
|
|
372
|
-
tg.source.some(({ tokens: { description, end, lineEnd, name, postDelimiter, postTag, tag, type } }) => {
|
|
373
|
-
const desc = (tag && postTag || !tag && !name && !type && postDelimiter || "").slice(1) + (description || "") + (lineEnd || "");
|
|
374
|
-
if (end) {
|
|
375
|
-
if (desc) descriptions.push(desc);
|
|
376
|
-
return true;
|
|
377
|
-
}
|
|
378
|
-
descriptions.push(desc);
|
|
379
|
-
return false;
|
|
380
|
-
});
|
|
381
|
-
return returnArray ? descriptions : descriptions.join("\n");
|
|
382
|
-
};
|
|
383
|
-
/**
|
|
384
|
-
* @typedef {{
|
|
385
|
-
* report: (descriptor: import('eslint').Rule.ReportDescriptor) => void
|
|
386
|
-
* }} Reporter
|
|
387
|
-
*/
|
|
388
|
-
/**
|
|
389
|
-
* @param {string} name
|
|
390
|
-
* @param {ParserMode|undefined} mode
|
|
391
|
-
* @param {TagNamePreference} tagPreference
|
|
392
|
-
* @param {Reporter} context
|
|
393
|
-
* @returns {string|false|{
|
|
394
|
-
* message: string;
|
|
395
|
-
* replacement?: string|undefined;
|
|
396
|
-
* }}
|
|
397
|
-
*/
|
|
398
|
-
const getPreferredTagNameSimple = (name, mode, tagPreference = {}, context = { report() {} }) => {
|
|
399
|
-
const prefValues = Object.values(tagPreference);
|
|
400
|
-
if (prefValues.includes(name) || prefValues.some((prefVal) => {
|
|
401
|
-
return prefVal && typeof prefVal === "object" && prefVal.replacement === name;
|
|
402
|
-
})) return name;
|
|
403
|
-
const tagPreferenceFixed = Object.fromEntries(Object.entries(tagPreference).map(([key, value]) => {
|
|
404
|
-
return [key.replace(/^tag /v, ""), value];
|
|
405
|
-
}));
|
|
406
|
-
if (Object.hasOwn(tagPreferenceFixed, name)) return tagPreferenceFixed[name];
|
|
407
|
-
const tagNames = getTagNamesForMode(mode, context);
|
|
408
|
-
const preferredTagName = Object.entries(tagNames).find(([, aliases]) => {
|
|
409
|
-
return aliases.includes(name);
|
|
410
|
-
})?.[0];
|
|
411
|
-
if (preferredTagName) return preferredTagName;
|
|
412
|
-
return name;
|
|
413
|
-
};
|
|
414
|
-
/**
|
|
415
|
-
* @param {import('eslint').Rule.RuleContext} context
|
|
416
|
-
* @param {ParserMode|undefined} mode
|
|
417
|
-
* @param {string} name
|
|
418
|
-
* @param {string[]} definedTags
|
|
419
|
-
* @returns {boolean}
|
|
420
|
-
*/
|
|
421
|
-
const isValidTag = (context, mode, name, definedTags) => {
|
|
422
|
-
const tagNames = getTagNamesForMode(mode, context);
|
|
423
|
-
const validTagNames = Object.keys(tagNames).concat(Object.values(tagNames).flat());
|
|
424
|
-
const additionalTags = definedTags;
|
|
425
|
-
const allTags = validTagNames.concat(additionalTags);
|
|
426
|
-
return allTags.includes(name);
|
|
427
|
-
};
|
|
428
|
-
/**
|
|
429
|
-
* @param {import('./iterateJsdoc.js').JsdocBlockWithInline} jsdoc
|
|
430
|
-
* @param {string} targetTagName
|
|
431
|
-
* @returns {boolean}
|
|
432
|
-
*/
|
|
433
|
-
const hasTag = (jsdoc, targetTagName) => {
|
|
434
|
-
const targetTagLower = targetTagName.toLowerCase();
|
|
435
|
-
return jsdoc.tags.some((doc) => {
|
|
436
|
-
return doc.tag.toLowerCase() === targetTagLower;
|
|
437
|
-
});
|
|
438
|
-
};
|
|
439
|
-
/**
|
|
440
|
-
* @param {import('./iterateJsdoc.js').JsdocBlockWithInline} jsdoc
|
|
441
|
-
* @param {(tag: import('@es-joy/jsdoccomment').JsdocTagWithInline) => boolean} filter
|
|
442
|
-
* @returns {import('@es-joy/jsdoccomment').JsdocTagWithInline[]}
|
|
443
|
-
*/
|
|
444
|
-
const filterTags = (jsdoc, filter) => {
|
|
445
|
-
return jsdoc.tags.filter((tag) => {
|
|
446
|
-
return filter(tag);
|
|
447
|
-
});
|
|
448
|
-
};
|
|
449
|
-
/**
|
|
450
|
-
* @param {import('./iterateJsdoc.js').JsdocBlockWithInline} jsdoc
|
|
451
|
-
* @param {string} tagName
|
|
452
|
-
* @returns {import('comment-parser').Spec[]}
|
|
453
|
-
*/
|
|
454
|
-
const getTags = (jsdoc, tagName) => {
|
|
455
|
-
return filterTags(jsdoc, (item) => {
|
|
456
|
-
return item.tag === tagName;
|
|
457
|
-
});
|
|
458
|
-
};
|
|
459
|
-
/**
|
|
460
|
-
* @param {import('./iterateJsdoc.js').JsdocBlockWithInline} jsdoc
|
|
461
|
-
* @param {{
|
|
462
|
-
* tagName: string,
|
|
463
|
-
* context?: import('eslint').Rule.RuleContext,
|
|
464
|
-
* mode?: ParserMode,
|
|
465
|
-
* report?: import('./iterateJsdoc.js').Report
|
|
466
|
-
* tagNamePreference?: TagNamePreference
|
|
467
|
-
* skipReportingBlockedTag?: boolean,
|
|
468
|
-
* allowObjectReturn?: boolean,
|
|
469
|
-
* defaultMessage?: string,
|
|
470
|
-
* }} cfg
|
|
471
|
-
* @returns {string|undefined|false|{
|
|
472
|
-
* message: string;
|
|
473
|
-
* replacement?: string|undefined;
|
|
474
|
-
* }|{
|
|
475
|
-
* blocked: true,
|
|
476
|
-
* tagName: string
|
|
477
|
-
* }}
|
|
478
|
-
*/
|
|
479
|
-
const getPreferredTagName = (jsdoc, { allowObjectReturn = false, context, tagName, defaultMessage = `Unexpected tag \`@${tagName}\``, mode, report = () => {}, skipReportingBlockedTag = false, tagNamePreference }) => {
|
|
480
|
-
const ret = getPreferredTagNameSimple(tagName, mode, tagNamePreference, context);
|
|
481
|
-
const isObject = ret && typeof ret === "object";
|
|
482
|
-
if (hasTag(jsdoc, tagName) && (ret === false || isObject && !ret.replacement)) {
|
|
483
|
-
if (skipReportingBlockedTag) return {
|
|
484
|
-
blocked: true,
|
|
485
|
-
tagName
|
|
486
|
-
};
|
|
487
|
-
const message = isObject && ret.message || defaultMessage;
|
|
488
|
-
report(message, null, getTags(jsdoc, tagName)[0]);
|
|
489
|
-
return false;
|
|
490
|
-
}
|
|
491
|
-
return isObject && !allowObjectReturn ? ret.replacement : ret;
|
|
492
|
-
};
|
|
493
|
-
/**
|
|
494
|
-
* @param {import('./iterateJsdoc.js').JsdocBlockWithInline} jsdoc
|
|
495
|
-
* @param {string} tagName
|
|
496
|
-
* @param {(
|
|
497
|
-
* matchingJsdocTag: import('@es-joy/jsdoccomment').JsdocTagWithInline,
|
|
498
|
-
* targetTagName: string
|
|
499
|
-
* ) => void} arrayHandler
|
|
500
|
-
* @param {object} cfg
|
|
501
|
-
* @param {import('eslint').Rule.RuleContext} [cfg.context]
|
|
502
|
-
* @param {ParserMode} [cfg.mode]
|
|
503
|
-
* @param {import('./iterateJsdoc.js').Report} [cfg.report]
|
|
504
|
-
* @param {TagNamePreference} [cfg.tagNamePreference]
|
|
505
|
-
* @param {boolean} [cfg.skipReportingBlockedTag]
|
|
506
|
-
* @returns {void}
|
|
507
|
-
*/
|
|
508
|
-
const forEachPreferredTag = (jsdoc, tagName, arrayHandler, { context, mode, report, skipReportingBlockedTag = false, tagNamePreference } = {}) => {
|
|
509
|
-
const targetTagName = getPreferredTagName(jsdoc, {
|
|
510
|
-
context,
|
|
511
|
-
mode,
|
|
512
|
-
report,
|
|
513
|
-
skipReportingBlockedTag,
|
|
514
|
-
tagName,
|
|
515
|
-
tagNamePreference
|
|
516
|
-
});
|
|
517
|
-
if (!targetTagName || skipReportingBlockedTag && targetTagName && typeof targetTagName === "object") return;
|
|
518
|
-
const matchingJsdocTags = jsdoc.tags.filter(({ tag }) => {
|
|
519
|
-
return tag === targetTagName;
|
|
520
|
-
});
|
|
521
|
-
for (const matchingJsdocTag of matchingJsdocTags) arrayHandler(matchingJsdocTag, targetTagName);
|
|
522
|
-
};
|
|
523
|
-
/**
|
|
524
|
-
* Get all tags, inline tags and inline tags in tags
|
|
525
|
-
* @param {import('./iterateJsdoc.js').JsdocBlockWithInline} jsdoc
|
|
526
|
-
* @returns {(import('comment-parser').Spec|
|
|
527
|
-
* import('@es-joy/jsdoccomment').JsdocInlineTagNoType)[]}
|
|
528
|
-
*/
|
|
529
|
-
const getAllTags = (jsdoc) => {
|
|
530
|
-
return [
|
|
531
|
-
...jsdoc.tags,
|
|
532
|
-
...jsdoc.inlineTags.map((inlineTag) => {
|
|
533
|
-
let line = -1;
|
|
534
|
-
for (const { tokens: { description } } of jsdoc.source) {
|
|
535
|
-
line++;
|
|
536
|
-
if (description && description.includes(`{@${inlineTag.tag}`)) break;
|
|
537
|
-
}
|
|
538
|
-
inlineTag.line = line;
|
|
539
|
-
return inlineTag;
|
|
540
|
-
}),
|
|
541
|
-
...jsdoc.tags.flatMap((tag) => {
|
|
542
|
-
let tagBegins = -1;
|
|
543
|
-
for (const { tokens: { tag: tg } } of jsdoc.source) {
|
|
544
|
-
tagBegins++;
|
|
545
|
-
if (tg) break;
|
|
546
|
-
}
|
|
547
|
-
for (const inlineTag of tag.inlineTags) {
|
|
548
|
-
/** @type {import('./iterateJsdoc.js').Integer} */
|
|
549
|
-
let line = 0;
|
|
550
|
-
for (const { number, tokens: { description } } of tag.source) if (description && description.includes(`{@${inlineTag.tag}`)) {
|
|
551
|
-
line = number;
|
|
552
|
-
break;
|
|
553
|
-
}
|
|
554
|
-
inlineTag.line = tagBegins + line - 1;
|
|
555
|
-
}
|
|
556
|
-
return tag.inlineTags;
|
|
557
|
-
})
|
|
558
|
-
];
|
|
559
|
-
};
|
|
560
|
-
/**
|
|
561
|
-
* @param {import('./iterateJsdoc.js').JsdocBlockWithInline} jsdoc
|
|
562
|
-
* @param {string[]} targetTagNames
|
|
563
|
-
* @returns {boolean}
|
|
564
|
-
*/
|
|
565
|
-
const hasATag = (jsdoc, targetTagNames) => {
|
|
566
|
-
return targetTagNames.some((targetTagName) => {
|
|
567
|
-
return hasTag(jsdoc, targetTagName);
|
|
568
|
-
});
|
|
569
|
-
};
|
|
570
|
-
/**
|
|
571
|
-
* Checks if the JSDoc comment has an undefined type.
|
|
572
|
-
* @param {import('comment-parser').Spec|null|undefined} tag
|
|
573
|
-
* the tag which should be checked.
|
|
574
|
-
* @param {ParserMode} mode
|
|
575
|
-
* @returns {boolean}
|
|
576
|
-
* true in case a defined type is undeclared; otherwise false.
|
|
577
|
-
*/
|
|
578
|
-
const mayBeUndefinedTypeTag = (tag, mode) => {
|
|
579
|
-
if (typeof tag === "undefined" || tag === null) return true;
|
|
580
|
-
const tagType = tag.type.trim();
|
|
581
|
-
if (tagType === "undefined" || tagType === "void" || tagType === "*" || tagType === "any") return true;
|
|
582
|
-
let parsedTypes;
|
|
583
|
-
try {
|
|
584
|
-
parsedTypes = tryParse(tagType, mode === "permissive" ? void 0 : [mode]);
|
|
585
|
-
} catch {}
|
|
586
|
-
if (parsedTypes && parsedTypes.type === "JsdocTypeUnion" && parsedTypes.elements.find((elem) => {
|
|
587
|
-
return elem.type === "JsdocTypeUndefined" || elem.type === "JsdocTypeName" && elem.value === "void";
|
|
588
|
-
})) return true;
|
|
589
|
-
return false;
|
|
590
|
-
};
|
|
591
|
-
/**
|
|
592
|
-
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} map
|
|
593
|
-
* @param {string} tag
|
|
594
|
-
* @returns {Map<string, string|string[]|boolean|undefined>}
|
|
595
|
-
*/
|
|
596
|
-
const ensureMap = (map, tag) => {
|
|
597
|
-
if (!map.has(tag)) map.set(tag, /* @__PURE__ */ new Map());
|
|
598
|
-
return map.get(tag);
|
|
599
|
-
};
|
|
600
|
-
/**
|
|
601
|
-
* @param {import('./iterateJsdoc.js').StructuredTags} structuredTags
|
|
602
|
-
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
603
|
-
* @returns {void}
|
|
604
|
-
*/
|
|
605
|
-
const overrideTagStructure = (structuredTags, tagMap = tagStructure) => {
|
|
606
|
-
for (const [tag, { name, required = [], type }] of Object.entries(structuredTags)) {
|
|
607
|
-
const tagStruct = ensureMap(tagMap, tag);
|
|
608
|
-
tagStruct.set("namepathRole", name);
|
|
609
|
-
tagStruct.set("typeAllowed", type);
|
|
610
|
-
const requiredName = required.includes("name");
|
|
611
|
-
if (requiredName && name === false) throw new Error("Cannot add \"name\" to `require` with the tag's `name` set to `false`");
|
|
612
|
-
tagStruct.set("nameRequired", requiredName);
|
|
613
|
-
const requiredType = required.includes("type");
|
|
614
|
-
if (requiredType && type === false) throw new Error("Cannot add \"type\" to `require` with the tag's `type` set to `false`");
|
|
615
|
-
tagStruct.set("typeRequired", requiredType);
|
|
616
|
-
const typeOrNameRequired = required.includes("typeOrNameRequired");
|
|
617
|
-
if (typeOrNameRequired && name === false) throw new Error("Cannot add \"typeOrNameRequired\" to `require` with the tag's `name` set to `false`");
|
|
618
|
-
if (typeOrNameRequired && type === false) throw new Error("Cannot add \"typeOrNameRequired\" to `require` with the tag's `type` set to `false`");
|
|
619
|
-
tagStruct.set("typeOrNameRequired", typeOrNameRequired);
|
|
620
|
-
}
|
|
621
|
-
};
|
|
622
|
-
/**
|
|
623
|
-
* @param {ParserMode} mode
|
|
624
|
-
* @param {import('./iterateJsdoc.js').StructuredTags} structuredTags
|
|
625
|
-
* @returns {import('./getDefaultTagStructureForMode.js').TagStructure}
|
|
626
|
-
*/
|
|
627
|
-
const getTagStructureForMode = (mode, structuredTags) => {
|
|
628
|
-
const tagStruct = getDefaultTagStructureForMode_default(mode);
|
|
629
|
-
try {
|
|
630
|
-
overrideTagStructure(structuredTags, tagStruct);
|
|
631
|
-
} catch {}
|
|
632
|
-
return tagStruct;
|
|
633
|
-
};
|
|
634
|
-
/**
|
|
635
|
-
* @param {string} tag
|
|
636
|
-
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
637
|
-
* @returns {boolean}
|
|
638
|
-
*/
|
|
639
|
-
const isNamepathDefiningTag = (tag, tagMap = tagStructure) => {
|
|
640
|
-
const tagStruct = ensureMap(tagMap, tag);
|
|
641
|
-
return tagStruct.get("namepathRole") === "namepath-defining";
|
|
642
|
-
};
|
|
643
|
-
/**
|
|
644
|
-
* @param {string} tag
|
|
645
|
-
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
646
|
-
* @returns {boolean}
|
|
647
|
-
*/
|
|
648
|
-
const isNamepathReferencingTag = (tag, tagMap = tagStructure) => {
|
|
649
|
-
const tagStruct = ensureMap(tagMap, tag);
|
|
650
|
-
return tagStruct.get("namepathRole") === "namepath-referencing";
|
|
651
|
-
};
|
|
652
|
-
/**
|
|
653
|
-
* @param {string} tag
|
|
654
|
-
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
655
|
-
* @returns {boolean}
|
|
656
|
-
*/
|
|
657
|
-
const isNamepathOrUrlReferencingTag = (tag, tagMap = tagStructure) => {
|
|
658
|
-
const tagStruct = ensureMap(tagMap, tag);
|
|
659
|
-
return tagStruct.get("namepathRole") === "namepath-or-url-referencing";
|
|
660
|
-
};
|
|
661
|
-
/**
|
|
662
|
-
* @param {string} tag
|
|
663
|
-
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
664
|
-
* @returns {boolean|undefined}
|
|
665
|
-
*/
|
|
666
|
-
const tagMustHaveTypePosition = (tag, tagMap = tagStructure) => {
|
|
667
|
-
const tagStruct = ensureMap(tagMap, tag);
|
|
668
|
-
return tagStruct.get("typeRequired");
|
|
669
|
-
};
|
|
670
|
-
/**
|
|
671
|
-
* @param {string} tag
|
|
672
|
-
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
673
|
-
* @returns {boolean|string}
|
|
674
|
-
*/
|
|
675
|
-
const tagMightHaveTypePosition = (tag, tagMap = tagStructure) => {
|
|
676
|
-
if (tagMustHaveTypePosition(tag, tagMap)) return true;
|
|
677
|
-
const tagStruct = ensureMap(tagMap, tag);
|
|
678
|
-
const ret = tagStruct.get("typeAllowed");
|
|
679
|
-
return ret === void 0 ? true : ret;
|
|
680
|
-
};
|
|
681
|
-
const namepathTypes = new Set(["namepath-defining", "namepath-referencing"]);
|
|
682
|
-
/**
|
|
683
|
-
* @param {string} tag
|
|
684
|
-
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
685
|
-
* @returns {boolean}
|
|
686
|
-
*/
|
|
687
|
-
const tagMightHaveNamePosition = (tag, tagMap = tagStructure) => {
|
|
688
|
-
const tagStruct = ensureMap(tagMap, tag);
|
|
689
|
-
const ret = tagStruct.get("namepathRole");
|
|
690
|
-
return ret === void 0 ? true : Boolean(ret);
|
|
691
|
-
};
|
|
692
|
-
/**
|
|
693
|
-
* @param {string} tag
|
|
694
|
-
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
695
|
-
* @returns {boolean}
|
|
696
|
-
*/
|
|
697
|
-
const tagMightHaveNamepath = (tag, tagMap = tagStructure) => {
|
|
698
|
-
const tagStruct = ensureMap(tagMap, tag);
|
|
699
|
-
const nampathRole = tagStruct.get("namepathRole");
|
|
700
|
-
return nampathRole !== false && namepathTypes.has(nampathRole);
|
|
701
|
-
};
|
|
702
|
-
/**
|
|
703
|
-
* @param {string} tag
|
|
704
|
-
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
705
|
-
* @returns {boolean|undefined}
|
|
706
|
-
*/
|
|
707
|
-
const tagMustHaveNamePosition = (tag, tagMap = tagStructure) => {
|
|
708
|
-
const tagStruct = ensureMap(tagMap, tag);
|
|
709
|
-
return tagStruct.get("nameRequired");
|
|
710
|
-
};
|
|
711
|
-
/**
|
|
712
|
-
* @param {string} tag
|
|
713
|
-
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
714
|
-
* @returns {boolean}
|
|
715
|
-
*/
|
|
716
|
-
const tagMightHaveEitherTypeOrNamePosition = (tag, tagMap) => {
|
|
717
|
-
return Boolean(tagMightHaveTypePosition(tag, tagMap)) || tagMightHaveNamepath(tag, tagMap);
|
|
718
|
-
};
|
|
719
|
-
/**
|
|
720
|
-
* @param {string} tag
|
|
721
|
-
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
722
|
-
* @returns {boolean|undefined}
|
|
723
|
-
*/
|
|
724
|
-
const tagMustHaveEitherTypeOrNamePosition = (tag, tagMap) => {
|
|
725
|
-
const tagStruct = ensureMap(tagMap, tag);
|
|
726
|
-
return tagStruct.get("typeOrNameRequired");
|
|
727
|
-
};
|
|
728
|
-
/**
|
|
729
|
-
* @param {import('comment-parser').Spec} tag
|
|
730
|
-
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
731
|
-
* @returns {boolean|undefined}
|
|
732
|
-
*/
|
|
733
|
-
const tagMissingRequiredTypeOrNamepath = (tag, tagMap = tagStructure) => {
|
|
734
|
-
const mustHaveTypePosition = tagMustHaveTypePosition(tag.tag, tagMap);
|
|
735
|
-
const mightHaveTypePosition = tagMightHaveTypePosition(tag.tag, tagMap);
|
|
736
|
-
const hasTypePosition = mightHaveTypePosition && Boolean(tag.type);
|
|
737
|
-
const hasNameOrNamepathPosition = (tagMustHaveNamePosition(tag.tag, tagMap) || tagMightHaveNamepath(tag.tag, tagMap)) && Boolean(tag.name);
|
|
738
|
-
const mustHaveEither = tagMustHaveEitherTypeOrNamePosition(tag.tag, tagMap);
|
|
739
|
-
const hasEither = tagMightHaveEitherTypeOrNamePosition(tag.tag, tagMap) && (hasTypePosition || hasNameOrNamepathPosition);
|
|
740
|
-
return mustHaveEither && !hasEither && !mustHaveTypePosition;
|
|
741
|
-
};
|
|
742
|
-
/**
|
|
743
|
-
* @param {ESTreeOrTypeScriptNode|null|undefined} node
|
|
744
|
-
* @param {boolean} [checkYieldReturnValue]
|
|
745
|
-
* @returns {boolean}
|
|
746
|
-
*/
|
|
747
|
-
const hasNonFunctionYield = (node, checkYieldReturnValue) => {
|
|
748
|
-
if (!node) return false;
|
|
749
|
-
switch (node.type) {
|
|
750
|
-
case "ArrayExpression":
|
|
751
|
-
case "ArrayPattern": return node.elements.some((element) => {
|
|
752
|
-
return hasNonFunctionYield(element, checkYieldReturnValue);
|
|
753
|
-
});
|
|
754
|
-
case "AssignmentExpression":
|
|
755
|
-
case "BinaryExpression":
|
|
756
|
-
case "LogicalExpression": return hasNonFunctionYield(node.left, checkYieldReturnValue) || hasNonFunctionYield(node.right, checkYieldReturnValue);
|
|
757
|
-
case "AssignmentPattern": return hasNonFunctionYield(node.right, checkYieldReturnValue);
|
|
758
|
-
case "BlockStatement": return node.body.some((bodyNode) => {
|
|
759
|
-
return ![
|
|
760
|
-
"ArrowFunctionExpression",
|
|
761
|
-
"FunctionDeclaration",
|
|
762
|
-
"FunctionExpression"
|
|
763
|
-
].includes(bodyNode.type) && hasNonFunctionYield(bodyNode, checkYieldReturnValue);
|
|
764
|
-
});
|
|
765
|
-
case "CallExpression":
|
|
766
|
-
case "OptionalCallExpression": return node.arguments.some((element) => {
|
|
767
|
-
return hasNonFunctionYield(element, checkYieldReturnValue);
|
|
768
|
-
});
|
|
769
|
-
case "ChainExpression":
|
|
770
|
-
case "ExpressionStatement": return hasNonFunctionYield(node.expression, checkYieldReturnValue);
|
|
771
|
-
case "ClassProperty":
|
|
772
|
-
case "ObjectProperty":
|
|
773
|
-
case "Property":
|
|
774
|
-
case "PropertyDefinition": return node.computed && hasNonFunctionYield(node.key, checkYieldReturnValue) || hasNonFunctionYield(node.value, checkYieldReturnValue);
|
|
775
|
-
case "ConditionalExpression":
|
|
776
|
-
case "IfStatement": return hasNonFunctionYield(node.test, checkYieldReturnValue) || hasNonFunctionYield(node.consequent, checkYieldReturnValue) || hasNonFunctionYield(node.alternate, checkYieldReturnValue);
|
|
777
|
-
case "DoWhileStatement":
|
|
778
|
-
case "ForInStatement":
|
|
779
|
-
case "ForOfStatement":
|
|
780
|
-
case "ForStatement":
|
|
781
|
-
case "LabeledStatement":
|
|
782
|
-
case "WhileStatement":
|
|
783
|
-
case "WithStatement": return hasNonFunctionYield(node.body, checkYieldReturnValue);
|
|
784
|
-
case "Import":
|
|
785
|
-
case "ImportExpression": return hasNonFunctionYield(node.source, checkYieldReturnValue);
|
|
786
|
-
case "MemberExpression":
|
|
787
|
-
case "OptionalMemberExpression": return hasNonFunctionYield(node.object, checkYieldReturnValue) || hasNonFunctionYield(node.property, checkYieldReturnValue);
|
|
788
|
-
case "ObjectExpression":
|
|
789
|
-
case "ObjectPattern": return node.properties.some((property) => {
|
|
790
|
-
return hasNonFunctionYield(property, checkYieldReturnValue);
|
|
791
|
-
});
|
|
792
|
-
case "ObjectMethod":
|
|
793
|
-
/* c8 ignore next 6 -- In Babel? */
|
|
794
|
-
return node.computed && hasNonFunctionYield(node.key, checkYieldReturnValue) || node.arguments.some((nde) => {
|
|
795
|
-
return hasNonFunctionYield(nde, checkYieldReturnValue);
|
|
796
|
-
});
|
|
797
|
-
case "ReturnStatement":
|
|
798
|
-
if (node.argument === null) return false;
|
|
799
|
-
return hasNonFunctionYield(node.argument, checkYieldReturnValue);
|
|
800
|
-
case "SequenceExpression":
|
|
801
|
-
case "TemplateLiteral": return node.expressions.some((subExpression) => {
|
|
802
|
-
return hasNonFunctionYield(subExpression, checkYieldReturnValue);
|
|
803
|
-
});
|
|
804
|
-
case "SpreadElement":
|
|
805
|
-
case "UnaryExpression": return hasNonFunctionYield(node.argument, checkYieldReturnValue);
|
|
806
|
-
case "SwitchStatement": return node.cases.some((someCase) => {
|
|
807
|
-
return someCase.consequent.some((nde) => {
|
|
808
|
-
return hasNonFunctionYield(nde, checkYieldReturnValue);
|
|
809
|
-
});
|
|
810
|
-
});
|
|
811
|
-
case "TaggedTemplateExpression": return hasNonFunctionYield(node.quasi, checkYieldReturnValue);
|
|
812
|
-
case "TryStatement": return hasNonFunctionYield(node.block, checkYieldReturnValue) || hasNonFunctionYield(node.handler && node.handler.body, checkYieldReturnValue) || hasNonFunctionYield(node.finalizer, checkYieldReturnValue);
|
|
813
|
-
case "VariableDeclaration": return node.declarations.some((nde) => {
|
|
814
|
-
return hasNonFunctionYield(nde, checkYieldReturnValue);
|
|
815
|
-
});
|
|
816
|
-
case "VariableDeclarator": return hasNonFunctionYield(node.id, checkYieldReturnValue) || hasNonFunctionYield(node.init, checkYieldReturnValue);
|
|
817
|
-
case "YieldExpression":
|
|
818
|
-
if (checkYieldReturnValue) {
|
|
819
|
-
if (node.parent.type === "VariableDeclarator") return true;
|
|
820
|
-
return false;
|
|
821
|
-
}
|
|
822
|
-
if (node.argument === null) return false;
|
|
823
|
-
return true;
|
|
824
|
-
default: return false;
|
|
825
|
-
}
|
|
826
|
-
};
|
|
827
|
-
/**
|
|
828
|
-
* Checks if a node has a return statement. Void return does not count.
|
|
829
|
-
* @param {ESTreeOrTypeScriptNode} node
|
|
830
|
-
* @param {boolean} [checkYieldReturnValue]
|
|
831
|
-
* @returns {boolean}
|
|
832
|
-
*/
|
|
833
|
-
const hasYieldValue = (node, checkYieldReturnValue) => {
|
|
834
|
-
return node.generator && (node.expression || hasNonFunctionYield(
|
|
835
|
-
/** @type {import('@typescript-eslint/types').TSESTree.FunctionDeclaration} */
|
|
836
|
-
node.body,
|
|
837
|
-
checkYieldReturnValue
|
|
838
|
-
));
|
|
839
|
-
};
|
|
840
|
-
/**
|
|
841
|
-
* Checks if a node has a throws statement.
|
|
842
|
-
* @param {ESTreeOrTypeScriptNode|null|undefined} node
|
|
843
|
-
* @param {boolean} [innerFunction]
|
|
844
|
-
* @returns {boolean}
|
|
845
|
-
*/
|
|
846
|
-
const hasThrowValue = (node, innerFunction) => {
|
|
847
|
-
if (!node) return false;
|
|
848
|
-
switch (node.type) {
|
|
849
|
-
case "ArrowFunctionExpression":
|
|
850
|
-
case "FunctionDeclaration":
|
|
851
|
-
case "FunctionExpression": return !innerFunction && !node.async && hasThrowValue(node.body, true);
|
|
852
|
-
case "BlockStatement": return node.body.some((bodyNode) => {
|
|
853
|
-
return bodyNode.type !== "FunctionDeclaration" && hasThrowValue(bodyNode);
|
|
854
|
-
});
|
|
855
|
-
case "DoWhileStatement":
|
|
856
|
-
case "ForInStatement":
|
|
857
|
-
case "ForOfStatement":
|
|
858
|
-
case "ForStatement":
|
|
859
|
-
case "LabeledStatement":
|
|
860
|
-
case "WhileStatement":
|
|
861
|
-
case "WithStatement": return hasThrowValue(node.body);
|
|
862
|
-
case "IfStatement": return hasThrowValue(node.consequent) || hasThrowValue(node.alternate);
|
|
863
|
-
case "SwitchStatement": return node.cases.some((someCase) => {
|
|
864
|
-
return someCase.consequent.some((nde) => {
|
|
865
|
-
return hasThrowValue(nde);
|
|
866
|
-
});
|
|
867
|
-
});
|
|
868
|
-
case "ThrowStatement": return true;
|
|
869
|
-
case "TryStatement": return hasThrowValue(node.handler && node.handler.body) || hasThrowValue(node.finalizer);
|
|
870
|
-
default: return false;
|
|
871
|
-
}
|
|
872
|
-
};
|
|
873
|
-
/**
|
|
874
|
-
* @param {string} tag
|
|
875
|
-
*/
|
|
876
|
-
/**
|
|
877
|
-
* Parses GCC Generic/Template types
|
|
878
|
-
* @see {@link https://github.com/google/closure-compiler/wiki/Generic-Types}
|
|
879
|
-
* @see {@link https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#template}
|
|
880
|
-
* @param {import('comment-parser').Spec} tag
|
|
881
|
-
* @returns {string[]}
|
|
882
|
-
*/
|
|
883
|
-
const parseClosureTemplateTag = (tag) => {
|
|
884
|
-
return tag.name.split(",").map((type) => {
|
|
885
|
-
return type.trim().replace(/^\[?(?<name>.*?)=.*$/v, "$<name>");
|
|
886
|
-
});
|
|
887
|
-
};
|
|
888
|
-
/**
|
|
889
|
-
* @typedef {true|string[]} DefaultContexts
|
|
890
|
-
*/
|
|
891
|
-
/**
|
|
892
|
-
* Checks user option for `contexts` array, defaulting to
|
|
893
|
-
* contexts designated by the rule. Returns an array of
|
|
894
|
-
* ESTree AST types, indicating allowable contexts.
|
|
895
|
-
* @param {import('eslint').Rule.RuleContext} context
|
|
896
|
-
* @param {DefaultContexts|undefined} defaultContexts
|
|
897
|
-
* @param {{
|
|
898
|
-
* contexts?: import('./iterateJsdoc.js').Context[]
|
|
899
|
-
* }} settings
|
|
900
|
-
* @returns {(string|import('./iterateJsdoc.js').ContextObject)[]}
|
|
901
|
-
*/
|
|
902
|
-
const enforcedContexts = (context, defaultContexts, settings) => {
|
|
903
|
-
const contexts = context.options[0]?.contexts || settings.contexts || (defaultContexts === true ? [
|
|
904
|
-
"ArrowFunctionExpression",
|
|
905
|
-
"FunctionDeclaration",
|
|
906
|
-
"FunctionExpression",
|
|
907
|
-
"TSDeclareFunction"
|
|
908
|
-
] : defaultContexts);
|
|
909
|
-
return contexts;
|
|
910
|
-
};
|
|
911
|
-
/**
|
|
912
|
-
* @param {import('./iterateJsdoc.js').Context[]} contexts
|
|
913
|
-
* @param {import('./iterateJsdoc.js').CheckJsdoc} checkJsdoc
|
|
914
|
-
* @param {import('@es-joy/jsdoccomment').CommentHandler} [handler]
|
|
915
|
-
* @returns {import('eslint').Rule.RuleListener}
|
|
916
|
-
*/
|
|
917
|
-
const getContextObject = (contexts, checkJsdoc, handler) => {
|
|
918
|
-
/** @type {import('eslint').Rule.RuleListener} */
|
|
919
|
-
const properties = {};
|
|
920
|
-
for (const [idx, prop] of contexts.entries()) {
|
|
921
|
-
/** @type {string} */
|
|
922
|
-
let property;
|
|
923
|
-
/** @type {(node: import('eslint').Rule.Node) => void} */
|
|
924
|
-
let value;
|
|
925
|
-
if (typeof prop === "object") {
|
|
926
|
-
const selInfo = {
|
|
927
|
-
lastIndex: idx,
|
|
928
|
-
selector: prop.context
|
|
929
|
-
};
|
|
930
|
-
if (prop.comment) {
|
|
931
|
-
property = prop.context;
|
|
932
|
-
value = checkJsdoc.bind(
|
|
933
|
-
null,
|
|
934
|
-
{
|
|
935
|
-
...selInfo,
|
|
936
|
-
comment: prop.comment
|
|
937
|
-
},
|
|
938
|
-
/** @type {import('@es-joy/jsdoccomment').CommentHandler} */
|
|
939
|
-
handler.bind(null, prop.comment)
|
|
940
|
-
);
|
|
941
|
-
} else {
|
|
942
|
-
property = prop.context;
|
|
943
|
-
value = checkJsdoc.bind(null, selInfo, null);
|
|
944
|
-
}
|
|
945
|
-
} else {
|
|
946
|
-
const selInfo = {
|
|
947
|
-
lastIndex: idx,
|
|
948
|
-
selector: prop
|
|
949
|
-
};
|
|
950
|
-
property = prop;
|
|
951
|
-
value = checkJsdoc.bind(null, selInfo, null);
|
|
952
|
-
}
|
|
953
|
-
const old = properties[property];
|
|
954
|
-
properties[property] = old ? function(node) {
|
|
955
|
-
old(node);
|
|
956
|
-
value(node);
|
|
957
|
-
} : value;
|
|
958
|
-
}
|
|
959
|
-
return properties;
|
|
960
|
-
};
|
|
961
|
-
const tagsWithNamesAndDescriptions = new Set([
|
|
962
|
-
"arg",
|
|
963
|
-
"argument",
|
|
964
|
-
"param",
|
|
965
|
-
"prop",
|
|
966
|
-
"property",
|
|
967
|
-
"return",
|
|
968
|
-
"returns",
|
|
969
|
-
"template"
|
|
970
|
-
]);
|
|
971
|
-
/**
|
|
972
|
-
* @typedef {{
|
|
973
|
-
* [key: string]: false|string|
|
|
974
|
-
* {message: string, replacement?: string}
|
|
975
|
-
* }} TagNamePreference
|
|
976
|
-
*/
|
|
977
|
-
/**
|
|
978
|
-
* @param {import('eslint').Rule.RuleContext} context
|
|
979
|
-
* @param {ParserMode|undefined} mode
|
|
980
|
-
* @param {import('comment-parser').Spec[]} tags
|
|
981
|
-
* @returns {{
|
|
982
|
-
* tagsWithNames: import('comment-parser').Spec[],
|
|
983
|
-
* tagsWithoutNames: import('comment-parser').Spec[]
|
|
984
|
-
* }}
|
|
985
|
-
*/
|
|
986
|
-
const getTagsByType = (context, mode, tags) => {
|
|
987
|
-
/**
|
|
988
|
-
* @type {import('comment-parser').Spec[]}
|
|
989
|
-
*/
|
|
990
|
-
const tagsWithoutNames = [];
|
|
991
|
-
const tagsWithNames = tags.filter((tag) => {
|
|
992
|
-
const { tag: tagName } = tag;
|
|
993
|
-
const tagWithName = tagsWithNamesAndDescriptions.has(tagName);
|
|
994
|
-
if (!tagWithName) tagsWithoutNames.push(tag);
|
|
995
|
-
return tagWithName;
|
|
996
|
-
});
|
|
997
|
-
return {
|
|
998
|
-
tagsWithNames,
|
|
999
|
-
tagsWithoutNames
|
|
1000
|
-
};
|
|
1001
|
-
};
|
|
1002
|
-
/**
|
|
1003
|
-
* @param {import('eslint').SourceCode|{
|
|
1004
|
-
* text: string
|
|
1005
|
-
* }} sourceCode
|
|
1006
|
-
* @returns {string}
|
|
1007
|
-
*/
|
|
1008
|
-
const getIndent = (sourceCode) => {
|
|
1009
|
-
return (sourceCode.text.match(/^\n*([ \t]+)/v)?.[1] ?? "") + " ";
|
|
1010
|
-
};
|
|
1011
|
-
/**
|
|
1012
|
-
* @param {import('eslint').Rule.Node|null} node
|
|
1013
|
-
* @returns {boolean}
|
|
1014
|
-
*/
|
|
1015
|
-
const isConstructor = (node) => {
|
|
1016
|
-
return node?.type === "MethodDefinition" && node.kind === "constructor" || (node?.parent)?.kind === "constructor";
|
|
1017
|
-
};
|
|
1018
|
-
/**
|
|
1019
|
-
* @param {import('eslint').Rule.Node|null} node
|
|
1020
|
-
* @returns {boolean}
|
|
1021
|
-
*/
|
|
1022
|
-
const isGetter = (node) => {
|
|
1023
|
-
return node !== null && node.parent?.kind === "get";
|
|
1024
|
-
};
|
|
1025
|
-
/**
|
|
1026
|
-
* @param {import('eslint').Rule.Node|null} node
|
|
1027
|
-
* @returns {boolean}
|
|
1028
|
-
*/
|
|
1029
|
-
const isSetter = (node) => {
|
|
1030
|
-
return node !== null && node.parent?.kind === "set";
|
|
1031
|
-
};
|
|
1032
|
-
/**
|
|
1033
|
-
* @param {import('eslint').Rule.Node} node
|
|
1034
|
-
* @returns {boolean}
|
|
1035
|
-
*/
|
|
1036
|
-
const hasAccessorPair = (node) => {
|
|
1037
|
-
const { key, kind: sourceKind, type } = node;
|
|
1038
|
-
const sourceName = key.name;
|
|
1039
|
-
const oppositeKind = sourceKind === "get" ? "set" : "get";
|
|
1040
|
-
const sibling = type === "MethodDefinition" ? node.parent.body : node.parent.properties;
|
|
1041
|
-
return sibling.some((child) => {
|
|
1042
|
-
const { key: ky, kind } = child;
|
|
1043
|
-
const name = ky.name;
|
|
1044
|
-
return kind === oppositeKind && name === sourceName;
|
|
1045
|
-
});
|
|
1046
|
-
};
|
|
1047
|
-
/**
|
|
1048
|
-
* @param {import('./iterateJsdoc.js').JsdocBlockWithInline} jsdoc
|
|
1049
|
-
* @param {import('eslint').Rule.Node|null} node
|
|
1050
|
-
* @param {import('eslint').Rule.RuleContext} context
|
|
1051
|
-
* @param {import('json-schema').JSONSchema4} schema
|
|
1052
|
-
* @returns {boolean}
|
|
1053
|
-
*/
|
|
1054
|
-
const exemptSpeciaMethods = (jsdoc, node, context, schema) => {
|
|
1055
|
-
/**
|
|
1056
|
-
* @param {"checkGetters"|"checkSetters"|"checkConstructors"} prop
|
|
1057
|
-
* @returns {boolean|"no-setter"|"no-getter"}
|
|
1058
|
-
*/
|
|
1059
|
-
const hasSchemaOption = (prop) => {
|
|
1060
|
-
const schemaProperties = schema[0].properties;
|
|
1061
|
-
return context.options[0]?.[prop] ?? (schemaProperties[prop] && schemaProperties[prop].default);
|
|
1062
|
-
};
|
|
1063
|
-
const checkGetters = hasSchemaOption("checkGetters");
|
|
1064
|
-
const checkSetters = hasSchemaOption("checkSetters");
|
|
1065
|
-
return !hasSchemaOption("checkConstructors") && (isConstructor(node) || hasATag(jsdoc, ["class", "constructor"])) || isGetter(node) && (!checkGetters || checkGetters === "no-setter" && hasAccessorPair(
|
|
1066
|
-
/** @type {import('./iterateJsdoc.js').Node} */
|
|
1067
|
-
node.parent
|
|
1068
|
-
)) || isSetter(node) && (!checkSetters || checkSetters === "no-getter" && hasAccessorPair(
|
|
1069
|
-
/** @type {import('./iterateJsdoc.js').Node} */
|
|
1070
|
-
node.parent
|
|
1071
|
-
));
|
|
1072
|
-
};
|
|
1073
|
-
/**
|
|
1074
|
-
* Since path segments may be unquoted (if matching a reserved word,
|
|
1075
|
-
* identifier or numeric literal) or single or double quoted, in either
|
|
1076
|
-
* the `@param` or in source, we need to strip the quotes to give a fair
|
|
1077
|
-
* comparison.
|
|
1078
|
-
* @param {string} str
|
|
1079
|
-
* @returns {string}
|
|
1080
|
-
*/
|
|
1081
|
-
const dropPathSegmentQuotes = (str) => {
|
|
1082
|
-
return str.replaceAll(/\.(['"])(.*)\1/gv, ".$2");
|
|
1083
|
-
};
|
|
1084
|
-
/**
|
|
1085
|
-
* @param {string} name
|
|
1086
|
-
* @returns {(otherPathName: string) => boolean}
|
|
1087
|
-
*/
|
|
1088
|
-
const comparePaths = (name) => {
|
|
1089
|
-
return (otherPathName) => {
|
|
1090
|
-
return otherPathName === name || dropPathSegmentQuotes(otherPathName) === dropPathSegmentQuotes(name);
|
|
1091
|
-
};
|
|
1092
|
-
};
|
|
1093
|
-
/**
|
|
1094
|
-
* @callback PathDoesNotBeginWith
|
|
1095
|
-
* @param {string} name
|
|
1096
|
-
* @param {string} otherPathName
|
|
1097
|
-
* @returns {boolean}
|
|
1098
|
-
*/
|
|
1099
|
-
/** @type {PathDoesNotBeginWith} */
|
|
1100
|
-
const pathDoesNotBeginWith = (name, otherPathName) => {
|
|
1101
|
-
return !name.startsWith(otherPathName) && !dropPathSegmentQuotes(name).startsWith(dropPathSegmentQuotes(otherPathName));
|
|
1102
|
-
};
|
|
1103
|
-
/**
|
|
1104
|
-
* @param {string} regexString
|
|
1105
|
-
* @param {string} [requiredFlags]
|
|
1106
|
-
* @returns {RegExp}
|
|
1107
|
-
*/
|
|
1108
|
-
const getRegexFromString = (regexString, requiredFlags) => {
|
|
1109
|
-
const match = regexString.match(/^\/(.*)\/([gimyvus]*)$/sv);
|
|
1110
|
-
let flags = "v";
|
|
1111
|
-
let regex = regexString;
|
|
1112
|
-
if (match) {
|
|
1113
|
-
[, regex, flags] = match;
|
|
1114
|
-
if (!flags) flags = "v";
|
|
1115
|
-
}
|
|
1116
|
-
const uniqueFlags = [...new Set(flags + (requiredFlags || ""))];
|
|
1117
|
-
flags = uniqueFlags.join("");
|
|
1118
|
-
return new RegExp(regex, flags);
|
|
1119
|
-
};
|
|
1120
|
-
|
|
1121
|
-
//#endregion
|
|
1122
|
-
export { comparePaths, dropPathSegmentQuotes, enforcedContexts, exemptSpeciaMethods, filterTags, flattenRoots, forEachPreferredTag, getAllTags, getContextObject, getFunctionParameterNames, getIndent, getJsdocTagsDeep, getPreferredTagName, getPreferredTagNameSimple, getRegexFromString, getTagDescription, getTagStructureForMode, getTags, getTagsByType, hasATag, hasParams, hasTag, hasThrowValue, hasYieldValue, isConstructor, isValidTag, jsdocUtils_exports, mayBeUndefinedTypeTag, overrideTagStructure, parseClosureTemplateTag, pathDoesNotBeginWith, setTagStructure, tagMissingRequiredTypeOrNamepath };
|
|
1123
|
-
//# sourceMappingURL=jsdocUtils.js.map
|