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/rules/sortTags.cjs
CHANGED
|
@@ -1,262 +1,448 @@
|
|
|
1
|
-
|
|
2
|
-
const require_defaultTagOrder = require('../defaultTagOrder.cjs');
|
|
1
|
+
"use strict";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { alphabetizeExtras = false, linesBetween = 1, reportIntraTagGroupSpacing = true, reportTagGroupSpacing = true, tagSequence = require_defaultTagOrder.default } = context.options[0] || {};
|
|
7
|
-
const tagList = tagSequence.flatMap((obj) => {
|
|
8
|
-
return obj.tags;
|
|
9
|
-
});
|
|
10
|
-
const otherPos = tagList.indexOf("-other");
|
|
11
|
-
const endPos = otherPos > -1 ? otherPos : tagList.length;
|
|
12
|
-
let ongoingCount = 0;
|
|
13
|
-
for (const [idx, tag] of jsdoc.tags.entries()) {
|
|
14
|
-
tag.originalIndex = idx;
|
|
15
|
-
ongoingCount += tag.source.length;
|
|
16
|
-
tag.originalLine = ongoingCount;
|
|
17
|
-
}
|
|
18
|
-
/** @type {import('../iterateJsdoc.js').Integer|undefined} */
|
|
19
|
-
let firstChangedTagLine;
|
|
20
|
-
/** @type {import('../iterateJsdoc.js').Integer|undefined} */
|
|
21
|
-
let firstChangedTagIndex;
|
|
22
|
-
/**
|
|
23
|
-
* @type {(import('comment-parser').Spec & {
|
|
24
|
-
* originalIndex: import('../iterateJsdoc.js').Integer,
|
|
25
|
-
* originalLine: import('../iterateJsdoc.js').Integer,
|
|
26
|
-
* })[]}
|
|
27
|
-
*/
|
|
28
|
-
const sortedTags = JSON.parse(JSON.stringify(jsdoc.tags));
|
|
29
|
-
sortedTags.sort(({ tag: tagNew }, { originalIndex, originalLine, tag: tagOld }) => {
|
|
30
|
-
if (tagNew === tagOld) return 0;
|
|
31
|
-
const checkOrSetFirstChanged = () => {
|
|
32
|
-
if (!firstChangedTagLine || originalLine < firstChangedTagLine) {
|
|
33
|
-
firstChangedTagLine = originalLine;
|
|
34
|
-
firstChangedTagIndex = originalIndex;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const newPos = tagList.indexOf(tagNew);
|
|
38
|
-
const oldPos = tagList.indexOf(tagOld);
|
|
39
|
-
const preferredNewPos = newPos === -1 ? endPos : newPos;
|
|
40
|
-
const preferredOldPos = oldPos === -1 ? endPos : oldPos;
|
|
41
|
-
if (preferredNewPos < preferredOldPos) {
|
|
42
|
-
checkOrSetFirstChanged();
|
|
43
|
-
return -1;
|
|
44
|
-
}
|
|
45
|
-
if (preferredNewPos > preferredOldPos) return 1;
|
|
46
|
-
if (!alphabetizeExtras || newPos >= 0) return 0;
|
|
47
|
-
if (tagNew < tagOld) {
|
|
48
|
-
checkOrSetFirstChanged();
|
|
49
|
-
return -1;
|
|
50
|
-
}
|
|
51
|
-
return 1;
|
|
52
|
-
});
|
|
53
|
-
if (firstChangedTagLine === void 0) {
|
|
54
|
-
/**
|
|
55
|
-
* @type {import('comment-parser').Spec[]}
|
|
56
|
-
*/
|
|
57
|
-
const lastTagsOfGroup = [];
|
|
58
|
-
/**
|
|
59
|
-
* @type {[
|
|
60
|
-
* import('comment-parser').Spec,
|
|
61
|
-
* import('../iterateJsdoc.js').Integer
|
|
62
|
-
* ][]}
|
|
63
|
-
*/
|
|
64
|
-
const badLastTagsOfGroup = [];
|
|
65
|
-
/**
|
|
66
|
-
* @param {import('comment-parser').Spec} tag
|
|
67
|
-
*/
|
|
68
|
-
const countTagEmptyLines = (tag) => {
|
|
69
|
-
return tag.source.reduce((acc, { tokens: { description, end, name, tag: tg, type } }) => {
|
|
70
|
-
const empty = !tg && !type && !name && !description;
|
|
71
|
-
return empty ? acc + Number(empty && !end) : 0;
|
|
72
|
-
}, 0);
|
|
73
|
-
};
|
|
74
|
-
let idx = 0;
|
|
75
|
-
for (const { tags } of tagSequence) {
|
|
76
|
-
let innerIdx;
|
|
77
|
-
/** @type {import('comment-parser').Spec} */
|
|
78
|
-
let currentTag;
|
|
79
|
-
/** @type {import('comment-parser').Spec|undefined} */
|
|
80
|
-
let lastTag;
|
|
81
|
-
do {
|
|
82
|
-
currentTag = jsdoc.tags[idx];
|
|
83
|
-
if (!currentTag) {
|
|
84
|
-
idx++;
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
innerIdx = tags.indexOf(currentTag.tag);
|
|
88
|
-
if (innerIdx === -1 && (!tags.includes("-other") || tagSequence.some(({ tags: tgs }) => {
|
|
89
|
-
return tgs.includes(currentTag.tag);
|
|
90
|
-
}))) {
|
|
91
|
-
idx++;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
lastTag = currentTag;
|
|
95
|
-
idx++;
|
|
96
|
-
} while (true);
|
|
97
|
-
idx--;
|
|
98
|
-
if (lastTag) {
|
|
99
|
-
lastTagsOfGroup.push(lastTag);
|
|
100
|
-
const ct = countTagEmptyLines(lastTag);
|
|
101
|
-
if (ct !== linesBetween && jsdoc.tags[idx]) badLastTagsOfGroup.push([lastTag, ct]);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (reportTagGroupSpacing && badLastTagsOfGroup.length) {
|
|
105
|
-
/**
|
|
106
|
-
* @param {import('comment-parser').Spec} tg
|
|
107
|
-
* @returns {() => void}
|
|
108
|
-
*/
|
|
109
|
-
const fixer = (tg) => {
|
|
110
|
-
return () => {
|
|
111
|
-
for (const [currIdx, { tokens }] of jsdoc.source.entries()) {
|
|
112
|
-
if (tokens.tag !== "@" + tg.tag) continue;
|
|
113
|
-
let newIdx = currIdx;
|
|
114
|
-
const emptyLine = () => {
|
|
115
|
-
return {
|
|
116
|
-
number: 0,
|
|
117
|
-
source: "",
|
|
118
|
-
tokens: utils.seedTokens({
|
|
119
|
-
delimiter: "*",
|
|
120
|
-
start: jsdoc.source[newIdx - 1].tokens.start
|
|
121
|
-
})
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
let existingEmptyLines = 0;
|
|
125
|
-
while (true) {
|
|
126
|
-
const nextTokens = jsdoc.source[++newIdx]?.tokens;
|
|
127
|
-
/* c8 ignore next 3 -- Guard */
|
|
128
|
-
if (!nextTokens) return;
|
|
129
|
-
if (nextTokens.tag) {
|
|
130
|
-
if (nextTokens.tag === tokens.tag) {
|
|
131
|
-
existingEmptyLines = 0;
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
const lineDiff = linesBetween - existingEmptyLines;
|
|
135
|
-
if (lineDiff > 0) {
|
|
136
|
-
const lines = Array.from({ length: lineDiff }, () => {
|
|
137
|
-
return emptyLine();
|
|
138
|
-
});
|
|
139
|
-
jsdoc.source.splice(newIdx, 0, ...lines);
|
|
140
|
-
} else jsdoc.source.splice(newIdx + lineDiff, -lineDiff);
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
const empty = !nextTokens.type && !nextTokens.name && !nextTokens.description;
|
|
144
|
-
if (empty) existingEmptyLines++;
|
|
145
|
-
else existingEmptyLines = 0;
|
|
146
|
-
}
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
for (const [srcIdx, src] of jsdoc.source.entries()) src.number = srcIdx;
|
|
150
|
-
};
|
|
151
|
-
};
|
|
152
|
-
for (const [tg] of badLastTagsOfGroup) utils.reportJSDoc("Tag groups do not have the expected whitespace", tg, fixer(tg));
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
if (!reportIntraTagGroupSpacing) return;
|
|
156
|
-
for (const [tagIdx, tag] of jsdoc.tags.entries()) {
|
|
157
|
-
if (!jsdoc.tags[tagIdx + 1] || lastTagsOfGroup.includes(tag)) continue;
|
|
158
|
-
const ct = countTagEmptyLines(tag);
|
|
159
|
-
if (ct) {
|
|
160
|
-
const fixer = () => {
|
|
161
|
-
let foundFirstTag = false;
|
|
162
|
-
/** @type {string|undefined} */
|
|
163
|
-
let currentTag;
|
|
164
|
-
for (const [currIdx, { tokens: { description, end, name, tag: tg, type } }] of jsdoc.source.entries()) {
|
|
165
|
-
if (tg) {
|
|
166
|
-
foundFirstTag = true;
|
|
167
|
-
currentTag = tg;
|
|
168
|
-
}
|
|
169
|
-
if (!foundFirstTag) continue;
|
|
170
|
-
if (currentTag && !tg && !type && !name && !description && !end) {
|
|
171
|
-
let nextIdx = currIdx;
|
|
172
|
-
let ignore = true;
|
|
173
|
-
if (lastTagsOfGroup.some((lastTagOfGroup) => {
|
|
174
|
-
return currentTag === "@" + lastTagOfGroup.tag;
|
|
175
|
-
})) while (true) {
|
|
176
|
-
const nextTokens = jsdoc.source[++nextIdx]?.tokens;
|
|
177
|
-
if (!nextTokens) break;
|
|
178
|
-
if (!nextTokens.tag) continue;
|
|
179
|
-
if (nextTokens.tag === currentTag) ignore = false;
|
|
180
|
-
}
|
|
181
|
-
else while (true) {
|
|
182
|
-
const nextTokens = jsdoc.source[++nextIdx]?.tokens;
|
|
183
|
-
if (!nextTokens || nextTokens.end) break;
|
|
184
|
-
if (nextTokens.tag) {
|
|
185
|
-
ignore = false;
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
if (!ignore) {
|
|
190
|
-
jsdoc.source.splice(currIdx, 1);
|
|
191
|
-
for (const [srcIdx, src] of jsdoc.source.entries()) src.number = srcIdx;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
utils.reportJSDoc("Intra-group tags have unexpected whitespace", tag, fixer);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const firstLine = utils.getFirstLine();
|
|
202
|
-
const fix = () => {
|
|
203
|
-
const itemsToMoveRange = [...Array.from({ length: jsdoc.tags.length - firstChangedTagIndex }).keys()];
|
|
204
|
-
const unchangedPriorTagDescriptions = jsdoc.tags.slice(0, firstChangedTagIndex).reduce((ct, { source }) => {
|
|
205
|
-
return ct + source.length - 1;
|
|
206
|
-
}, 0);
|
|
207
|
-
const initialOffset = firstLine + firstChangedTagIndex + unchangedPriorTagDescriptions;
|
|
208
|
-
for (const idx of itemsToMoveRange) utils.removeTag(idx + firstChangedTagIndex);
|
|
209
|
-
const changedTags = sortedTags.slice(firstChangedTagIndex);
|
|
210
|
-
let extraTagCount = 0;
|
|
211
|
-
for (const idx of itemsToMoveRange) {
|
|
212
|
-
const changedTag = changedTags[idx];
|
|
213
|
-
utils.addTag(changedTag.tag, extraTagCount + initialOffset + idx, {
|
|
214
|
-
...changedTag.source[0].tokens,
|
|
215
|
-
end: ""
|
|
216
|
-
});
|
|
217
|
-
for (const { tokens } of changedTag.source.slice(1)) if (!tokens.end) {
|
|
218
|
-
utils.addLine(extraTagCount + initialOffset + idx + 1, {
|
|
219
|
-
...tokens,
|
|
220
|
-
end: ""
|
|
221
|
-
});
|
|
222
|
-
extraTagCount++;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
utils.reportJSDoc(`Tags are not in the prescribed order: ${tagList.join(", ") || "(alphabetical)"}`, jsdoc.tags[firstChangedTagIndex], fix, true);
|
|
227
|
-
}, {
|
|
228
|
-
iterateAllJsdocs: true,
|
|
229
|
-
meta: {
|
|
230
|
-
docs: {
|
|
231
|
-
description: "Sorts tags by a specified sequence according to tag name.",
|
|
232
|
-
url: "https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/sort-tags.md#repos-sticky-header"
|
|
233
|
-
},
|
|
234
|
-
fixable: "code",
|
|
235
|
-
schema: [{
|
|
236
|
-
additionalProperties: false,
|
|
237
|
-
properties: {
|
|
238
|
-
alphabetizeExtras: { type: "boolean" },
|
|
239
|
-
linesBetween: { type: "integer" },
|
|
240
|
-
reportIntraTagGroupSpacing: { type: "boolean" },
|
|
241
|
-
reportTagGroupSpacing: { type: "boolean" },
|
|
242
|
-
tagSequence: {
|
|
243
|
-
items: {
|
|
244
|
-
additionalProperties: false,
|
|
245
|
-
properties: { tags: {
|
|
246
|
-
items: { type: "string" },
|
|
247
|
-
type: "array"
|
|
248
|
-
} },
|
|
249
|
-
type: "object"
|
|
250
|
-
},
|
|
251
|
-
type: "array"
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
type: "object"
|
|
255
|
-
}],
|
|
256
|
-
type: "suggestion"
|
|
257
|
-
}
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
258
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _defaultTagOrder = _interopRequireDefault(require("../defaultTagOrder.cjs"));
|
|
8
|
+
var _iterateJsdoc = _interopRequireDefault(require("../iterateJsdoc.cjs"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
// eslint-disable-next-line complexity -- Temporary
|
|
11
|
+
var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
12
|
+
context,
|
|
13
|
+
jsdoc,
|
|
14
|
+
utils
|
|
15
|
+
}) => {
|
|
16
|
+
const
|
|
17
|
+
/**
|
|
18
|
+
* @type {{
|
|
19
|
+
* linesBetween: import('../iterateJsdoc.js').Integer,
|
|
20
|
+
* tagSequence: {
|
|
21
|
+
* tags: string[]
|
|
22
|
+
* }[],
|
|
23
|
+
* alphabetizeExtras: boolean,
|
|
24
|
+
* reportTagGroupSpacing: boolean,
|
|
25
|
+
* reportIntraTagGroupSpacing: boolean,
|
|
26
|
+
* }}
|
|
27
|
+
*/
|
|
28
|
+
{
|
|
29
|
+
alphabetizeExtras = false,
|
|
30
|
+
linesBetween = 1,
|
|
31
|
+
reportIntraTagGroupSpacing = true,
|
|
32
|
+
reportTagGroupSpacing = true,
|
|
33
|
+
tagSequence = _defaultTagOrder.default
|
|
34
|
+
} = context.options[0] || {};
|
|
35
|
+
const tagList = tagSequence.flatMap(obj => {
|
|
36
|
+
/* typeof obj === 'string' ? obj : */
|
|
37
|
+
return obj.tags;
|
|
38
|
+
});
|
|
39
|
+
const otherPos = tagList.indexOf('-other');
|
|
40
|
+
const endPos = otherPos > -1 ? otherPos : tagList.length;
|
|
41
|
+
let ongoingCount = 0;
|
|
42
|
+
for (const [idx, tag] of
|
|
43
|
+
/**
|
|
44
|
+
* @type {(
|
|
45
|
+
* import('@es-joy/jsdoccomment').JsdocTagWithInline & {
|
|
46
|
+
* originalIndex: import('../iterateJsdoc.js').Integer,
|
|
47
|
+
* originalLine: import('../iterateJsdoc.js').Integer,
|
|
48
|
+
* }
|
|
49
|
+
* )[]}
|
|
50
|
+
*/
|
|
51
|
+
jsdoc.tags.entries()) {
|
|
52
|
+
tag.originalIndex = idx;
|
|
53
|
+
ongoingCount += tag.source.length;
|
|
54
|
+
tag.originalLine = ongoingCount;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @type {import('../iterateJsdoc.js').Integer|undefined} */
|
|
58
|
+
let firstChangedTagLine;
|
|
59
|
+
/** @type {import('../iterateJsdoc.js').Integer|undefined} */
|
|
60
|
+
let firstChangedTagIndex;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @type {(import('comment-parser').Spec & {
|
|
64
|
+
* originalIndex: import('../iterateJsdoc.js').Integer,
|
|
65
|
+
* originalLine: import('../iterateJsdoc.js').Integer,
|
|
66
|
+
* })[]}
|
|
67
|
+
*/
|
|
68
|
+
const sortedTags = JSON.parse(JSON.stringify(jsdoc.tags));
|
|
69
|
+
sortedTags.sort(({
|
|
70
|
+
tag: tagNew
|
|
71
|
+
}, {
|
|
72
|
+
originalIndex,
|
|
73
|
+
originalLine,
|
|
74
|
+
tag: tagOld
|
|
75
|
+
}) => {
|
|
76
|
+
// Optimize: Just keep relative positions if the same tag name
|
|
77
|
+
if (tagNew === tagOld) {
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
const checkOrSetFirstChanged = () => {
|
|
81
|
+
if (!firstChangedTagLine || originalLine < firstChangedTagLine) {
|
|
82
|
+
firstChangedTagLine = originalLine;
|
|
83
|
+
firstChangedTagIndex = originalIndex;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const newPos = tagList.indexOf(tagNew);
|
|
87
|
+
const oldPos = tagList.indexOf(tagOld);
|
|
88
|
+
const preferredNewPos = newPos === -1 ? endPos : newPos;
|
|
89
|
+
const preferredOldPos = oldPos === -1 ? endPos : oldPos;
|
|
90
|
+
if (preferredNewPos < preferredOldPos) {
|
|
91
|
+
checkOrSetFirstChanged();
|
|
92
|
+
return -1;
|
|
93
|
+
}
|
|
94
|
+
if (preferredNewPos > preferredOldPos) {
|
|
95
|
+
return 1;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// preferredNewPos === preferredOldPos
|
|
99
|
+
if (!alphabetizeExtras ||
|
|
100
|
+
// Optimize: If tagNew (or tagOld which is the same) was found in the
|
|
101
|
+
// priority array, it can maintain its relative position—without need
|
|
102
|
+
// of alphabetizing (secondary sorting)
|
|
103
|
+
newPos >= 0) {
|
|
104
|
+
return 0;
|
|
105
|
+
}
|
|
106
|
+
if (tagNew < tagOld) {
|
|
107
|
+
checkOrSetFirstChanged();
|
|
108
|
+
return -1;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// tagNew > tagOld
|
|
112
|
+
return 1;
|
|
113
|
+
});
|
|
114
|
+
if (firstChangedTagLine === undefined) {
|
|
115
|
+
// Should be ordered by now
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @type {import('comment-parser').Spec[]}
|
|
119
|
+
*/
|
|
120
|
+
const lastTagsOfGroup = [];
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @type {[
|
|
124
|
+
* import('comment-parser').Spec,
|
|
125
|
+
* import('../iterateJsdoc.js').Integer
|
|
126
|
+
* ][]}
|
|
127
|
+
*/
|
|
128
|
+
const badLastTagsOfGroup = [];
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @param {import('comment-parser').Spec} tag
|
|
132
|
+
*/
|
|
133
|
+
const countTagEmptyLines = tag => {
|
|
134
|
+
return tag.source.reduce((acc, {
|
|
135
|
+
tokens: {
|
|
136
|
+
description,
|
|
137
|
+
end,
|
|
138
|
+
name,
|
|
139
|
+
tag: tg,
|
|
140
|
+
type
|
|
141
|
+
}
|
|
142
|
+
}) => {
|
|
143
|
+
const empty = !tg && !type && !name && !description;
|
|
144
|
+
// Reset the count so long as there is content
|
|
145
|
+
return empty ? acc + Number(empty && !end) : 0;
|
|
146
|
+
}, 0);
|
|
147
|
+
};
|
|
148
|
+
let idx = 0;
|
|
149
|
+
for (const {
|
|
150
|
+
tags
|
|
151
|
+
} of tagSequence) {
|
|
152
|
+
let innerIdx;
|
|
153
|
+
/** @type {import('comment-parser').Spec} */
|
|
154
|
+
let currentTag;
|
|
155
|
+
/** @type {import('comment-parser').Spec|undefined} */
|
|
156
|
+
let lastTag;
|
|
157
|
+
do {
|
|
158
|
+
currentTag = jsdoc.tags[idx];
|
|
159
|
+
if (!currentTag) {
|
|
160
|
+
idx++;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
innerIdx = tags.indexOf(currentTag.tag);
|
|
164
|
+
if (innerIdx === -1 && (
|
|
165
|
+
// eslint-disable-next-line no-loop-func -- Safe
|
|
166
|
+
!tags.includes('-other') || tagSequence.some(({
|
|
167
|
+
tags: tgs
|
|
168
|
+
}) => {
|
|
169
|
+
return tgs.includes(currentTag.tag);
|
|
170
|
+
}))) {
|
|
171
|
+
idx++;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
lastTag = currentTag;
|
|
175
|
+
idx++;
|
|
176
|
+
} while (true);
|
|
177
|
+
idx--;
|
|
178
|
+
if (lastTag) {
|
|
179
|
+
lastTagsOfGroup.push(lastTag);
|
|
180
|
+
const ct = countTagEmptyLines(lastTag);
|
|
181
|
+
if (ct !== linesBetween &&
|
|
182
|
+
// Use another rule for adding to end (should be of interest outside this rule)
|
|
183
|
+
jsdoc.tags[idx]) {
|
|
184
|
+
badLastTagsOfGroup.push([lastTag, ct]);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (reportTagGroupSpacing && badLastTagsOfGroup.length) {
|
|
189
|
+
/**
|
|
190
|
+
* @param {import('comment-parser').Spec} tg
|
|
191
|
+
* @returns {() => void}
|
|
192
|
+
*/
|
|
193
|
+
const fixer = tg => {
|
|
194
|
+
return () => {
|
|
195
|
+
// Due to https://github.com/syavorsky/comment-parser/issues/110 ,
|
|
196
|
+
// we have to modify `jsdoc.source` rather than just modify tags
|
|
197
|
+
// directly
|
|
198
|
+
for (const [currIdx, {
|
|
199
|
+
tokens
|
|
200
|
+
}] of jsdoc.source.entries()) {
|
|
201
|
+
if (tokens.tag !== '@' + tg.tag) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Cannot be `tokens.end`, as dropped off last tag, so safe to
|
|
206
|
+
// go on
|
|
207
|
+
let newIdx = currIdx;
|
|
208
|
+
const emptyLine = () => {
|
|
209
|
+
return {
|
|
210
|
+
number: 0,
|
|
211
|
+
source: '',
|
|
212
|
+
tokens: utils.seedTokens({
|
|
213
|
+
delimiter: '*',
|
|
214
|
+
start: jsdoc.source[newIdx - 1].tokens.start
|
|
215
|
+
})
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
let existingEmptyLines = 0;
|
|
219
|
+
while (true) {
|
|
220
|
+
const nextTokens = jsdoc.source[++newIdx]?.tokens;
|
|
221
|
+
|
|
222
|
+
/* c8 ignore next 3 -- Guard */
|
|
223
|
+
if (!nextTokens) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
259
226
|
|
|
260
|
-
|
|
261
|
-
|
|
227
|
+
// Should be no `nextTokens.end` to worry about since ignored
|
|
228
|
+
// if not followed by tag
|
|
229
|
+
|
|
230
|
+
if (nextTokens.tag) {
|
|
231
|
+
// Haven't made it to last tag instance yet, so keep looking
|
|
232
|
+
if (nextTokens.tag === tokens.tag) {
|
|
233
|
+
existingEmptyLines = 0;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
const lineDiff = linesBetween - existingEmptyLines;
|
|
237
|
+
if (lineDiff > 0) {
|
|
238
|
+
const lines = Array.from({
|
|
239
|
+
length: lineDiff
|
|
240
|
+
}, () => {
|
|
241
|
+
return emptyLine();
|
|
242
|
+
});
|
|
243
|
+
jsdoc.source.splice(newIdx, 0, ...lines);
|
|
244
|
+
} else {
|
|
245
|
+
// lineDiff < 0
|
|
246
|
+
jsdoc.source.splice(newIdx + lineDiff, -lineDiff);
|
|
247
|
+
}
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
const empty = !nextTokens.type && !nextTokens.name && !nextTokens.description;
|
|
251
|
+
if (empty) {
|
|
252
|
+
existingEmptyLines++;
|
|
253
|
+
} else {
|
|
254
|
+
// Has content again, so reset empty line count
|
|
255
|
+
existingEmptyLines = 0;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
for (const [srcIdx, src] of jsdoc.source.entries()) {
|
|
261
|
+
src.number = srcIdx;
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
for (const [tg] of badLastTagsOfGroup) {
|
|
266
|
+
utils.reportJSDoc('Tag groups do not have the expected whitespace', tg, fixer(tg));
|
|
267
|
+
}
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (!reportIntraTagGroupSpacing) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
for (const [tagIdx, tag] of jsdoc.tags.entries()) {
|
|
274
|
+
if (!jsdoc.tags[tagIdx + 1] || lastTagsOfGroup.includes(tag)) {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
const ct = countTagEmptyLines(tag);
|
|
278
|
+
if (ct) {
|
|
279
|
+
// eslint-disable-next-line complexity -- Temporary
|
|
280
|
+
const fixer = () => {
|
|
281
|
+
let foundFirstTag = false;
|
|
282
|
+
|
|
283
|
+
/** @type {string|undefined} */
|
|
284
|
+
let currentTag;
|
|
285
|
+
for (const [currIdx, {
|
|
286
|
+
tokens: {
|
|
287
|
+
description,
|
|
288
|
+
end,
|
|
289
|
+
name,
|
|
290
|
+
tag: tg,
|
|
291
|
+
type
|
|
292
|
+
}
|
|
293
|
+
}] of jsdoc.source.entries()) {
|
|
294
|
+
if (tg) {
|
|
295
|
+
foundFirstTag = true;
|
|
296
|
+
currentTag = tg;
|
|
297
|
+
}
|
|
298
|
+
if (!foundFirstTag) {
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (currentTag && !tg && !type && !name && !description && !end) {
|
|
302
|
+
let nextIdx = currIdx;
|
|
303
|
+
let ignore = true;
|
|
304
|
+
// Even if a tag of the same name as the last tags in a group,
|
|
305
|
+
// could still be an earlier tag in that group
|
|
306
|
+
|
|
307
|
+
// eslint-disable-next-line no-loop-func -- Safe
|
|
308
|
+
if (lastTagsOfGroup.some(lastTagOfGroup => {
|
|
309
|
+
return currentTag === '@' + lastTagOfGroup.tag;
|
|
310
|
+
})) {
|
|
311
|
+
while (true) {
|
|
312
|
+
const nextTokens = jsdoc.source[++nextIdx]?.tokens;
|
|
313
|
+
if (!nextTokens) {
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
if (!nextTokens.tag) {
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Followed by the same tag name, so not actually last in group,
|
|
321
|
+
// and of interest
|
|
322
|
+
if (nextTokens.tag === currentTag) {
|
|
323
|
+
ignore = false;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
} else {
|
|
327
|
+
while (true) {
|
|
328
|
+
const nextTokens = jsdoc.source[++nextIdx]?.tokens;
|
|
329
|
+
if (!nextTokens || nextTokens.end) {
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Not the very last tag, so don't ignore
|
|
334
|
+
if (nextTokens.tag) {
|
|
335
|
+
ignore = false;
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (!ignore) {
|
|
341
|
+
jsdoc.source.splice(currIdx, 1);
|
|
342
|
+
for (const [srcIdx, src] of jsdoc.source.entries()) {
|
|
343
|
+
src.number = srcIdx;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
utils.reportJSDoc('Intra-group tags have unexpected whitespace', tag, fixer);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
const firstLine = utils.getFirstLine();
|
|
355
|
+
const fix = () => {
|
|
356
|
+
const itemsToMoveRange = [...Array.from({
|
|
357
|
+
length: jsdoc.tags.length - (/** @type {import('../iterateJsdoc.js').Integer} */
|
|
358
|
+
firstChangedTagIndex)
|
|
359
|
+
}).keys()];
|
|
360
|
+
const unchangedPriorTagDescriptions = jsdoc.tags.slice(0, firstChangedTagIndex).reduce((ct, {
|
|
361
|
+
source
|
|
362
|
+
}) => {
|
|
363
|
+
return ct + source.length - 1;
|
|
364
|
+
}, 0);
|
|
365
|
+
|
|
366
|
+
// This offset includes not only the offset from where the first tag
|
|
367
|
+
// must begin, and the additional offset of where the first changed
|
|
368
|
+
// tag begins, but it must also account for prior descriptions
|
|
369
|
+
const initialOffset = /** @type {import('../iterateJsdoc.js').Integer} */firstLine + (/** @type {import('../iterateJsdoc.js').Integer} */firstChangedTagIndex) +
|
|
370
|
+
// May be the first tag, so don't try finding a prior one if so
|
|
371
|
+
unchangedPriorTagDescriptions;
|
|
372
|
+
|
|
373
|
+
// Use `firstChangedTagLine` for line number to begin reporting/splicing
|
|
374
|
+
for (const idx of itemsToMoveRange) {
|
|
375
|
+
utils.removeTag(idx + (/** @type {import('../iterateJsdoc.js').Integer} */
|
|
376
|
+
firstChangedTagIndex));
|
|
377
|
+
}
|
|
378
|
+
const changedTags = sortedTags.slice(firstChangedTagIndex);
|
|
379
|
+
let extraTagCount = 0;
|
|
380
|
+
for (const idx of itemsToMoveRange) {
|
|
381
|
+
const changedTag = changedTags[idx];
|
|
382
|
+
utils.addTag(changedTag.tag, extraTagCount + initialOffset + idx, {
|
|
383
|
+
...changedTag.source[0].tokens,
|
|
384
|
+
// `comment-parser` puts the `end` within the `tags` section, so
|
|
385
|
+
// avoid adding another to jsdoc.source
|
|
386
|
+
end: ''
|
|
387
|
+
});
|
|
388
|
+
for (const {
|
|
389
|
+
tokens
|
|
390
|
+
} of changedTag.source.slice(1)) {
|
|
391
|
+
if (!tokens.end) {
|
|
392
|
+
utils.addLine(extraTagCount + initialOffset + idx + 1, {
|
|
393
|
+
...tokens,
|
|
394
|
+
end: ''
|
|
395
|
+
});
|
|
396
|
+
extraTagCount++;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
utils.reportJSDoc(`Tags are not in the prescribed order: ${tagList.join(', ') || '(alphabetical)'}`, jsdoc.tags[(/** @type {import('../iterateJsdoc.js').Integer} */
|
|
402
|
+
firstChangedTagIndex)], fix, true);
|
|
403
|
+
}, {
|
|
404
|
+
iterateAllJsdocs: true,
|
|
405
|
+
meta: {
|
|
406
|
+
docs: {
|
|
407
|
+
description: 'Sorts tags by a specified sequence according to tag name.',
|
|
408
|
+
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/sort-tags.md#repos-sticky-header'
|
|
409
|
+
},
|
|
410
|
+
fixable: 'code',
|
|
411
|
+
schema: [{
|
|
412
|
+
additionalProperties: false,
|
|
413
|
+
properties: {
|
|
414
|
+
alphabetizeExtras: {
|
|
415
|
+
type: 'boolean'
|
|
416
|
+
},
|
|
417
|
+
linesBetween: {
|
|
418
|
+
type: 'integer'
|
|
419
|
+
},
|
|
420
|
+
reportIntraTagGroupSpacing: {
|
|
421
|
+
type: 'boolean'
|
|
422
|
+
},
|
|
423
|
+
reportTagGroupSpacing: {
|
|
424
|
+
type: 'boolean'
|
|
425
|
+
},
|
|
426
|
+
tagSequence: {
|
|
427
|
+
items: {
|
|
428
|
+
additionalProperties: false,
|
|
429
|
+
properties: {
|
|
430
|
+
tags: {
|
|
431
|
+
items: {
|
|
432
|
+
type: 'string'
|
|
433
|
+
},
|
|
434
|
+
type: 'array'
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
type: 'object'
|
|
438
|
+
},
|
|
439
|
+
type: 'array'
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
type: 'object'
|
|
443
|
+
}],
|
|
444
|
+
type: 'suggestion'
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
module.exports = exports.default;
|
|
262
448
|
//# sourceMappingURL=sortTags.cjs.map
|