eslint-plugin-jsdoc 56.0.0 → 56.0.2

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 (79) hide show
  1. package/dist/cjs/getJsdocProcessorPlugin.d.cts +5 -1
  2. package/dist/cjs/iterateJsdoc.d.cts +6 -2
  3. package/dist/getJsdocProcessorPlugin.cts +3 -1
  4. package/dist/iterateJsdoc.cts +9 -4
  5. package/package.json +4 -4
  6. package/src/getJsdocProcessorPlugin.cts +3 -1
  7. package/src/iterateJsdoc.cts +9 -4
  8. package/dist/cjs/WarnSettings.js +0 -30
  9. package/dist/cjs/alignTransform.js +0 -285
  10. package/dist/cjs/defaultTagOrder.js +0 -152
  11. package/dist/cjs/exportParser.js +0 -754
  12. package/dist/cjs/getDefaultTagStructureForMode.js +0 -840
  13. package/dist/cjs/getJsdocProcessorPlugin.cjs +0 -4
  14. package/dist/cjs/getJsdocProcessorPlugin.js +0 -553
  15. package/dist/cjs/index-cjs.js +0 -492
  16. package/dist/cjs/index.cjs.cjs +0 -6
  17. package/dist/cjs/iterateJsdoc.cjs +0 -38
  18. package/dist/cjs/iterateJsdoc.js +0 -1981
  19. package/dist/cjs/jsdocUtils.js +0 -1470
  20. package/dist/cjs/rules/checkAccess.js +0 -35
  21. package/dist/cjs/rules/checkAlignment.js +0 -63
  22. package/dist/cjs/rules/checkExamples.js +0 -486
  23. package/dist/cjs/rules/checkIndentation.js +0 -66
  24. package/dist/cjs/rules/checkLineAlignment.js +0 -297
  25. package/dist/cjs/rules/checkParamNames.js +0 -320
  26. package/dist/cjs/rules/checkPropertyNames.js +0 -105
  27. package/dist/cjs/rules/checkSyntax.js +0 -27
  28. package/dist/cjs/rules/checkTagNames.js +0 -252
  29. package/dist/cjs/rules/checkTemplateNames.js +0 -189
  30. package/dist/cjs/rules/checkTypes.js +0 -421
  31. package/dist/cjs/rules/checkValues.js +0 -163
  32. package/dist/cjs/rules/convertToJsdocComments.js +0 -313
  33. package/dist/cjs/rules/emptyTags.js +0 -79
  34. package/dist/cjs/rules/implementsOnClasses.js +0 -63
  35. package/dist/cjs/rules/importsAsDependencies.js +0 -105
  36. package/dist/cjs/rules/informativeDocs.js +0 -153
  37. package/dist/cjs/rules/linesBeforeBlock.js +0 -106
  38. package/dist/cjs/rules/matchDescription.js +0 -240
  39. package/dist/cjs/rules/matchName.js +0 -122
  40. package/dist/cjs/rules/multilineBlocks.js +0 -339
  41. package/dist/cjs/rules/noBadBlocks.js +0 -88
  42. package/dist/cjs/rules/noBlankBlockDescriptions.js +0 -56
  43. package/dist/cjs/rules/noBlankBlocks.js +0 -41
  44. package/dist/cjs/rules/noDefaults.js +0 -84
  45. package/dist/cjs/rules/noMissingSyntax.js +0 -164
  46. package/dist/cjs/rules/noMultiAsterisks.js +0 -83
  47. package/dist/cjs/rules/noRestrictedSyntax.js +0 -75
  48. package/dist/cjs/rules/noTypes.js +0 -88
  49. package/dist/cjs/rules/noUndefinedTypes.js +0 -451
  50. package/dist/cjs/rules/requireAsteriskPrefix.js +0 -144
  51. package/dist/cjs/rules/requireDescription.js +0 -136
  52. package/dist/cjs/rules/requireDescriptionCompleteSentence.js +0 -258
  53. package/dist/cjs/rules/requireExample.js +0 -103
  54. package/dist/cjs/rules/requireFileOverview.js +0 -117
  55. package/dist/cjs/rules/requireHyphenBeforeParamDescription.js +0 -144
  56. package/dist/cjs/rules/requireJsdoc.js +0 -629
  57. package/dist/cjs/rules/requireParam.js +0 -480
  58. package/dist/cjs/rules/requireParamDescription.js +0 -77
  59. package/dist/cjs/rules/requireParamName.js +0 -52
  60. package/dist/cjs/rules/requireParamType.js +0 -77
  61. package/dist/cjs/rules/requireProperty.js +0 -44
  62. package/dist/cjs/rules/requirePropertyDescription.js +0 -22
  63. package/dist/cjs/rules/requirePropertyName.js +0 -22
  64. package/dist/cjs/rules/requirePropertyType.js +0 -22
  65. package/dist/cjs/rules/requireReturns.js +0 -197
  66. package/dist/cjs/rules/requireReturnsCheck.js +0 -108
  67. package/dist/cjs/rules/requireReturnsDescription.js +0 -58
  68. package/dist/cjs/rules/requireReturnsType.js +0 -52
  69. package/dist/cjs/rules/requireTemplate.js +0 -173
  70. package/dist/cjs/rules/requireThrows.js +0 -101
  71. package/dist/cjs/rules/requireYields.js +0 -172
  72. package/dist/cjs/rules/requireYieldsCheck.js +0 -164
  73. package/dist/cjs/rules/sortTags.js +0 -392
  74. package/dist/cjs/rules/tagLines.js +0 -259
  75. package/dist/cjs/rules/textEscaping.js +0 -125
  76. package/dist/cjs/rules/typeFormatting.js +0 -328
  77. package/dist/cjs/rules/validTypes.js +0 -333
  78. package/dist/cjs/tagNames.js +0 -209
  79. package/dist/cjs/utils/hasReturnValue.js +0 -469
@@ -1,392 +0,0 @@
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
- });
@@ -1,259 +0,0 @@
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
- });