eslint-plugin-jsdoc 48.0.0 → 48.0.1

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 +1 -1
  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,55 @@
1
+ import iterateJsdoc from '../iterateJsdoc.js';
2
+
3
+ export default iterateJsdoc(({
4
+ report,
5
+ utils,
6
+ }) => {
7
+ utils.forEachPreferredTag('param', (jsdocParameter, targetTagName) => {
8
+ if (jsdocParameter.tag && jsdocParameter.name === '') {
9
+ report(
10
+ `There must be an identifier after @${targetTagName} ${jsdocParameter.type === '' ? 'type' : 'tag'}.`,
11
+ null,
12
+ jsdocParameter,
13
+ );
14
+ }
15
+ });
16
+ }, {
17
+ contextDefaults: true,
18
+ meta: {
19
+ docs: {
20
+ description: 'Requires that all function parameters have names.',
21
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-param-name.md#repos-sticky-header',
22
+ },
23
+ schema: [
24
+ {
25
+ additionalProperties: false,
26
+ properties: {
27
+ contexts: {
28
+ items: {
29
+ anyOf: [
30
+ {
31
+ type: 'string',
32
+ },
33
+ {
34
+ additionalProperties: false,
35
+ properties: {
36
+ comment: {
37
+ type: 'string',
38
+ },
39
+ context: {
40
+ type: 'string',
41
+ },
42
+ },
43
+ type: 'object',
44
+ },
45
+ ],
46
+ },
47
+ type: 'array',
48
+ },
49
+ },
50
+ type: 'object',
51
+ },
52
+ ],
53
+ type: 'suggestion',
54
+ },
55
+ });
@@ -0,0 +1,89 @@
1
+ import iterateJsdoc from '../iterateJsdoc.js';
2
+
3
+ export default iterateJsdoc(({
4
+ context,
5
+ report,
6
+ settings,
7
+ utils,
8
+ }) => {
9
+ const {
10
+ defaultDestructuredRootType = 'object',
11
+ setDefaultDestructuredRootType = false,
12
+ } = context.options[0] || {};
13
+
14
+ const functionParameterNames = utils.getFunctionParameterNames();
15
+
16
+ let rootCount = -1;
17
+ utils.forEachPreferredTag('param', (jsdocParameter, targetTagName) => {
18
+ rootCount += jsdocParameter.name.includes('.') ? 0 : 1;
19
+ if (!jsdocParameter.type) {
20
+ if (Array.isArray(functionParameterNames[rootCount])) {
21
+ if (settings.exemptDestructuredRootsFromChecks) {
22
+ return;
23
+ }
24
+
25
+ if (setDefaultDestructuredRootType) {
26
+ utils.reportJSDoc(`Missing root type for @${targetTagName}.`, jsdocParameter, () => {
27
+ utils.changeTag(jsdocParameter, {
28
+ postType: ' ',
29
+ type: `{${defaultDestructuredRootType}}`,
30
+ });
31
+ });
32
+ return;
33
+ }
34
+ }
35
+
36
+ report(
37
+ `Missing JSDoc @${targetTagName} "${jsdocParameter.name}" type.`,
38
+ null,
39
+ jsdocParameter,
40
+ );
41
+ }
42
+ });
43
+ }, {
44
+ contextDefaults: true,
45
+ meta: {
46
+ docs: {
47
+ description: 'Requires that each `@param` tag has a `type` value.',
48
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-param-type.md#repos-sticky-header',
49
+ },
50
+ fixable: 'code',
51
+ schema: [
52
+ {
53
+ additionalProperties: false,
54
+ properties: {
55
+ contexts: {
56
+ items: {
57
+ anyOf: [
58
+ {
59
+ type: 'string',
60
+ },
61
+ {
62
+ additionalProperties: false,
63
+ properties: {
64
+ comment: {
65
+ type: 'string',
66
+ },
67
+ context: {
68
+ type: 'string',
69
+ },
70
+ },
71
+ type: 'object',
72
+ },
73
+ ],
74
+ },
75
+ type: 'array',
76
+ },
77
+ defaultDestructuredRootType: {
78
+ type: 'string',
79
+ },
80
+ setDefaultDestructuredRootType: {
81
+ type: 'boolean',
82
+ },
83
+ },
84
+ type: 'object',
85
+ },
86
+ ],
87
+ type: 'suggestion',
88
+ },
89
+ });
@@ -0,0 +1,48 @@
1
+ import iterateJsdoc from '../iterateJsdoc.js';
2
+
3
+ export default iterateJsdoc(({
4
+ utils,
5
+ }) => {
6
+ const propertyAssociatedTags = utils.filterTags(({
7
+ tag,
8
+ }) => {
9
+ return [
10
+ 'typedef', 'namespace',
11
+ ].includes(tag);
12
+ });
13
+ if (!propertyAssociatedTags.length) {
14
+ return;
15
+ }
16
+
17
+ const targetTagName = /** @type {string} */ (utils.getPreferredTagName({
18
+ tagName: 'property',
19
+ }));
20
+
21
+ if (utils.hasATag([
22
+ targetTagName,
23
+ ])) {
24
+ return;
25
+ }
26
+
27
+ for (const propertyAssociatedTag of propertyAssociatedTags) {
28
+ if (![
29
+ 'object', 'Object', 'PlainObject',
30
+ ].includes(propertyAssociatedTag.type)) {
31
+ continue;
32
+ }
33
+
34
+ utils.reportJSDoc(`Missing JSDoc @${targetTagName}.`, null, () => {
35
+ utils.addTag(targetTagName);
36
+ });
37
+ }
38
+ }, {
39
+ iterateAllJsdocs: true,
40
+ meta: {
41
+ docs: {
42
+ description: 'Requires that all `@typedef` and `@namespace` tags have `@property` when their type is a plain `object`, `Object`, or `PlainObject`.',
43
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-property.md#repos-sticky-header',
44
+ },
45
+ fixable: 'code',
46
+ type: 'suggestion',
47
+ },
48
+ });
@@ -0,0 +1,25 @@
1
+ import iterateJsdoc from '../iterateJsdoc.js';
2
+
3
+ export default iterateJsdoc(({
4
+ report,
5
+ utils,
6
+ }) => {
7
+ utils.forEachPreferredTag('property', (jsdoc, targetTagName) => {
8
+ if (!jsdoc.description.trim()) {
9
+ report(
10
+ `Missing JSDoc @${targetTagName} "${jsdoc.name}" description.`,
11
+ null,
12
+ jsdoc,
13
+ );
14
+ }
15
+ });
16
+ }, {
17
+ iterateAllJsdocs: true,
18
+ meta: {
19
+ docs: {
20
+ description: 'Requires that each `@property` tag has a `description` value.',
21
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-property-description.md#repos-sticky-header',
22
+ },
23
+ type: 'suggestion',
24
+ },
25
+ });
@@ -0,0 +1,25 @@
1
+ import iterateJsdoc from '../iterateJsdoc.js';
2
+
3
+ export default iterateJsdoc(({
4
+ report,
5
+ utils,
6
+ }) => {
7
+ utils.forEachPreferredTag('property', (jsdoc, targetTagName) => {
8
+ if (jsdoc.tag && jsdoc.name === '') {
9
+ report(
10
+ `There must be an identifier after @${targetTagName} ${jsdoc.type === '' ? 'type' : 'tag'}.`,
11
+ null,
12
+ jsdoc,
13
+ );
14
+ }
15
+ });
16
+ }, {
17
+ iterateAllJsdocs: true,
18
+ meta: {
19
+ docs: {
20
+ description: 'Requires that all function `@property` tags have names.',
21
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-property-name.md#repos-sticky-header',
22
+ },
23
+ type: 'suggestion',
24
+ },
25
+ });
@@ -0,0 +1,25 @@
1
+ import iterateJsdoc from '../iterateJsdoc.js';
2
+
3
+ export default iterateJsdoc(({
4
+ report,
5
+ utils,
6
+ }) => {
7
+ utils.forEachPreferredTag('property', (jsdoc, targetTagName) => {
8
+ if (!jsdoc.type) {
9
+ report(
10
+ `Missing JSDoc @${targetTagName} "${jsdoc.name}" type.`,
11
+ null,
12
+ jsdoc,
13
+ );
14
+ }
15
+ });
16
+ }, {
17
+ iterateAllJsdocs: true,
18
+ meta: {
19
+ docs: {
20
+ description: 'Requires that each `@property` tag has a `type` value.',
21
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-property-type.md#repos-sticky-header',
22
+ },
23
+ type: 'suggestion',
24
+ },
25
+ });
@@ -0,0 +1,238 @@
1
+ import exportParser from '../exportParser.js';
2
+ import iterateJsdoc from '../iterateJsdoc.js';
3
+
4
+ /**
5
+ * We can skip checking for a return value, in case the documentation is inherited
6
+ * or the method is either a constructor or an abstract method.
7
+ *
8
+ * In either of these cases the return value is optional or not defined.
9
+ * @param {import('../iterateJsdoc.js').Utils} utils
10
+ * a reference to the utils which are used to probe if a tag is present or not.
11
+ * @returns {boolean}
12
+ * true in case deep checking can be skipped; otherwise false.
13
+ */
14
+ const canSkip = (utils) => {
15
+ return utils.hasATag([
16
+ // inheritdoc implies that all documentation is inherited
17
+ // see https://jsdoc.app/tags-inheritdoc.html
18
+ //
19
+ // Abstract methods are by definition incomplete,
20
+ // so it is not an error if it declares a return value but does not implement it.
21
+ 'abstract',
22
+ 'virtual',
23
+
24
+ // Constructors do not have a return value by definition (https://jsdoc.app/tags-class.html)
25
+ // So we can bail out here, too.
26
+ 'class',
27
+ 'constructor',
28
+
29
+ // Return type is specified by type in @type
30
+ 'type',
31
+
32
+ // This seems to imply a class as well
33
+ 'interface',
34
+ ]) ||
35
+ utils.avoidDocs();
36
+ };
37
+
38
+ export default iterateJsdoc(({
39
+ info: {
40
+ comment,
41
+ },
42
+ node,
43
+ report,
44
+ settings,
45
+ utils,
46
+ context,
47
+ }) => {
48
+ const {
49
+ contexts,
50
+ enableFixer = false,
51
+ forceRequireReturn = false,
52
+ forceReturnsWithAsync = false,
53
+ publicOnly = false,
54
+ } = context.options[0] || {};
55
+
56
+ // A preflight check. We do not need to run a deep check
57
+ // in case the @returns comment is optional or undefined.
58
+ if (canSkip(utils)) {
59
+ return;
60
+ }
61
+
62
+ /** @type {boolean|undefined} */
63
+ let forceRequireReturnContext;
64
+ if (contexts) {
65
+ const {
66
+ foundContext,
67
+ } = utils.findContext(contexts, comment);
68
+ if (typeof foundContext === 'object') {
69
+ forceRequireReturnContext = foundContext.forceRequireReturn;
70
+ }
71
+ }
72
+
73
+ const tagName = /** @type {string} */ (utils.getPreferredTagName({
74
+ tagName: 'returns',
75
+ }));
76
+ if (!tagName) {
77
+ return;
78
+ }
79
+
80
+ const tags = utils.getTags(tagName);
81
+
82
+ if (tags.length > 1) {
83
+ report(`Found more than one @${tagName} declaration.`);
84
+ }
85
+
86
+ const iteratingFunction = utils.isIteratingFunction();
87
+
88
+ // In case the code returns something, we expect a return value in JSDoc.
89
+ const [
90
+ tag,
91
+ ] = tags;
92
+ const missingReturnTag = typeof tag === 'undefined' || tag === null;
93
+
94
+ const shouldReport = () => {
95
+ if (!missingReturnTag) {
96
+ return false;
97
+ }
98
+
99
+ if (publicOnly) {
100
+ /** @type {import('./requireJsdoc.js').RequireJsdocOpts} */
101
+ const opt = {
102
+ ancestorsOnly: Boolean(publicOnly?.ancestorsOnly ?? false),
103
+ esm: Boolean(publicOnly?.esm ?? true),
104
+ initModuleExports: Boolean(publicOnly?.cjs ?? true),
105
+ initWindow: Boolean(publicOnly?.window ?? false),
106
+ };
107
+ /* c8 ignore next -- Fallback to deprecated method */
108
+ const {
109
+ sourceCode = context.getSourceCode(),
110
+ } = context;
111
+ const exported = exportParser.isUncommentedExport(
112
+ /** @type {import('eslint').Rule.Node} */ (node), sourceCode, opt, settings,
113
+ );
114
+
115
+ if (!exported) {
116
+ return false;
117
+ }
118
+ }
119
+
120
+ if ((forceRequireReturn || forceRequireReturnContext) && (
121
+ iteratingFunction || utils.isVirtualFunction()
122
+ )) {
123
+ return true;
124
+ }
125
+
126
+ const isAsync = !iteratingFunction && utils.hasTag('async') ||
127
+ iteratingFunction && utils.isAsync();
128
+
129
+ if (forceReturnsWithAsync && isAsync) {
130
+ return true;
131
+ }
132
+
133
+ return iteratingFunction && utils.hasValueOrExecutorHasNonEmptyResolveValue(
134
+ forceReturnsWithAsync,
135
+ );
136
+ };
137
+
138
+ if (shouldReport()) {
139
+ utils.reportJSDoc(`Missing JSDoc @${tagName} declaration.`, null, enableFixer ? () => {
140
+ utils.addTag(tagName);
141
+ } : null);
142
+ }
143
+ }, {
144
+ contextDefaults: true,
145
+ meta: {
146
+ docs: {
147
+ description: 'Requires that returns are documented.',
148
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-returns.md#repos-sticky-header',
149
+ },
150
+ fixable: 'code',
151
+ schema: [
152
+ {
153
+ additionalProperties: false,
154
+ properties: {
155
+ checkConstructors: {
156
+ default: false,
157
+ type: 'boolean',
158
+ },
159
+ checkGetters: {
160
+ default: true,
161
+ type: 'boolean',
162
+ },
163
+ contexts: {
164
+ items: {
165
+ anyOf: [
166
+ {
167
+ type: 'string',
168
+ },
169
+ {
170
+ additionalProperties: false,
171
+ properties: {
172
+ comment: {
173
+ type: 'string',
174
+ },
175
+ context: {
176
+ type: 'string',
177
+ },
178
+ forceRequireReturn: {
179
+ type: 'boolean',
180
+ },
181
+ },
182
+ type: 'object',
183
+ },
184
+ ],
185
+ },
186
+ type: 'array',
187
+ },
188
+ enableFixer: {
189
+ type: 'boolean',
190
+ },
191
+ exemptedBy: {
192
+ items: {
193
+ type: 'string',
194
+ },
195
+ type: 'array',
196
+ },
197
+ forceRequireReturn: {
198
+ default: false,
199
+ type: 'boolean',
200
+ },
201
+ forceReturnsWithAsync: {
202
+ default: false,
203
+ type: 'boolean',
204
+ },
205
+ publicOnly: {
206
+ oneOf: [
207
+ {
208
+ default: false,
209
+ type: 'boolean',
210
+ },
211
+ {
212
+ additionalProperties: false,
213
+ default: {},
214
+ properties: {
215
+ ancestorsOnly: {
216
+ type: 'boolean',
217
+ },
218
+ cjs: {
219
+ type: 'boolean',
220
+ },
221
+ esm: {
222
+ type: 'boolean',
223
+ },
224
+ window: {
225
+ type: 'boolean',
226
+ },
227
+ },
228
+ type: 'object',
229
+ },
230
+ ],
231
+ },
232
+ },
233
+ type: 'object',
234
+ },
235
+ ],
236
+ type: 'suggestion',
237
+ },
238
+ });
@@ -0,0 +1,141 @@
1
+ import iterateJsdoc from '../iterateJsdoc.js';
2
+
3
+ /**
4
+ * @param {import('../iterateJsdoc.js').Utils} utils
5
+ * @param {import('../iterateJsdoc.js').Settings} settings
6
+ * @returns {boolean}
7
+ */
8
+ const canSkip = (utils, settings) => {
9
+ const voidingTags = [
10
+ // An abstract function is by definition incomplete
11
+ // so it is perfectly fine if a return is documented but
12
+ // not present within the function.
13
+ // A subclass may inherit the doc and implement the
14
+ // missing return.
15
+ 'abstract',
16
+ 'virtual',
17
+
18
+ // A constructor function returns `this` by default, so may be `@returns`
19
+ // tag indicating this but no explicit return
20
+ 'class',
21
+ 'constructor',
22
+ 'interface',
23
+ ];
24
+
25
+ if (settings.mode === 'closure') {
26
+ // Structural Interface in GCC terms, equivalent to @interface tag as far as this rule is concerned
27
+ voidingTags.push('record');
28
+ }
29
+
30
+ return utils.hasATag(voidingTags) ||
31
+ utils.isConstructor() ||
32
+ utils.classHasTag('interface') ||
33
+ settings.mode === 'closure' && utils.classHasTag('record');
34
+ };
35
+
36
+ // eslint-disable-next-line complexity -- Temporary
37
+ export default iterateJsdoc(({
38
+ context,
39
+ node,
40
+ report,
41
+ settings,
42
+ utils,
43
+ }) => {
44
+ const {
45
+ exemptAsync = true,
46
+ exemptGenerators = settings.mode === 'typescript',
47
+ reportMissingReturnForUndefinedTypes = false,
48
+ } = context.options[0] || {};
49
+
50
+ if (canSkip(utils, settings)) {
51
+ return;
52
+ }
53
+
54
+ if (exemptAsync && utils.isAsync()) {
55
+ return;
56
+ }
57
+
58
+ const tagName = /** @type {string} */ (utils.getPreferredTagName({
59
+ tagName: 'returns',
60
+ }));
61
+ if (!tagName) {
62
+ return;
63
+ }
64
+
65
+ const tags = utils.getTags(tagName);
66
+
67
+ if (tags.length === 0) {
68
+ return;
69
+ }
70
+
71
+ if (tags.length > 1) {
72
+ report(`Found more than one @${tagName} declaration.`);
73
+
74
+ return;
75
+ }
76
+
77
+ const [
78
+ tag,
79
+ ] = tags;
80
+
81
+ const type = tag.type.trim();
82
+
83
+ // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions
84
+ if (/asserts\s/u.test(type)) {
85
+ return;
86
+ }
87
+
88
+ const returnNever = type === 'never';
89
+
90
+ if (returnNever && utils.hasValueOrExecutorHasNonEmptyResolveValue(false)) {
91
+ report(`JSDoc @${tagName} declaration set with "never" but return expression is present in function.`);
92
+
93
+ return;
94
+ }
95
+
96
+ // In case a return value is declared in JSDoc, we also expect one in the code.
97
+ if (
98
+ !returnNever &&
99
+ (
100
+ reportMissingReturnForUndefinedTypes ||
101
+ !utils.mayBeUndefinedTypeTag(tag)
102
+ ) &&
103
+ (tag.type === '' && !utils.hasValueOrExecutorHasNonEmptyResolveValue(
104
+ exemptAsync,
105
+ ) ||
106
+ tag.type !== '' && !utils.hasValueOrExecutorHasNonEmptyResolveValue(
107
+ exemptAsync,
108
+ true,
109
+ )) &&
110
+ (!exemptGenerators || !('generator' in /** @type {import('../iterateJsdoc.js').Node} */ (node)) || !node.generator)
111
+ ) {
112
+ report(`JSDoc @${tagName} declaration present but return expression not available in function.`);
113
+ }
114
+ }, {
115
+ meta: {
116
+ docs: {
117
+ description: 'Requires a return statement in function body if a `@returns` tag is specified in jsdoc comment.',
118
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-returns-check.md#repos-sticky-header',
119
+ },
120
+ schema: [
121
+ {
122
+ additionalProperties: false,
123
+ properties: {
124
+ exemptAsync: {
125
+ default: true,
126
+ type: 'boolean',
127
+ },
128
+ exemptGenerators: {
129
+ type: 'boolean',
130
+ },
131
+ reportMissingReturnForUndefinedTypes: {
132
+ default: false,
133
+ type: 'boolean',
134
+ },
135
+ },
136
+ type: 'object',
137
+ },
138
+ ],
139
+ type: 'suggestion',
140
+ },
141
+ });
@@ -0,0 +1,59 @@
1
+ import iterateJsdoc from '../iterateJsdoc.js';
2
+
3
+ export default iterateJsdoc(({
4
+ report,
5
+ utils,
6
+ }) => {
7
+ utils.forEachPreferredTag('returns', (jsdocTag, targetTagName) => {
8
+ const type = jsdocTag.type && jsdocTag.type.trim();
9
+
10
+ if ([
11
+ 'void', 'undefined', 'Promise<void>', 'Promise<undefined>',
12
+ ].includes(type)) {
13
+ return;
14
+ }
15
+
16
+ if (!jsdocTag.description.trim()) {
17
+ report(`Missing JSDoc @${targetTagName} description.`, null, jsdocTag);
18
+ }
19
+ });
20
+ }, {
21
+ contextDefaults: true,
22
+ meta: {
23
+ docs: {
24
+ description: 'Requires that the `@returns` tag has a `description` value.',
25
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-returns-description.md#repos-sticky-header',
26
+ },
27
+ schema: [
28
+ {
29
+ additionalProperties: false,
30
+ properties: {
31
+ contexts: {
32
+ items: {
33
+ anyOf: [
34
+ {
35
+ type: 'string',
36
+ },
37
+ {
38
+ additionalProperties: false,
39
+ properties: {
40
+ comment: {
41
+ type: 'string',
42
+ },
43
+ context: {
44
+ type: 'string',
45
+ },
46
+ },
47
+ type: 'object',
48
+ },
49
+ ],
50
+ },
51
+ type: 'array',
52
+ },
53
+ },
54
+ type: 'object',
55
+ },
56
+ ],
57
+ type: 'suggestion',
58
+ },
59
+ });