eslint-plugin-jsdoc 48.0.0 → 48.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 (64) hide show
  1. package/package.json +2 -2
  2. package/src/WarnSettings.js +34 -0
  3. package/src/alignTransform.js +356 -0
  4. package/src/defaultTagOrder.js +168 -0
  5. package/src/exportParser.js +957 -0
  6. package/src/getDefaultTagStructureForMode.js +969 -0
  7. package/src/index.js +266 -0
  8. package/src/iterateJsdoc.js +2555 -0
  9. package/src/jsdocUtils.js +1693 -0
  10. package/src/rules/checkAccess.js +45 -0
  11. package/src/rules/checkAlignment.js +63 -0
  12. package/src/rules/checkExamples.js +594 -0
  13. package/src/rules/checkIndentation.js +75 -0
  14. package/src/rules/checkLineAlignment.js +364 -0
  15. package/src/rules/checkParamNames.js +404 -0
  16. package/src/rules/checkPropertyNames.js +152 -0
  17. package/src/rules/checkSyntax.js +30 -0
  18. package/src/rules/checkTagNames.js +314 -0
  19. package/src/rules/checkTypes.js +535 -0
  20. package/src/rules/checkValues.js +220 -0
  21. package/src/rules/emptyTags.js +88 -0
  22. package/src/rules/implementsOnClasses.js +64 -0
  23. package/src/rules/importsAsDependencies.js +131 -0
  24. package/src/rules/informativeDocs.js +182 -0
  25. package/src/rules/matchDescription.js +286 -0
  26. package/src/rules/matchName.js +147 -0
  27. package/src/rules/multilineBlocks.js +333 -0
  28. package/src/rules/noBadBlocks.js +109 -0
  29. package/src/rules/noBlankBlockDescriptions.js +69 -0
  30. package/src/rules/noBlankBlocks.js +53 -0
  31. package/src/rules/noDefaults.js +85 -0
  32. package/src/rules/noMissingSyntax.js +195 -0
  33. package/src/rules/noMultiAsterisks.js +134 -0
  34. package/src/rules/noRestrictedSyntax.js +91 -0
  35. package/src/rules/noTypes.js +73 -0
  36. package/src/rules/noUndefinedTypes.js +328 -0
  37. package/src/rules/requireAsteriskPrefix.js +189 -0
  38. package/src/rules/requireDescription.js +161 -0
  39. package/src/rules/requireDescriptionCompleteSentence.js +333 -0
  40. package/src/rules/requireExample.js +118 -0
  41. package/src/rules/requireFileOverview.js +154 -0
  42. package/src/rules/requireHyphenBeforeParamDescription.js +178 -0
  43. package/src/rules/requireJsdoc.js +629 -0
  44. package/src/rules/requireParam.js +592 -0
  45. package/src/rules/requireParamDescription.js +89 -0
  46. package/src/rules/requireParamName.js +55 -0
  47. package/src/rules/requireParamType.js +89 -0
  48. package/src/rules/requireProperty.js +48 -0
  49. package/src/rules/requirePropertyDescription.js +25 -0
  50. package/src/rules/requirePropertyName.js +25 -0
  51. package/src/rules/requirePropertyType.js +25 -0
  52. package/src/rules/requireReturns.js +238 -0
  53. package/src/rules/requireReturnsCheck.js +141 -0
  54. package/src/rules/requireReturnsDescription.js +59 -0
  55. package/src/rules/requireReturnsType.js +51 -0
  56. package/src/rules/requireThrows.js +111 -0
  57. package/src/rules/requireYields.js +216 -0
  58. package/src/rules/requireYieldsCheck.js +208 -0
  59. package/src/rules/sortTags.js +557 -0
  60. package/src/rules/tagLines.js +359 -0
  61. package/src/rules/textEscaping.js +146 -0
  62. package/src/rules/validTypes.js +368 -0
  63. package/src/tagNames.js +234 -0
  64. package/src/utils/hasReturnValue.js +549 -0
