eslint-plugin-jsdoc 55.4.0 → 56.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.
Files changed (151) hide show
  1. package/dist/cjs/WarnSettings.d.ts +16 -0
  2. package/dist/cjs/WarnSettings.js +30 -0
  3. package/dist/cjs/alignTransform.d.ts +33 -0
  4. package/dist/cjs/alignTransform.js +285 -0
  5. package/dist/cjs/defaultTagOrder.d.ts +4 -0
  6. package/dist/cjs/defaultTagOrder.js +152 -0
  7. package/dist/cjs/exportParser.d.ts +40 -0
  8. package/dist/cjs/exportParser.js +754 -0
  9. package/dist/cjs/getDefaultTagStructureForMode.d.ts +10 -0
  10. package/dist/cjs/getDefaultTagStructureForMode.js +840 -0
  11. package/dist/cjs/getJsdocProcessorPlugin.cjs +4 -0
  12. package/dist/cjs/getJsdocProcessorPlugin.d.cts +1 -0
  13. package/dist/cjs/getJsdocProcessorPlugin.d.ts +66 -0
  14. package/dist/cjs/getJsdocProcessorPlugin.js +553 -0
  15. package/dist/cjs/index-cjs.d.ts +16 -0
  16. package/dist/cjs/index-cjs.js +492 -0
  17. package/dist/cjs/index.cjs.cjs +6 -0
  18. package/dist/cjs/index.cjs.d.cts +2 -0
  19. package/dist/cjs/iterateJsdoc.cjs +38 -0
  20. package/dist/cjs/iterateJsdoc.d.cts +2 -0
  21. package/dist/cjs/iterateJsdoc.d.ts +462 -0
  22. package/dist/cjs/iterateJsdoc.js +1981 -0
  23. package/dist/cjs/jsdocUtils.d.ts +454 -0
  24. package/dist/cjs/jsdocUtils.js +1470 -0
  25. package/dist/cjs/rules/checkAccess.d.ts +2 -0
  26. package/dist/cjs/rules/checkAccess.js +35 -0
  27. package/dist/cjs/rules/checkAlignment.d.ts +2 -0
  28. package/dist/cjs/rules/checkAlignment.js +63 -0
  29. package/dist/cjs/rules/checkExamples.d.ts +3 -0
  30. package/dist/cjs/rules/checkExamples.js +486 -0
  31. package/dist/cjs/rules/checkIndentation.d.ts +2 -0
  32. package/dist/cjs/rules/checkIndentation.js +66 -0
  33. package/dist/cjs/rules/checkLineAlignment.d.ts +9 -0
  34. package/dist/cjs/rules/checkLineAlignment.js +297 -0
  35. package/dist/cjs/rules/checkParamNames.d.ts +2 -0
  36. package/dist/cjs/rules/checkParamNames.js +320 -0
  37. package/dist/cjs/rules/checkPropertyNames.d.ts +2 -0
  38. package/dist/cjs/rules/checkPropertyNames.js +105 -0
  39. package/dist/cjs/rules/checkSyntax.d.ts +2 -0
  40. package/dist/cjs/rules/checkSyntax.js +27 -0
  41. package/dist/cjs/rules/checkTagNames.d.ts +2 -0
  42. package/dist/cjs/rules/checkTagNames.js +252 -0
  43. package/dist/cjs/rules/checkTemplateNames.d.ts +2 -0
  44. package/dist/cjs/rules/checkTemplateNames.js +189 -0
  45. package/dist/cjs/rules/checkTypes.d.ts +2 -0
  46. package/dist/cjs/rules/checkTypes.js +421 -0
  47. package/dist/cjs/rules/checkValues.d.ts +2 -0
  48. package/dist/cjs/rules/checkValues.js +163 -0
  49. package/dist/cjs/rules/convertToJsdocComments.d.ts +251 -0
  50. package/dist/cjs/rules/convertToJsdocComments.js +313 -0
  51. package/dist/cjs/rules/emptyTags.d.ts +2 -0
  52. package/dist/cjs/rules/emptyTags.js +79 -0
  53. package/dist/cjs/rules/implementsOnClasses.d.ts +2 -0
  54. package/dist/cjs/rules/implementsOnClasses.js +63 -0
  55. package/dist/cjs/rules/importsAsDependencies.d.ts +2 -0
  56. package/dist/cjs/rules/importsAsDependencies.js +105 -0
  57. package/dist/cjs/rules/informativeDocs.d.ts +2 -0
  58. package/dist/cjs/rules/informativeDocs.js +153 -0
  59. package/dist/cjs/rules/linesBeforeBlock.d.ts +2 -0
  60. package/dist/cjs/rules/linesBeforeBlock.js +106 -0
  61. package/dist/cjs/rules/matchDescription.d.ts +2 -0
  62. package/dist/cjs/rules/matchDescription.js +240 -0
  63. package/dist/cjs/rules/matchName.d.ts +2 -0
  64. package/dist/cjs/rules/matchName.js +122 -0
  65. package/dist/cjs/rules/multilineBlocks.d.ts +2 -0
  66. package/dist/cjs/rules/multilineBlocks.js +339 -0
  67. package/dist/cjs/rules/noBadBlocks.d.ts +2 -0
  68. package/dist/cjs/rules/noBadBlocks.js +88 -0
  69. package/dist/cjs/rules/noBlankBlockDescriptions.d.ts +2 -0
  70. package/dist/cjs/rules/noBlankBlockDescriptions.js +56 -0
  71. package/dist/cjs/rules/noBlankBlocks.d.ts +2 -0
  72. package/dist/cjs/rules/noBlankBlocks.js +41 -0
  73. package/dist/cjs/rules/noDefaults.d.ts +2 -0
  74. package/dist/cjs/rules/noDefaults.js +84 -0
  75. package/dist/cjs/rules/noMissingSyntax.d.ts +9 -0
  76. package/dist/cjs/rules/noMissingSyntax.js +164 -0
  77. package/dist/cjs/rules/noMultiAsterisks.d.ts +2 -0
  78. package/dist/cjs/rules/noMultiAsterisks.js +83 -0
  79. package/dist/cjs/rules/noRestrictedSyntax.d.ts +2 -0
  80. package/dist/cjs/rules/noRestrictedSyntax.js +75 -0
  81. package/dist/cjs/rules/noTypes.d.ts +2 -0
  82. package/dist/cjs/rules/noTypes.js +88 -0
  83. package/dist/cjs/rules/noUndefinedTypes.d.ts +2 -0
  84. package/dist/cjs/rules/noUndefinedTypes.js +451 -0
  85. package/dist/cjs/rules/requireAsteriskPrefix.d.ts +2 -0
  86. package/dist/cjs/rules/requireAsteriskPrefix.js +144 -0
  87. package/dist/cjs/rules/requireDescription.d.ts +2 -0
  88. package/dist/cjs/rules/requireDescription.js +136 -0
  89. package/dist/cjs/rules/requireDescriptionCompleteSentence.d.ts +2 -0
  90. package/dist/cjs/rules/requireDescriptionCompleteSentence.js +258 -0
  91. package/dist/cjs/rules/requireExample.d.ts +2 -0
  92. package/dist/cjs/rules/requireExample.js +103 -0
  93. package/dist/cjs/rules/requireFileOverview.d.ts +2 -0
  94. package/dist/cjs/rules/requireFileOverview.js +117 -0
  95. package/dist/cjs/rules/requireHyphenBeforeParamDescription.d.ts +2 -0
  96. package/dist/cjs/rules/requireHyphenBeforeParamDescription.js +144 -0
  97. package/dist/cjs/rules/requireJsdoc.d.ts +25 -0
  98. package/dist/cjs/rules/requireJsdoc.js +629 -0
  99. package/dist/cjs/rules/requireParam.d.ts +3 -0
  100. package/dist/cjs/rules/requireParam.js +480 -0
  101. package/dist/cjs/rules/requireParamDescription.d.ts +2 -0
  102. package/dist/cjs/rules/requireParamDescription.js +77 -0
  103. package/dist/cjs/rules/requireParamName.d.ts +2 -0
  104. package/dist/cjs/rules/requireParamName.js +52 -0
  105. package/dist/cjs/rules/requireParamType.d.ts +2 -0
  106. package/dist/cjs/rules/requireParamType.js +77 -0
  107. package/dist/cjs/rules/requireProperty.d.ts +2 -0
  108. package/dist/cjs/rules/requireProperty.js +44 -0
  109. package/dist/cjs/rules/requirePropertyDescription.d.ts +2 -0
  110. package/dist/cjs/rules/requirePropertyDescription.js +22 -0
  111. package/dist/cjs/rules/requirePropertyName.d.ts +2 -0
  112. package/dist/cjs/rules/requirePropertyName.js +22 -0
  113. package/dist/cjs/rules/requirePropertyType.d.ts +2 -0
  114. package/dist/cjs/rules/requirePropertyType.js +22 -0
  115. package/dist/cjs/rules/requireReturns.d.ts +2 -0
  116. package/dist/cjs/rules/requireReturns.js +197 -0
  117. package/dist/cjs/rules/requireReturnsCheck.d.ts +2 -0
  118. package/dist/cjs/rules/requireReturnsCheck.js +108 -0
  119. package/dist/cjs/rules/requireReturnsDescription.d.ts +2 -0
  120. package/dist/cjs/rules/requireReturnsDescription.js +58 -0
  121. package/dist/cjs/rules/requireReturnsType.d.ts +2 -0
  122. package/dist/cjs/rules/requireReturnsType.js +52 -0
  123. package/dist/cjs/rules/requireTemplate.d.ts +2 -0
  124. package/dist/cjs/rules/requireTemplate.js +173 -0
  125. package/dist/cjs/rules/requireThrows.d.ts +2 -0
  126. package/dist/cjs/rules/requireThrows.js +101 -0
  127. package/dist/cjs/rules/requireYields.d.ts +2 -0
  128. package/dist/cjs/rules/requireYields.js +172 -0
  129. package/dist/cjs/rules/requireYieldsCheck.d.ts +2 -0
  130. package/dist/cjs/rules/requireYieldsCheck.js +164 -0
  131. package/dist/cjs/rules/sortTags.d.ts +2 -0
  132. package/dist/cjs/rules/sortTags.js +392 -0
  133. package/dist/cjs/rules/tagLines.d.ts +2 -0
  134. package/dist/cjs/rules/tagLines.js +259 -0
  135. package/dist/cjs/rules/textEscaping.d.ts +2 -0
  136. package/dist/cjs/rules/textEscaping.js +125 -0
  137. package/dist/cjs/rules/typeFormatting.d.ts +2 -0
  138. package/dist/cjs/rules/typeFormatting.js +328 -0
  139. package/dist/cjs/rules/validTypes.d.ts +2 -0
  140. package/dist/cjs/rules/validTypes.js +333 -0
  141. package/dist/cjs/tagNames.d.ts +15 -0
  142. package/dist/cjs/tagNames.js +209 -0
  143. package/dist/cjs/utils/hasReturnValue.d.ts +19 -0
  144. package/dist/cjs/utils/hasReturnValue.js +469 -0
  145. package/dist/getJsdocProcessorPlugin.cts +3 -0
  146. package/dist/index.cjs.cts +3 -0
  147. package/dist/iterateJsdoc.cts +6 -0
  148. package/package.json +21 -10
  149. package/src/getJsdocProcessorPlugin.cts +3 -0
  150. package/src/index.cjs.cts +3 -0
  151. package/src/iterateJsdoc.cts +6 -0
@@ -0,0 +1,392 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const defaultTagOrder_js_1 = __importDefault(require("../defaultTagOrder.js"));
7
+ const iterateJsdoc_js_1 = __importDefault(require("../iterateJsdoc.js"));
8
+ // eslint-disable-next-line complexity -- Temporary
9
+ exports.default = (0, iterateJsdoc_js_1.default)(({ context, jsdoc, utils, }) => {
10
+ const
11
+ /**
12
+ * @type {{
13
+ * linesBetween: import('../iterateJsdoc.js').Integer,
14
+ * tagSequence: {
15
+ * tags: string[]
16
+ * }[],
17
+ * alphabetizeExtras: boolean,
18
+ * reportTagGroupSpacing: boolean,
19
+ * reportIntraTagGroupSpacing: boolean,
20
+ * }}
21
+ */ { alphabetizeExtras = false, linesBetween = 1, reportIntraTagGroupSpacing = true, reportTagGroupSpacing = true, tagSequence = defaultTagOrder_js_1.default, } = context.options[0] || {};
22
+ const tagList = tagSequence.flatMap((obj) => {
23
+ /* typeof obj === 'string' ? obj : */
24
+ return obj.tags;
25
+ });
26
+ const otherPos = tagList.indexOf('-other');
27
+ const endPos = otherPos > -1 ? otherPos : tagList.length;
28
+ let ongoingCount = 0;
29
+ for (const [idx, tag,] of
30
+ /**
31
+ * @type {(
32
+ * import('@es-joy/jsdoccomment').JsdocTagWithInline & {
33
+ * originalIndex: import('../iterateJsdoc.js').Integer,
34
+ * originalLine: import('../iterateJsdoc.js').Integer,
35
+ * }
36
+ * )[]}
37
+ */ (jsdoc.tags).entries()) {
38
+ tag.originalIndex = idx;
39
+ ongoingCount += tag.source.length;
40
+ tag.originalLine = ongoingCount;
41
+ }
42
+ /** @type {import('../iterateJsdoc.js').Integer|undefined} */
43
+ let firstChangedTagLine;
44
+ /** @type {import('../iterateJsdoc.js').Integer|undefined} */
45
+ let firstChangedTagIndex;
46
+ /**
47
+ * @type {(import('comment-parser').Spec & {
48
+ * originalIndex: import('../iterateJsdoc.js').Integer,
49
+ * originalLine: import('../iterateJsdoc.js').Integer,
50
+ * })[]}
51
+ */
52
+ const sortedTags = JSON.parse(JSON.stringify(jsdoc.tags));
53
+ sortedTags.sort(({ tag: tagNew, }, { originalIndex, originalLine, tag: tagOld, }) => {
54
+ // Optimize: Just keep relative positions if the same tag name
55
+ if (tagNew === tagOld) {
56
+ return 0;
57
+ }
58
+ const checkOrSetFirstChanged = () => {
59
+ if (!firstChangedTagLine || originalLine < firstChangedTagLine) {
60
+ firstChangedTagLine = originalLine;
61
+ firstChangedTagIndex = originalIndex;
62
+ }
63
+ };
64
+ const newPos = tagList.indexOf(tagNew);
65
+ const oldPos = tagList.indexOf(tagOld);
66
+ const preferredNewPos = newPos === -1 ? endPos : newPos;
67
+ const preferredOldPos = oldPos === -1 ? endPos : oldPos;
68
+ if (preferredNewPos < preferredOldPos) {
69
+ checkOrSetFirstChanged();
70
+ return -1;
71
+ }
72
+ if (preferredNewPos > preferredOldPos) {
73
+ return 1;
74
+ }
75
+ // preferredNewPos === preferredOldPos
76
+ if (!alphabetizeExtras ||
77
+ // Optimize: If tagNew (or tagOld which is the same) was found in the
78
+ // priority array, it can maintain its relative position—without need
79
+ // of alphabetizing (secondary sorting)
80
+ newPos >= 0) {
81
+ return 0;
82
+ }
83
+ if (tagNew < tagOld) {
84
+ checkOrSetFirstChanged();
85
+ return -1;
86
+ }
87
+ // tagNew > tagOld
88
+ return 1;
89
+ });
90
+ if (firstChangedTagLine === undefined) {
91
+ // Should be ordered by now
92
+ /**
93
+ * @type {import('comment-parser').Spec[]}
94
+ */
95
+ const lastTagsOfGroup = [];
96
+ /**
97
+ * @type {[
98
+ * import('comment-parser').Spec,
99
+ * import('../iterateJsdoc.js').Integer
100
+ * ][]}
101
+ */
102
+ const badLastTagsOfGroup = [];
103
+ /**
104
+ * @param {import('comment-parser').Spec} tag
105
+ */
106
+ const countTagEmptyLines = (tag) => {
107
+ return tag.source.reduce((acc, { tokens: { description, end, name, tag: tg, type, }, }) => {
108
+ const empty = !tg && !type && !name && !description;
109
+ // Reset the count so long as there is content
110
+ return empty ? acc + Number(empty && !end) : 0;
111
+ }, 0);
112
+ };
113
+ let idx = 0;
114
+ for (const { tags, } of tagSequence) {
115
+ let innerIdx;
116
+ /** @type {import('comment-parser').Spec} */
117
+ let currentTag;
118
+ /** @type {import('comment-parser').Spec|undefined} */
119
+ let lastTag;
120
+ do {
121
+ currentTag = jsdoc.tags[idx];
122
+ if (!currentTag) {
123
+ idx++;
124
+ break;
125
+ }
126
+ innerIdx = tags.indexOf(currentTag.tag);
127
+ if (innerIdx === -1 &&
128
+ // eslint-disable-next-line no-loop-func -- Safe
129
+ (!tags.includes('-other') || tagSequence.some(({ tags: tgs, }) => {
130
+ return tgs.includes(currentTag.tag);
131
+ }))) {
132
+ idx++;
133
+ break;
134
+ }
135
+ lastTag = currentTag;
136
+ idx++;
137
+ } while (true);
138
+ idx--;
139
+ if (lastTag) {
140
+ lastTagsOfGroup.push(lastTag);
141
+ const ct = countTagEmptyLines(lastTag);
142
+ if (ct !== linesBetween &&
143
+ // Use another rule for adding to end (should be of interest outside this rule)
144
+ jsdoc.tags[idx]) {
145
+ badLastTagsOfGroup.push([
146
+ lastTag, ct,
147
+ ]);
148
+ }
149
+ }
150
+ }
151
+ if (reportTagGroupSpacing && badLastTagsOfGroup.length) {
152
+ /**
153
+ * @param {import('comment-parser').Spec} tg
154
+ * @returns {() => void}
155
+ */
156
+ const fixer = (tg) => {
157
+ return () => {
158
+ // Due to https://github.com/syavorsky/comment-parser/issues/110 ,
159
+ // we have to modify `jsdoc.source` rather than just modify tags
160
+ // directly
161
+ for (const [currIdx, { tokens, },] of jsdoc.source.entries()) {
162
+ if (tokens.tag !== '@' + tg.tag) {
163
+ continue;
164
+ }
165
+ // Cannot be `tokens.end`, as dropped off last tag, so safe to
166
+ // go on
167
+ let newIdx = currIdx;
168
+ const emptyLine = () => {
169
+ return {
170
+ number: 0,
171
+ source: '',
172
+ tokens: utils.seedTokens({
173
+ delimiter: '*',
174
+ start: jsdoc.source[newIdx - 1].tokens.start,
175
+ }),
176
+ };
177
+ };
178
+ let existingEmptyLines = 0;
179
+ while (true) {
180
+ const nextTokens = jsdoc.source[++newIdx]?.tokens;
181
+ /* c8 ignore next 3 -- Guard */
182
+ if (!nextTokens) {
183
+ return;
184
+ }
185
+ // Should be no `nextTokens.end` to worry about since ignored
186
+ // if not followed by tag
187
+ if (nextTokens.tag) {
188
+ // Haven't made it to last tag instance yet, so keep looking
189
+ if (nextTokens.tag === tokens.tag) {
190
+ existingEmptyLines = 0;
191
+ continue;
192
+ }
193
+ const lineDiff = linesBetween - existingEmptyLines;
194
+ if (lineDiff > 0) {
195
+ const lines = Array.from({
196
+ length: lineDiff,
197
+ }, () => {
198
+ return emptyLine();
199
+ });
200
+ jsdoc.source.splice(newIdx, 0, ...lines);
201
+ }
202
+ else {
203
+ // lineDiff < 0
204
+ jsdoc.source.splice(newIdx + lineDiff, -lineDiff);
205
+ }
206
+ break;
207
+ }
208
+ const empty = !nextTokens.type && !nextTokens.name &&
209
+ !nextTokens.description;
210
+ if (empty) {
211
+ existingEmptyLines++;
212
+ }
213
+ else {
214
+ // Has content again, so reset empty line count
215
+ existingEmptyLines = 0;
216
+ }
217
+ }
218
+ break;
219
+ }
220
+ for (const [srcIdx, src,] of jsdoc.source.entries()) {
221
+ src.number = srcIdx;
222
+ }
223
+ };
224
+ };
225
+ for (const [tg,] of badLastTagsOfGroup) {
226
+ utils.reportJSDoc('Tag groups do not have the expected whitespace', tg, fixer(tg));
227
+ }
228
+ return;
229
+ }
230
+ if (!reportIntraTagGroupSpacing) {
231
+ return;
232
+ }
233
+ for (const [tagIdx, tag,] of jsdoc.tags.entries()) {
234
+ if (!jsdoc.tags[tagIdx + 1] || lastTagsOfGroup.includes(tag)) {
235
+ continue;
236
+ }
237
+ const ct = countTagEmptyLines(tag);
238
+ if (ct) {
239
+ // eslint-disable-next-line complexity -- Temporary
240
+ const fixer = () => {
241
+ let foundFirstTag = false;
242
+ /** @type {string|undefined} */
243
+ let currentTag;
244
+ for (const [currIdx, { tokens: { description, end, name, tag: tg, type, }, },] of jsdoc.source.entries()) {
245
+ if (tg) {
246
+ foundFirstTag = true;
247
+ currentTag = tg;
248
+ }
249
+ if (!foundFirstTag) {
250
+ continue;
251
+ }
252
+ if (currentTag && !tg && !type && !name && !description && !end) {
253
+ let nextIdx = currIdx;
254
+ let ignore = true;
255
+ // Even if a tag of the same name as the last tags in a group,
256
+ // could still be an earlier tag in that group
257
+ // eslint-disable-next-line no-loop-func -- Safe
258
+ if (lastTagsOfGroup.some((lastTagOfGroup) => {
259
+ return currentTag === '@' + lastTagOfGroup.tag;
260
+ })) {
261
+ while (true) {
262
+ const nextTokens = jsdoc.source[++nextIdx]?.tokens;
263
+ if (!nextTokens) {
264
+ break;
265
+ }
266
+ if (!nextTokens.tag) {
267
+ continue;
268
+ }
269
+ // Followed by the same tag name, so not actually last in group,
270
+ // and of interest
271
+ if (nextTokens.tag === currentTag) {
272
+ ignore = false;
273
+ }
274
+ }
275
+ }
276
+ else {
277
+ while (true) {
278
+ const nextTokens = jsdoc.source[++nextIdx]?.tokens;
279
+ if (!nextTokens || nextTokens.end) {
280
+ break;
281
+ }
282
+ // Not the very last tag, so don't ignore
283
+ if (nextTokens.tag) {
284
+ ignore = false;
285
+ break;
286
+ }
287
+ }
288
+ }
289
+ if (!ignore) {
290
+ jsdoc.source.splice(currIdx, 1);
291
+ for (const [srcIdx, src,] of jsdoc.source.entries()) {
292
+ src.number = srcIdx;
293
+ }
294
+ }
295
+ }
296
+ }
297
+ };
298
+ utils.reportJSDoc('Intra-group tags have unexpected whitespace', tag, fixer);
299
+ }
300
+ }
301
+ return;
302
+ }
303
+ const firstLine = utils.getFirstLine();
304
+ const fix = () => {
305
+ const itemsToMoveRange = [
306
+ ...Array.from({
307
+ length: jsdoc.tags.length -
308
+ /** @type {import('../iterateJsdoc.js').Integer} */ (firstChangedTagIndex),
309
+ }).keys(),
310
+ ];
311
+ const unchangedPriorTagDescriptions = jsdoc.tags.slice(0, firstChangedTagIndex).reduce((ct, { source, }) => {
312
+ return ct + source.length - 1;
313
+ }, 0);
314
+ // This offset includes not only the offset from where the first tag
315
+ // must begin, and the additional offset of where the first changed
316
+ // tag begins, but it must also account for prior descriptions
317
+ const initialOffset = /** @type {import('../iterateJsdoc.js').Integer} */ (firstLine) + /** @type {import('../iterateJsdoc.js').Integer} */ (firstChangedTagIndex) +
318
+ // May be the first tag, so don't try finding a prior one if so
319
+ unchangedPriorTagDescriptions;
320
+ // Use `firstChangedTagLine` for line number to begin reporting/splicing
321
+ for (const idx of itemsToMoveRange) {
322
+ utils.removeTag(idx +
323
+ /** @type {import('../iterateJsdoc.js').Integer} */ (firstChangedTagIndex));
324
+ }
325
+ const changedTags = sortedTags.slice(firstChangedTagIndex);
326
+ let extraTagCount = 0;
327
+ for (const idx of itemsToMoveRange) {
328
+ const changedTag = changedTags[idx];
329
+ utils.addTag(changedTag.tag, extraTagCount + initialOffset + idx, {
330
+ ...changedTag.source[0].tokens,
331
+ // `comment-parser` puts the `end` within the `tags` section, so
332
+ // avoid adding another to jsdoc.source
333
+ end: '',
334
+ });
335
+ for (const { tokens, } of changedTag.source.slice(1)) {
336
+ if (!tokens.end) {
337
+ utils.addLine(extraTagCount + initialOffset + idx + 1, {
338
+ ...tokens,
339
+ end: '',
340
+ });
341
+ extraTagCount++;
342
+ }
343
+ }
344
+ }
345
+ };
346
+ utils.reportJSDoc(`Tags are not in the prescribed order: ${tagList.join(', ') || '(alphabetical)'}`, jsdoc.tags[ /** @type {import('../iterateJsdoc.js').Integer} */(firstChangedTagIndex)], fix, true);
347
+ }, {
348
+ iterateAllJsdocs: true,
349
+ meta: {
350
+ docs: {
351
+ description: 'Sorts tags by a specified sequence according to tag name.',
352
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/sort-tags.md#repos-sticky-header',
353
+ },
354
+ fixable: 'code',
355
+ schema: [
356
+ {
357
+ additionalProperties: false,
358
+ properties: {
359
+ alphabetizeExtras: {
360
+ type: 'boolean',
361
+ },
362
+ linesBetween: {
363
+ type: 'integer',
364
+ },
365
+ reportIntraTagGroupSpacing: {
366
+ type: 'boolean',
367
+ },
368
+ reportTagGroupSpacing: {
369
+ type: 'boolean',
370
+ },
371
+ tagSequence: {
372
+ items: {
373
+ additionalProperties: false,
374
+ properties: {
375
+ tags: {
376
+ items: {
377
+ type: 'string',
378
+ },
379
+ type: 'array',
380
+ },
381
+ },
382
+ type: 'object',
383
+ },
384
+ type: 'array',
385
+ },
386
+ },
387
+ type: 'object',
388
+ },
389
+ ],
390
+ type: 'suggestion',
391
+ },
392
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("eslint").Rule.RuleModule;
2
+ export default _default;
@@ -0,0 +1,259 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const iterateJsdoc_js_1 = __importDefault(require("../iterateJsdoc.js"));
7
+ exports.default = (0, iterateJsdoc_js_1.default)(({ context, jsdoc, utils, }) => {
8
+ const [alwaysNever = 'never', { applyToEndTag = true, count = 1, endLines = 0, startLines = 0, tags = {}, } = {},] = context.options;
9
+ // eslint-disable-next-line complexity -- Temporary
10
+ jsdoc.tags.some((tg, tagIdx) => {
11
+ let lastTag;
12
+ /**
13
+ * @type {null|import('../iterateJsdoc.js').Integer}
14
+ */
15
+ let lastEmpty = null;
16
+ /**
17
+ * @type {null|import('../iterateJsdoc.js').Integer}
18
+ */
19
+ let reportIndex = null;
20
+ let emptyLinesCount = 0;
21
+ for (const [idx, { tokens: { description, end, name, tag, type, }, },] of tg.source.entries()) {
22
+ // May be text after a line break within a tag description
23
+ if (description) {
24
+ reportIndex = null;
25
+ }
26
+ if (lastTag && [
27
+ 'always', 'any',
28
+ ].includes(tags[lastTag.slice(1)]?.lines)) {
29
+ continue;
30
+ }
31
+ const empty = !tag && !name && !type && !description;
32
+ if (empty && !end &&
33
+ (alwaysNever === 'never' ||
34
+ lastTag && tags[lastTag.slice(1)]?.lines === 'never')) {
35
+ reportIndex = idx;
36
+ continue;
37
+ }
38
+ if (!end) {
39
+ if (empty) {
40
+ emptyLinesCount++;
41
+ }
42
+ else {
43
+ emptyLinesCount = 0;
44
+ }
45
+ lastEmpty = empty ? idx : null;
46
+ }
47
+ lastTag = tag;
48
+ }
49
+ if (typeof endLines === 'number' &&
50
+ lastEmpty !== null && tagIdx === jsdoc.tags.length - 1) {
51
+ const lineDiff = endLines - emptyLinesCount;
52
+ if (lineDiff < 0) {
53
+ const fixer = () => {
54
+ utils.removeTag(tagIdx, {
55
+ tagSourceOffset: /** @type {import('../iterateJsdoc.js').Integer} */ (lastEmpty) + lineDiff + 1,
56
+ });
57
+ };
58
+ utils.reportJSDoc(`Expected ${endLines} trailing lines`, {
59
+ line: tg.source[lastEmpty].number + lineDiff + 1,
60
+ }, fixer);
61
+ }
62
+ else if (lineDiff > 0) {
63
+ const fixer = () => {
64
+ utils.addLines(tagIdx,
65
+ /** @type {import('../iterateJsdoc.js').Integer} */ (lastEmpty), endLines - emptyLinesCount);
66
+ };
67
+ utils.reportJSDoc(`Expected ${endLines} trailing lines`, {
68
+ line: tg.source[lastEmpty].number,
69
+ }, fixer);
70
+ }
71
+ return true;
72
+ }
73
+ if (reportIndex !== null) {
74
+ const fixer = () => {
75
+ utils.removeTag(tagIdx, {
76
+ tagSourceOffset: /** @type {import('../iterateJsdoc.js').Integer} */ (reportIndex),
77
+ });
78
+ };
79
+ utils.reportJSDoc('Expected no lines between tags', {
80
+ line: tg.source[0].number + 1,
81
+ }, fixer);
82
+ return true;
83
+ }
84
+ return false;
85
+ });
86
+ (applyToEndTag ? jsdoc.tags : jsdoc.tags.slice(0, -1)).some((tg, tagIdx) => {
87
+ /**
88
+ * @type {{
89
+ * idx: import('../iterateJsdoc.js').Integer,
90
+ * number: import('../iterateJsdoc.js').Integer
91
+ * }[]}
92
+ */
93
+ const lines = [];
94
+ let currentTag;
95
+ let tagSourceIdx = 0;
96
+ for (const [idx, { number, tokens: { description, end, name, tag, type, }, },] of tg.source.entries()) {
97
+ if (description) {
98
+ lines.splice(0);
99
+ tagSourceIdx = idx;
100
+ }
101
+ if (tag) {
102
+ currentTag = tag;
103
+ }
104
+ if (!tag && !name && !type && !description && !end) {
105
+ lines.push({
106
+ idx,
107
+ number,
108
+ });
109
+ }
110
+ }
111
+ const currentTg = currentTag && tags[currentTag.slice(1)];
112
+ const tagCount = currentTg?.count;
113
+ const defaultAlways = alwaysNever === 'always' && currentTg?.lines !== 'never' &&
114
+ currentTg?.lines !== 'any' && lines.length < count;
115
+ let overrideAlways;
116
+ let fixCount = count;
117
+ if (!defaultAlways) {
118
+ fixCount = typeof tagCount === 'number' ? tagCount : count;
119
+ overrideAlways = currentTg?.lines === 'always' &&
120
+ lines.length < fixCount;
121
+ }
122
+ if (defaultAlways || overrideAlways) {
123
+ const fixer = () => {
124
+ utils.addLines(tagIdx, lines[lines.length - 1]?.idx || tagSourceIdx + 1, fixCount - lines.length);
125
+ };
126
+ const line = lines[lines.length - 1]?.number || tg.source[tagSourceIdx].number;
127
+ utils.reportJSDoc(`Expected ${fixCount} line${fixCount === 1 ? '' : 's'} between tags but found ${lines.length}`, {
128
+ line,
129
+ }, fixer);
130
+ return true;
131
+ }
132
+ return false;
133
+ });
134
+ if (typeof startLines === 'number') {
135
+ if (!jsdoc.tags.length) {
136
+ return;
137
+ }
138
+ const { description, lastDescriptionLine, } = utils.getDescription();
139
+ if (!(/\S/v).test(description)) {
140
+ return;
141
+ }
142
+ const trailingLines = description.match(/\n+$/v)?.[0]?.length;
143
+ const trailingDiff = (trailingLines ?? 0) - startLines;
144
+ if (trailingDiff > 0) {
145
+ utils.reportJSDoc(`Expected only ${startLines} line after block description`, {
146
+ line: lastDescriptionLine - trailingDiff,
147
+ }, () => {
148
+ utils.setBlockDescription((info, seedTokens, descLines) => {
149
+ return descLines.slice(0, -trailingDiff).map((desc) => {
150
+ return {
151
+ number: 0,
152
+ source: '',
153
+ tokens: seedTokens({
154
+ ...info,
155
+ description: desc,
156
+ postDelimiter: desc.trim() ? info.postDelimiter : '',
157
+ }),
158
+ };
159
+ });
160
+ });
161
+ });
162
+ }
163
+ else if (trailingDiff < 0) {
164
+ utils.reportJSDoc(`Expected ${startLines} lines after block description`, {
165
+ line: lastDescriptionLine,
166
+ }, () => {
167
+ utils.setBlockDescription((info, seedTokens, descLines) => {
168
+ return [
169
+ ...descLines,
170
+ ...Array.from({
171
+ length: -trailingDiff,
172
+ }, () => {
173
+ return '';
174
+ }),
175
+ ].map((desc) => {
176
+ return {
177
+ number: 0,
178
+ source: '',
179
+ tokens: seedTokens({
180
+ ...info,
181
+ description: desc,
182
+ postDelimiter: desc.trim() ? info.postDelimiter : '',
183
+ }),
184
+ };
185
+ });
186
+ });
187
+ });
188
+ }
189
+ }
190
+ }, {
191
+ iterateAllJsdocs: true,
192
+ meta: {
193
+ docs: {
194
+ description: 'Enforces lines (or no lines) between tags.',
195
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/tag-lines.md#repos-sticky-header',
196
+ },
197
+ fixable: 'code',
198
+ schema: [
199
+ {
200
+ enum: [
201
+ 'always', 'any', 'never',
202
+ ],
203
+ type: 'string',
204
+ },
205
+ {
206
+ additionalProperties: false,
207
+ properties: {
208
+ applyToEndTag: {
209
+ type: 'boolean',
210
+ },
211
+ count: {
212
+ type: 'integer',
213
+ },
214
+ endLines: {
215
+ anyOf: [
216
+ {
217
+ type: 'integer',
218
+ },
219
+ {
220
+ type: 'null',
221
+ },
222
+ ],
223
+ },
224
+ startLines: {
225
+ anyOf: [
226
+ {
227
+ type: 'integer',
228
+ },
229
+ {
230
+ type: 'null',
231
+ },
232
+ ],
233
+ },
234
+ tags: {
235
+ patternProperties: {
236
+ '.*': {
237
+ additionalProperties: false,
238
+ properties: {
239
+ count: {
240
+ type: 'integer',
241
+ },
242
+ lines: {
243
+ enum: [
244
+ 'always', 'never', 'any',
245
+ ],
246
+ type: 'string',
247
+ },
248
+ },
249
+ },
250
+ },
251
+ type: 'object',
252
+ },
253
+ },
254
+ type: 'object',
255
+ },
256
+ ],
257
+ type: 'suggestion',
258
+ },
259
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("eslint").Rule.RuleModule;
2
+ export default _default;