@@ -0,0 +1,333 @@
1
+ import iterateJsdoc from '../iterateJsdoc.js';
2
+
3
+ export default iterateJsdoc(({
4
+ context,
5
+ jsdoc,
6
+ utils,
7
+ }) => {
8
+ const {
9
+ allowMultipleTags = true,
10
+ noFinalLineText = true,
11
+ noZeroLineText = true,
12
+ noSingleLineBlocks = false,
13
+ singleLineTags = [
14
+ 'lends', 'type',
15
+ ],
16
+ noMultilineBlocks = false,
17
+ minimumLengthForMultiline = Number.POSITIVE_INFINITY,
18
+ multilineTags = [
19
+ '*',
20
+ ],
21
+ } = context.options[0] || {};
22
+
23
+ const {
24
+ source: [
25
+ {
26
+ tokens,
27
+ },
28
+ ],
29
+ } = jsdoc;
30
+ const {
31
+ description,
32
+ tag,
33
+ } = tokens;
34
+ const sourceLength = jsdoc.source.length;
35
+
36
+ /**
37
+ * @param {string} tagName
38
+ * @returns {boolean}
39
+ */
40
+ const isInvalidSingleLine = (tagName) => {
41
+ return noSingleLineBlocks &&
42
+ (!tagName ||
43
+ !singleLineTags.includes(tagName) && !singleLineTags.includes('*'));
44
+ };
45
+
46
+ if (sourceLength === 1) {
47
+ if (!isInvalidSingleLine(tag.slice(1))) {
48
+ return;
49
+ }
50
+
51
+ const fixer = () => {
52
+ utils.makeMultiline();
53
+ };
54
+
55
+ utils.reportJSDoc(
56
+ 'Single line blocks are not permitted by your configuration.',
57
+ null,
58
+ fixer,
59
+ true,
60
+ );
61
+
62
+ return;
63
+ }
64
+
65
+ const lineChecks = () => {
66
+ if (
67
+ noZeroLineText &&
68
+ (tag || description)
69
+ ) {
70
+ const fixer = () => {
71
+ const line = {
72
+ ...tokens,
73
+ };
74
+ utils.emptyTokens(tokens);
75
+ const {
76
+ tokens: {
77
+ delimiter,
78
+ start,
79
+ },
80
+ } = jsdoc.source[1];
81
+ utils.addLine(1, {
82
+ ...line,
83
+ delimiter,
84
+ start,
85
+ });
86
+ };
87
+
88
+ utils.reportJSDoc(
89
+ 'Should have no text on the "0th" line (after the `/**`).',
90
+ null,
91
+ fixer,
92
+ );
93
+
94
+ return;
95
+ }
96
+
97
+ const finalLine = jsdoc.source[jsdoc.source.length - 1];
98
+ const finalLineTokens = finalLine.tokens;
99
+ if (
100
+ noFinalLineText &&
101
+ finalLineTokens.description.trim()
102
+ ) {
103
+ const fixer = () => {
104
+ const line = {
105
+ ...finalLineTokens,
106
+ };
107
+ line.description = line.description.trimEnd();
108
+
109
+ const {
110
+ delimiter,
111
+ } = line;
112
+
113
+ for (const prop of [
114
+ 'delimiter',
115
+ 'postDelimiter',
116
+ 'tag',
117
+ 'type',
118
+ 'lineEnd',
119
+ 'postType',
120
+ 'postTag',
121
+ 'name',
122
+ 'postName',
123
+ 'description',
124
+ ]) {
125
+ finalLineTokens[
126
+ /**
127
+ * @type {"delimiter"|"postDelimiter"|"tag"|"type"|
128
+ * "lineEnd"|"postType"|"postTag"|"name"|
129
+ * "postName"|"description"}
130
+ */ (
131
+ prop
132
+ )
133
+ ] = '';
134
+ }
135
+
136
+ utils.addLine(jsdoc.source.length - 1, {
137
+ ...line,
138
+ delimiter,
139
+ end: '',
140
+ });
141
+ };
142
+
143
+ utils.reportJSDoc(
144
+ 'Should have no text on the final line (before the `*/`).',
145
+ null,
146
+ fixer,
147
+ );
148
+ }
149
+ };
150
+
151
+ if (noMultilineBlocks) {
152
+ if (
153
+ jsdoc.tags.length &&
154
+ (multilineTags.includes('*') || utils.hasATag(multilineTags))
155
+ ) {
156
+ lineChecks();
157
+
158
+ return;
159
+ }
160
+
161
+ if (jsdoc.description.length >= minimumLengthForMultiline) {
162
+ lineChecks();
163
+
164
+ return;
165
+ }
166
+
167
+ if (
168
+ noSingleLineBlocks &&
169
+ (!jsdoc.tags.length ||
170
+ !utils.filterTags(({
171
+ tag: tg,
172
+ }) => {
173
+ return !isInvalidSingleLine(tg);
174
+ }).length)
175
+ ) {
176
+ utils.reportJSDoc(
177
+ 'Multiline jsdoc blocks are prohibited by ' +
178
+ 'your configuration but fixing would result in a single ' +
179
+ 'line block which you have prohibited with `noSingleLineBlocks`.',
180
+ );
181
+
182
+ return;
183
+ }
184
+
185
+ if (jsdoc.tags.length > 1) {
186
+ if (!allowMultipleTags) {
187
+ utils.reportJSDoc(
188
+ 'Multiline jsdoc blocks are prohibited by ' +
189
+ 'your configuration but the block has multiple tags.',
190
+ );
191
+
192
+ return;
193
+ }
194
+ } else if (jsdoc.tags.length === 1 && jsdoc.description.trim()) {
195
+ if (!allowMultipleTags) {
196
+ utils.reportJSDoc(
197
+ 'Multiline jsdoc blocks are prohibited by ' +
198
+ 'your configuration but the block has a description with a tag.',
199
+ );
200
+
201
+ return;
202
+ }
203
+ } else {
204
+ const fixer = () => {
205
+ jsdoc.source = [
206
+ {
207
+ number: 1,
208
+ source: '',
209
+ tokens: jsdoc.source.reduce((obj, {
210
+ tokens: {
211
+ description: desc,
212
+ tag: tg,
213
+ type: typ,
214
+ name: nme,
215
+ lineEnd,
216
+ postType,
217
+ postName,
218
+ postTag,
219
+ },
220
+ }) => {
221
+ if (typ) {
222
+ obj.type = typ;
223
+ }
224
+
225
+ if (tg && typ && nme) {
226
+ obj.postType = postType;
227
+ }
228
+
229
+ if (nme) {
230
+ obj.name += nme;
231
+ }
232
+
233
+ if (nme && desc) {
234
+ obj.postName = postName;
235
+ }
236
+
237
+ obj.description += desc;
238
+
239
+ const nameOrDescription = obj.description || obj.name;
240
+ if (
241
+ nameOrDescription && nameOrDescription.slice(-1) !== ' '
242
+ ) {
243
+ obj.description += ' ';
244
+ }
245
+
246
+ obj.lineEnd = lineEnd;
247
+
248
+ // Already filtered for multiple tags
249
+ obj.tag += tg;
250
+ if (tg) {
251
+ obj.postTag = postTag || ' ';
252
+ }
253
+
254
+ return obj;
255
+ }, utils.seedTokens({
256
+ delimiter: '/**',
257
+ end: '*/',
258
+ postDelimiter: ' ',
259
+ })),
260
+ },
261
+ ];
262
+ };
263
+
264
+ utils.reportJSDoc(
265
+ 'Multiline jsdoc blocks are prohibited by ' +
266
+ 'your configuration.',
267
+ null,
268
+ fixer,
269
+ );
270
+
271
+ return;
272
+ }
273
+ }
274
+
275
+ lineChecks();
276
+ }, {
277
+ iterateAllJsdocs: true,
278
+ meta: {
279
+ docs: {
280
+ description: 'Controls how and whether jsdoc blocks can be expressed as single or multiple line blocks.',
281
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/multiline-blocks.md#repos-sticky-header',
282
+ },
283
+ fixable: 'code',
284
+ schema: [
285
+ {
286
+ additionalProperties: false,
287
+ properties: {
288
+ allowMultipleTags: {
289
+ type: 'boolean',
290
+ },
291
+ minimumLengthForMultiline: {
292
+ type: 'integer',
293
+ },
294
+ multilineTags: {
295
+ anyOf: [
296
+ {
297
+ enum: [
298
+ '*',
299
+ ],
300
+ type: 'string',
301
+ }, {
302
+ items: {
303
+ type: 'string',
304
+ },
305
+ type: 'array',
306
+ },
307
+ ],
308
+ },
309
+ noFinalLineText: {
310
+ type: 'boolean',
311
+ },
312
+ noMultilineBlocks: {
313
+ type: 'boolean',
314
+ },
315
+ noSingleLineBlocks: {
316
+ type: 'boolean',
317
+ },
318
+ noZeroLineText: {
319
+ type: 'boolean',
320
+ },
321
+ singleLineTags: {
322
+ items: {
323
+ type: 'string',
324
+ },
325
+ type: 'array',
326
+ },
327
+ },
328
+ type: 'object',
329
+ },
330
+ ],
331
+ type: 'suggestion',
332
+ },
333
+ });
@@ -0,0 +1,109 @@
1
+ import iterateJsdoc from '../iterateJsdoc.js';
2
+ import {
3
+ parse as commentParser,
4
+ } from 'comment-parser';
5
+
6
+ // Neither a single nor 3+ asterisks are valid jsdoc per
7
+ // https://jsdoc.app/about-getting-started.html#adding-documentation-comments-to-your-code
8
+ const commentRegexp = /^\/\*(?!\*)/u;
9
+ const extraAsteriskCommentRegexp = /^\/\*{3,}/u;
10
+
11
+ export default iterateJsdoc(({
12
+ context,
13
+ sourceCode,
14
+ allComments,
15
+ makeReport,
16
+ }) => {
17
+ const [
18
+ {
19
+ ignore = [
20
+ 'ts-check',
21
+ 'ts-expect-error',
22
+ 'ts-ignore',
23
+ 'ts-nocheck',
24
+ ],
25
+ preventAllMultiAsteriskBlocks = false,
26
+ } = {},
27
+ ] = context.options;
28
+
29
+ let extraAsterisks = false;
30
+ const nonJsdocNodes = /** @type {import('estree').Node[]} */ (
31
+ allComments
32
+ ).filter((comment) => {
33
+ const commentText = sourceCode.getText(comment);
34
+ let sliceIndex = 2;
35
+ if (!commentRegexp.test(commentText)) {
36
+ const multiline = extraAsteriskCommentRegexp.exec(commentText)?.[0];
37
+ if (!multiline) {
38
+ return false;
39
+ }
40
+
41
+ sliceIndex = multiline.length;
42
+ extraAsterisks = true;
43
+ if (preventAllMultiAsteriskBlocks) {
44
+ return true;
45
+ }
46
+ }
47
+
48
+ const tags = (commentParser(
49
+ `${commentText.slice(0, 2)}*${commentText.slice(sliceIndex)}`,
50
+ )[0] || {}).tags ?? [];
51
+
52
+ return tags.length && !tags.some(({
53
+ tag,
54
+ }) => {
55
+ return ignore.includes(tag);
56
+ });
57
+ });
58
+
59
+ if (!nonJsdocNodes.length) {
60
+ return;
61
+ }
62
+
63
+ for (const node of nonJsdocNodes) {
64
+ const report = /** @type {import('../iterateJsdoc.js').MakeReport} */ (
65
+ makeReport
66
+ )(context, node);
67
+
68
+ // eslint-disable-next-line no-loop-func
69
+ const fix = /** @type {import('eslint').Rule.ReportFixer} */ (fixer) => {
70
+ const text = sourceCode.getText(node);
71
+
72
+ return fixer.replaceText(
73
+ node,
74
+ extraAsterisks ?
75
+ text.replace(extraAsteriskCommentRegexp, '/**') :
76
+ text.replace('/*', '/**'),
77
+ );
78
+ };
79
+
80
+ report('Expected JSDoc-like comment to begin with two asterisks.', fix);
81
+ }
82
+ }, {
83
+ checkFile: true,
84
+ meta: {
85
+ docs: {
86
+ description: 'This rule checks for multi-line-style comments which fail to meet the criteria of a jsdoc block.',
87
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/no-bad-blocks.md#repos-sticky-header',
88
+ },
89
+ fixable: 'code',
90
+ schema: [
91
+ {
92
+ additionalProperties: false,
93
+ properties: {
94
+ ignore: {
95
+ items: {
96
+ type: 'string',
97
+ },
98
+ type: 'array',
99
+ },
100
+ preventAllMultiAsteriskBlocks: {
101
+ type: 'boolean',
102
+ },
103
+ },
104
+ type: 'object',
105
+ },
106
+ ],
107
+ type: 'layout',
108
+ },
109
+ });
@@ -0,0 +1,69 @@
1
+ import iterateJsdoc from '../iterateJsdoc.js';
2
+
3
+ const anyWhitespaceLines = /^\s*$/u;
4
+ const atLeastTwoLinesWhitespace = /^[ \t]*\n[ \t]*\n\s*$/u;
5
+
6
+ export default iterateJsdoc(({
7
+ jsdoc,
8
+ utils,
9
+ }) => {
10
+ const {
11
+ description,
12
+ descriptions,
13
+ lastDescriptionLine,
14
+ } = utils.getDescription();
15
+
16
+ const regex = jsdoc.tags.length ?
17
+ anyWhitespaceLines :
18
+ atLeastTwoLinesWhitespace;
19
+
20
+ if (descriptions.length && regex.test(description)) {
21
+ if (jsdoc.tags.length) {
22
+ utils.reportJSDoc(
23
+ 'There should be no blank lines in block descriptions followed by tags.',
24
+ {
25
+ line: lastDescriptionLine,
26
+ },
27
+ () => {
28
+ utils.setBlockDescription(() => {
29
+ // Remove all lines
30
+ return [];
31
+ });
32
+ },
33
+ );
34
+ } else {
35
+ utils.reportJSDoc(
36
+ 'There should be no extra blank lines in block descriptions not followed by tags.',
37
+ {
38
+ line: lastDescriptionLine,
39
+ },
40
+ () => {
41
+ utils.setBlockDescription((info, seedTokens) => {
42
+ return [
43
+ // Keep the starting line
44
+ {
45
+ number: 0,
46
+ source: '',
47
+ tokens: seedTokens({
48
+ ...info,
49
+ description: '',
50
+ }),
51
+ },
52
+ ];
53
+ });
54
+ },
55
+ );
56
+ }
57
+ }
58
+ }, {
59
+ iterateAllJsdocs: true,
60
+ meta: {
61
+ docs: {
62
+ description: 'Detects and removes extra lines of a blank block description',
63
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/no-blank-block-descriptions.md#repos-sticky-header',
64
+ },
65
+ fixable: 'whitespace',
66
+ schema: [],
67
+ type: 'layout',
68
+ },
69
+ });
@@ -0,0 +1,53 @@
1
+ import iterateJsdoc from '../iterateJsdoc.js';
2
+
3
+ export default iterateJsdoc(({
4
+ context,
5
+ jsdoc,
6
+ utils,
7
+ }) => {
8
+ if (jsdoc.tags.length) {
9
+ return;
10
+ }
11
+
12
+ const {
13
+ description,
14
+ lastDescriptionLine,
15
+ } = utils.getDescription();
16
+ if (description.trim()) {
17
+ return;
18
+ }
19
+
20
+ const {
21
+ enableFixer,
22
+ } = context.options[0] || {};
23
+
24
+ utils.reportJSDoc(
25
+ 'No empty blocks',
26
+ {
27
+ line: lastDescriptionLine,
28
+ },
29
+ enableFixer ? () => {
30
+ jsdoc.source.splice(0, jsdoc.source.length);
31
+ } : null,
32
+ );
33
+ }, {
34
+ iterateAllJsdocs: true,
35
+ meta: {
36
+ docs: {
37
+ description: 'Removes empty blocks with nothing but possibly line breaks',
38
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/no-blank-blocks.md#repos-sticky-header',
39
+ },
40
+ fixable: 'code',
41
+ schema: [
42
+ {
43
+ additionalProperties: false,
44
+ properties: {
45
+ enableFixer: {
46
+ type: 'boolean',
47
+ },
48
+ },
49
+ },
50
+ ],
51
+ type: 'suggestion',
52
+ },
53
+ });
@@ -0,0 +1,85 @@
1
+ import iterateJsdoc from '../iterateJsdoc.js';
2
+
3
+ export default iterateJsdoc(({
4
+ context,
5
+ utils,
6
+ }) => {
7
+ const {
8
+ noOptionalParamNames,
9
+ } = context.options[0] || {};
10
+ const paramTags = utils.getPresentTags([
11
+ 'param', 'arg', 'argument',
12
+ ]);
13
+ for (const tag of paramTags) {
14
+ if (noOptionalParamNames && tag.optional) {
15
+ utils.reportJSDoc(`Optional param names are not permitted on @${tag.tag}.`, tag, () => {
16
+ utils.changeTag(tag, {
17
+ name: tag.name.replace(/([^=]*)(=.+)?/u, '$1'),
18
+ });
19
+ });
20
+ } else if (tag.default) {
21
+ utils.reportJSDoc(`Defaults are not permitted on @${tag.tag}.`, tag, () => {
22
+ utils.changeTag(tag, {
23
+ name: tag.name.replace(/([^=]*)(=.+)?/u, '[$1]'),
24
+ });
25
+ });
26
+ }
27
+ }
28
+
29
+ const defaultTags = utils.getPresentTags([
30
+ 'default', 'defaultvalue',
31
+ ]);
32
+ for (const tag of defaultTags) {
33
+ if (tag.description.trim()) {
34
+ utils.reportJSDoc(`Default values are not permitted on @${tag.tag}.`, tag, () => {
35
+ utils.changeTag(tag, {
36
+ description: '',
37
+ postTag: '',
38
+ });
39
+ });
40
+ }
41
+ }
42
+ }, {
43
+ contextDefaults: true,
44
+ meta: {
45
+ docs: {
46
+ description: 'This rule reports defaults being used on the relevant portion of `@param` or `@default`.',
47
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/no-defaults.md#repos-sticky-header',
48
+ },
49
+ fixable: 'code',
50
+ schema: [
51
+ {
52
+ additionalProperties: false,
53
+ properties: {
54
+ contexts: {
55
+ items: {
56
+ anyOf: [
57
+ {
58
+ type: 'string',
59
+ },
60
+ {
61
+ additionalProperties: false,
62
+ properties: {
63
+ comment: {
64
+ type: 'string',
65
+ },
66
+ context: {
67
+ type: 'string',
68
+ },
69
+ },
70
+ type: 'object',
71
+ },
72
+ ],
73
+ },
74
+ type: 'array',
75
+ },
76
+ noOptionalParamNames: {
77
+ type: 'boolean',
78
+ },
79
+ },
80
+ type: 'object',
81
+ },
82
+ ],
83
+ type: 'suggestion',
84
+ },
85
+ });