eslint-plugin-jsdoc 60.5.0 → 60.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/cjs/jsdocUtils.d.ts +1 -0
- package/dist/cjs/rules/escapeInlineTags.d.ts +2 -0
- package/dist/generateDocs.cjs +5 -6
- package/dist/generateDocs.cjs.map +1 -1
- package/dist/index-cjs.cjs +4 -1
- package/dist/index-cjs.cjs.map +1 -1
- package/dist/index.cjs +4 -1
- package/dist/index.cjs.map +1 -1
- package/dist/jsdocUtils.cjs +3 -2
- package/dist/jsdocUtils.cjs.map +1 -1
- package/dist/jsdocUtils.d.ts +1 -0
- package/dist/rules/checkLineAlignment.cjs +1 -2
- package/dist/rules/checkLineAlignment.cjs.map +1 -1
- package/dist/rules/checkTypes.cjs +2 -3
- package/dist/rules/checkTypes.cjs.map +1 -1
- package/dist/rules/convertToJsdocComments.cjs +2 -4
- package/dist/rules/convertToJsdocComments.cjs.map +1 -1
- package/dist/rules/emptyTags.cjs +1 -2
- package/dist/rules/emptyTags.cjs.map +1 -1
- package/dist/rules/escapeInlineTags.cjs +149 -0
- package/dist/rules/escapeInlineTags.cjs.map +1 -0
- package/dist/rules/escapeInlineTags.d.ts +3 -0
- package/dist/rules/informativeDocs.cjs +3 -6
- package/dist/rules/informativeDocs.cjs.map +1 -1
- package/dist/rules/linesBeforeBlock.cjs +4 -8
- package/dist/rules/linesBeforeBlock.cjs.map +1 -1
- package/dist/rules/matchDescription.cjs +2 -4
- package/dist/rules/matchDescription.cjs.map +1 -1
- package/dist/rules/matchName.cjs +1 -2
- package/dist/rules/matchName.cjs.map +1 -1
- package/dist/rules/multilineBlocks.cjs +3 -6
- package/dist/rules/multilineBlocks.cjs.map +1 -1
- package/dist/rules/noBadBlocks.cjs +1 -2
- package/dist/rules/noBadBlocks.cjs.map +1 -1
- package/dist/rules/noTypes.cjs +1 -2
- package/dist/rules/noTypes.cjs.map +1 -1
- package/dist/rules/preferImportTag.cjs +6 -2
- package/dist/rules/preferImportTag.cjs.map +1 -1
- package/dist/rules/requireAsteriskPrefix.cjs +1 -2
- package/dist/rules/requireAsteriskPrefix.cjs.map +1 -1
- package/dist/rules/requireDescriptionCompleteSentence.cjs +1 -2
- package/dist/rules/requireDescriptionCompleteSentence.cjs.map +1 -1
- package/dist/rules/requireFileOverview.cjs +1 -3
- package/dist/rules/requireFileOverview.cjs.map +1 -1
- package/dist/rules/requireHyphenBeforeParamDescription.cjs +1 -2
- package/dist/rules/requireHyphenBeforeParamDescription.cjs.map +1 -1
- package/dist/rules/requireJsdoc.cjs +3 -6
- package/dist/rules/requireJsdoc.cjs.map +1 -1
- package/dist/rules/requireParam.cjs +6 -12
- package/dist/rules/requireParam.cjs.map +1 -1
- package/dist/rules/requireParamName.cjs +1 -2
- package/dist/rules/requireParamName.cjs.map +1 -1
- package/dist/rules/requireReturns.cjs +1 -2
- package/dist/rules/requireReturns.cjs.map +1 -1
- package/dist/rules/requireReturnsCheck.cjs +13 -1
- package/dist/rules/requireReturnsCheck.cjs.map +1 -1
- package/dist/rules/requireTemplate.cjs +1 -2
- package/dist/rules/requireTemplate.cjs.map +1 -1
- package/dist/rules/sortTags.cjs +1 -2
- package/dist/rules/sortTags.cjs.map +1 -1
- package/dist/rules.d.ts +30 -37
- package/package.json +9 -9
- package/src/index-cjs.js +4 -0
- package/src/index.js +4 -0
- package/src/jsdocUtils.js +17 -1
- package/src/rules/checkLineAlignment.js +1 -2
- package/src/rules/checkTypes.js +3 -15
- package/src/rules/convertToJsdocComments.js +2 -4
- package/src/rules/emptyTags.js +1 -2
- package/src/rules/escapeInlineTags.js +189 -0
- package/src/rules/informativeDocs.js +3 -6
- package/src/rules/linesBeforeBlock.js +4 -8
- package/src/rules/matchDescription.js +2 -4
- package/src/rules/matchName.js +1 -2
- package/src/rules/multilineBlocks.js +3 -6
- package/src/rules/noBadBlocks.js +1 -2
- package/src/rules/noTypes.js +1 -2
- package/src/rules/preferImportTag.js +8 -3
- package/src/rules/requireAsteriskPrefix.js +1 -2
- package/src/rules/requireDescriptionCompleteSentence.js +1 -2
- package/src/rules/requireFileOverview.js +1 -3
- package/src/rules/requireHyphenBeforeParamDescription.js +1 -2
- package/src/rules/requireJsdoc.js +3 -6
- package/src/rules/requireParam.js +6 -12
- package/src/rules/requireParamName.js +1 -2
- package/src/rules/requireReturns.js +1 -2
- package/src/rules/requireReturnsCheck.js +16 -1
- package/src/rules/requireTemplate.js +1 -2
- package/src/rules/sortTags.js +1 -2
- package/src/rules.d.ts +30 -37
package/src/rules/checkTypes.js
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildRejectOrPreferRuleDefinition,
|
|
3
3
|
} from '../buildRejectOrPreferRuleDefinition.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
'null',
|
|
8
|
-
'boolean',
|
|
9
|
-
'number',
|
|
10
|
-
'bigint',
|
|
11
|
-
'string',
|
|
12
|
-
'symbol',
|
|
13
|
-
'object',
|
|
14
|
-
'Array',
|
|
15
|
-
'Function',
|
|
16
|
-
'Date',
|
|
17
|
-
'RegExp',
|
|
18
|
-
];
|
|
4
|
+
import {
|
|
5
|
+
strictNativeTypes,
|
|
6
|
+
} from '../jsdocUtils.js';
|
|
19
7
|
|
|
20
8
|
/**
|
|
21
9
|
* @callback CheckNativeTypes
|
|
@@ -319,8 +319,7 @@ Supplying your own value overrides the defaults.`,
|
|
|
319
319
|
Can either be strings or an object with a \`context\` string and an optional, default \`false\` \`inlineCommentBlock\` boolean.
|
|
320
320
|
|
|
321
321
|
Defaults to \`ArrowFunctionExpression\`, \`FunctionDeclaration\`,
|
|
322
|
-
\`FunctionExpression\`, \`TSDeclareFunction
|
|
323
|
-
`,
|
|
322
|
+
\`FunctionExpression\`, \`TSDeclareFunction\`.`,
|
|
324
323
|
items: {
|
|
325
324
|
anyOf: [
|
|
326
325
|
{
|
|
@@ -417,8 +416,7 @@ be converted to \`multi\` style JSDoc comments.)
|
|
|
417
416
|
/** Some text */
|
|
418
417
|
\`\`\`
|
|
419
418
|
|
|
420
|
-
Defaults to \`multi
|
|
421
|
-
`,
|
|
419
|
+
Defaults to \`multi\`.`,
|
|
422
420
|
enum: [
|
|
423
421
|
'multi', 'single',
|
|
424
422
|
],
|
package/src/rules/emptyTags.js
CHANGED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import iterateJsdoc from '../iterateJsdoc.js';
|
|
2
|
+
|
|
3
|
+
export default iterateJsdoc(({
|
|
4
|
+
context,
|
|
5
|
+
jsdoc,
|
|
6
|
+
settings,
|
|
7
|
+
utils,
|
|
8
|
+
}) => {
|
|
9
|
+
const {
|
|
10
|
+
mode,
|
|
11
|
+
} = settings;
|
|
12
|
+
|
|
13
|
+
if (mode !== 'typescript') {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
allowedInlineTags = [],
|
|
19
|
+
enableFixer = false,
|
|
20
|
+
fixType = 'backslash',
|
|
21
|
+
} = context.options[0] || {};
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
description,
|
|
25
|
+
} = utils.getDescription();
|
|
26
|
+
|
|
27
|
+
/** @type {string[]} */
|
|
28
|
+
const tagNames = [];
|
|
29
|
+
|
|
30
|
+
/** @type {number[]} */
|
|
31
|
+
const indexes = [];
|
|
32
|
+
|
|
33
|
+
const unescapedInlineTagRegex = /(?:^|\s)@(\w+)/gv;
|
|
34
|
+
for (const [
|
|
35
|
+
idx,
|
|
36
|
+
descLine,
|
|
37
|
+
] of (
|
|
38
|
+
description.startsWith('\n') ? description.slice(1) : description
|
|
39
|
+
).split('\n').entries()
|
|
40
|
+
) {
|
|
41
|
+
descLine.replaceAll(unescapedInlineTagRegex, (_, tagName) => {
|
|
42
|
+
if (allowedInlineTags.includes(tagName)) {
|
|
43
|
+
return _;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
tagNames.push(tagName);
|
|
47
|
+
indexes.push(idx);
|
|
48
|
+
|
|
49
|
+
return _;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for (const [
|
|
54
|
+
idx,
|
|
55
|
+
tagName,
|
|
56
|
+
] of tagNames.entries()) {
|
|
57
|
+
utils.reportJSDoc(
|
|
58
|
+
`Unexpected inline JSDoc tag. Did you mean to use {@${tagName}}, \\@${tagName}, or \`@${tagName}\`?`,
|
|
59
|
+
{
|
|
60
|
+
line: indexes[idx] + 1,
|
|
61
|
+
},
|
|
62
|
+
enableFixer ?
|
|
63
|
+
() => {
|
|
64
|
+
utils.setBlockDescription((info, seedTokens, descLines) => {
|
|
65
|
+
return descLines.map((desc) => {
|
|
66
|
+
const newDesc = desc.replaceAll(
|
|
67
|
+
new RegExp(`(^|\\s)@${
|
|
68
|
+
// No need to escape, as contains only safe characters
|
|
69
|
+
tagName
|
|
70
|
+
}`, 'gv'),
|
|
71
|
+
fixType === 'backticks' ? '$1`@' + tagName + '`' : '$1\\@' + tagName,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
number: 0,
|
|
76
|
+
source: '',
|
|
77
|
+
tokens: seedTokens({
|
|
78
|
+
...info,
|
|
79
|
+
description: newDesc,
|
|
80
|
+
postDelimiter: newDesc.trim() ? ' ' : '',
|
|
81
|
+
}),
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
} :
|
|
86
|
+
null,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param {string} tagName
|
|
92
|
+
* @returns {[
|
|
93
|
+
* RegExp,
|
|
94
|
+
* (description: string) => string
|
|
95
|
+
* ]}
|
|
96
|
+
*/
|
|
97
|
+
const escapeInlineTags = (tagName) => {
|
|
98
|
+
const regex = new RegExp(`(^|\\s)@${
|
|
99
|
+
// No need to escape, as contains only safe characters
|
|
100
|
+
tagName
|
|
101
|
+
}`, 'gv');
|
|
102
|
+
|
|
103
|
+
return [
|
|
104
|
+
regex,
|
|
105
|
+
/**
|
|
106
|
+
* @param {string} desc
|
|
107
|
+
*/
|
|
108
|
+
(desc) => {
|
|
109
|
+
return desc.replaceAll(
|
|
110
|
+
regex,
|
|
111
|
+
fixType === 'backticks' ? '$1`@' + tagName + '`' : '$1\\@' + tagName,
|
|
112
|
+
);
|
|
113
|
+
},
|
|
114
|
+
];
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
for (const tag of jsdoc.tags) {
|
|
118
|
+
if (tag.tag === 'example') {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** @type {string} */
|
|
123
|
+
let tagName = '';
|
|
124
|
+
while (/** @type {string[]} */ (
|
|
125
|
+
utils.getTagDescription(tag, true)
|
|
126
|
+
// eslint-disable-next-line no-loop-func -- Safe
|
|
127
|
+
).some((desc) => {
|
|
128
|
+
tagName = unescapedInlineTagRegex.exec(desc)?.[1] ?? '';
|
|
129
|
+
if (allowedInlineTags.includes(tagName)) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return tagName;
|
|
134
|
+
})) {
|
|
135
|
+
const line = utils.setTagDescription(tag, ...escapeInlineTags(tagName)) +
|
|
136
|
+
tag.source[0].number;
|
|
137
|
+
utils.reportJSDoc(
|
|
138
|
+
`Unexpected inline JSDoc tag. Did you mean to use {@${tagName}}, \\@${tagName}, or \`@${tagName}\`?`,
|
|
139
|
+
{
|
|
140
|
+
line,
|
|
141
|
+
},
|
|
142
|
+
enableFixer ? () => {} : null,
|
|
143
|
+
true,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}, {
|
|
148
|
+
iterateAllJsdocs: true,
|
|
149
|
+
meta: {
|
|
150
|
+
docs: {
|
|
151
|
+
description: 'Reports use of JSDoc tags in non-tag positions (in the default "typescript" mode).',
|
|
152
|
+
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/escape-inline-tags.md#repos-sticky-header',
|
|
153
|
+
},
|
|
154
|
+
fixable: 'code',
|
|
155
|
+
schema: [
|
|
156
|
+
{
|
|
157
|
+
additionalProperties: false,
|
|
158
|
+
properties: {
|
|
159
|
+
allowedInlineTags: {
|
|
160
|
+
description: 'A listing of tags you wish to allow unescaped. Defaults to an empty array.',
|
|
161
|
+
items: {
|
|
162
|
+
type: 'string',
|
|
163
|
+
},
|
|
164
|
+
type: 'array',
|
|
165
|
+
},
|
|
166
|
+
enableFixer: {
|
|
167
|
+
description: 'Whether to enable the fixer. Defaults to `false`.',
|
|
168
|
+
type: 'boolean',
|
|
169
|
+
},
|
|
170
|
+
fixType: {
|
|
171
|
+
description: `How to escape the inline tag.
|
|
172
|
+
|
|
173
|
+
May be "backticks" to enclose tags in backticks (treating as code segments), or
|
|
174
|
+
"backslash" to escape tags with a backslash, i.e., \`\\@\`
|
|
175
|
+
|
|
176
|
+
Defaults to "backslash".`,
|
|
177
|
+
enum: [
|
|
178
|
+
'backticks',
|
|
179
|
+
'backslash',
|
|
180
|
+
],
|
|
181
|
+
type: 'string',
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
type: 'object',
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
type: 'suggestion',
|
|
188
|
+
},
|
|
189
|
+
});
|
|
@@ -171,8 +171,7 @@ The default \`aliases\` option is:
|
|
|
171
171
|
{
|
|
172
172
|
"a": ["an", "our"]
|
|
173
173
|
}
|
|
174
|
-
|
|
175
|
-
`,
|
|
174
|
+
\`\`\``,
|
|
176
175
|
patternProperties: {
|
|
177
176
|
'.*': {
|
|
178
177
|
items: {
|
|
@@ -194,8 +193,7 @@ function computeTypes(node) {
|
|
|
194
193
|
}
|
|
195
194
|
\`\`\`
|
|
196
195
|
|
|
197
|
-
No tags are excluded by default
|
|
198
|
-
`,
|
|
196
|
+
No tags are excluded by default.`,
|
|
199
197
|
items: {
|
|
200
198
|
type: 'string',
|
|
201
199
|
},
|
|
@@ -215,8 +213,7 @@ The default \`uselessWords\` option is:
|
|
|
215
213
|
|
|
216
214
|
\`\`\`json
|
|
217
215
|
["a", "an", "i", "in", "of", "s", "the"]
|
|
218
|
-
|
|
219
|
-
`,
|
|
216
|
+
\`\`\``,
|
|
220
217
|
items: {
|
|
221
218
|
type: 'string',
|
|
222
219
|
},
|
|
@@ -109,15 +109,13 @@ export default iterateJsdoc(({
|
|
|
109
109
|
properties: {
|
|
110
110
|
checkBlockStarts: {
|
|
111
111
|
description: `Whether to additionally check the start of blocks, such as classes or functions.
|
|
112
|
-
Defaults to \`false
|
|
113
|
-
`,
|
|
112
|
+
Defaults to \`false\`.`,
|
|
114
113
|
type: 'boolean',
|
|
115
114
|
},
|
|
116
115
|
excludedTags: {
|
|
117
116
|
description: `An array of tags whose presence in the JSDoc block will prevent the
|
|
118
117
|
application of the rule. Defaults to \`['type']\` (i.e., if \`@type\` is present,
|
|
119
|
-
lines before the block will not be added)
|
|
120
|
-
`,
|
|
118
|
+
lines before the block will not be added).`,
|
|
121
119
|
items: {
|
|
122
120
|
type: 'string',
|
|
123
121
|
},
|
|
@@ -125,14 +123,12 @@ lines before the block will not be added).
|
|
|
125
123
|
},
|
|
126
124
|
ignoreSameLine: {
|
|
127
125
|
description: `This option excludes cases where the JSDoc block occurs on the same line as a
|
|
128
|
-
preceding code or comment. Defaults to \`true
|
|
129
|
-
`,
|
|
126
|
+
preceding code or comment. Defaults to \`true\`.`,
|
|
130
127
|
type: 'boolean',
|
|
131
128
|
},
|
|
132
129
|
ignoreSingleLines: {
|
|
133
130
|
description: `This option excludes cases where the JSDoc block is only one line long.
|
|
134
|
-
Defaults to \`true
|
|
135
|
-
`,
|
|
131
|
+
Defaults to \`true\`.`,
|
|
136
132
|
type: 'boolean',
|
|
137
133
|
},
|
|
138
134
|
lines: {
|
|
@@ -184,8 +184,7 @@ Overrides the default contexts (\`ArrowFunctionExpression\`, \`FunctionDeclarati
|
|
|
184
184
|
JSDoc block throughout your files.
|
|
185
185
|
|
|
186
186
|
See the ["AST and Selectors"](../#advanced-ast-and-selectors)
|
|
187
|
-
section of our Advanced docs for more on the expected format
|
|
188
|
-
`,
|
|
187
|
+
section of our Advanced docs for more on the expected format.`,
|
|
189
188
|
items: {
|
|
190
189
|
anyOf: [
|
|
191
190
|
{
|
|
@@ -302,8 +301,7 @@ literal, e.g., \`/[A-Z].*\\./vi\`.
|
|
|
302
301
|
\`\`\`
|
|
303
302
|
|
|
304
303
|
This can be overridden per tag or for the main block description by setting
|
|
305
|
-
\`message\` within \`tags\` or \`mainDescription\`, respectively
|
|
306
|
-
`,
|
|
304
|
+
\`message\` within \`tags\` or \`mainDescription\`, respectively.`,
|
|
307
305
|
type: 'string',
|
|
308
306
|
},
|
|
309
307
|
nonemptyTags: {
|
package/src/rules/matchName.js
CHANGED
|
@@ -118,8 +118,7 @@ fixes found by the likes of \`disallowName\` even when a different tag has the
|
|
|
118
118
|
disallowed name. An alternative is to ensure that \`comment\` finds the specific
|
|
119
119
|
tag of the desired tag and/or name and no \`disallowName\` (or \`allowName\`) is
|
|
120
120
|
supplied. In such a case, only one error will be reported, but no fixer will
|
|
121
|
-
be applied, however
|
|
122
|
-
`,
|
|
121
|
+
be applied, however.`,
|
|
123
122
|
items: {
|
|
124
123
|
additionalProperties: false,
|
|
125
124
|
properties: {
|
|
@@ -494,8 +494,7 @@ such a tag will cause multiline blocks to be allowed.
|
|
|
494
494
|
You may set this to an empty array to prevent any tag from permitting multiple
|
|
495
495
|
lines.
|
|
496
496
|
|
|
497
|
-
Defaults to \`['*']
|
|
498
|
-
`,
|
|
497
|
+
Defaults to \`['*']\`.`,
|
|
499
498
|
},
|
|
500
499
|
noFinalLineText: {
|
|
501
500
|
description: `For multiline blocks, any non-whitespace text preceding the \`*/\` on the final
|
|
@@ -518,8 +517,7 @@ Defaults to \`false\`.`,
|
|
|
518
517
|
description: `If this is \`true\`, any single line blocks will be reported, except those which
|
|
519
518
|
are whitelisted in \`singleLineTags\`.
|
|
520
519
|
|
|
521
|
-
Defaults to \`false
|
|
522
|
-
`,
|
|
520
|
+
Defaults to \`false\`.`,
|
|
523
521
|
type: 'boolean',
|
|
524
522
|
},
|
|
525
523
|
noZeroLineText: {
|
|
@@ -539,8 +537,7 @@ for such cases. Blocks are not reported which have multi-line descriptions,
|
|
|
539
537
|
multiple tags, a block description and tag, or tags with multi-line types or
|
|
540
538
|
descriptions.
|
|
541
539
|
|
|
542
|
-
Defaults to \`null
|
|
543
|
-
`,
|
|
540
|
+
Defaults to \`null\`.`,
|
|
544
541
|
type: 'number',
|
|
545
542
|
},
|
|
546
543
|
singleLineTags: {
|
package/src/rules/noBadBlocks.js
CHANGED
|
@@ -106,8 +106,7 @@ export default iterateJsdoc(({
|
|
|
106
106
|
a multi-comment block and at-sign \`/* @\`.
|
|
107
107
|
|
|
108
108
|
Defaults to \`['ts-check', 'ts-expect-error', 'ts-ignore', 'ts-nocheck']\`
|
|
109
|
-
(some directives [used by TypeScript](https://www.typescriptlang.org/docs/handbook/intro-to-js-ts.html#ts-check))
|
|
110
|
-
`,
|
|
109
|
+
(some directives [used by TypeScript](https://www.typescriptlang.org/docs/handbook/intro-to-js-ts.html#ts-check)).`,
|
|
111
110
|
items: {
|
|
112
111
|
type: 'string',
|
|
113
112
|
},
|
package/src/rules/noTypes.js
CHANGED
|
@@ -77,8 +77,7 @@ expression, i.e., \`@callback\` or \`@function\` (or its aliases \`@func\` or
|
|
|
77
77
|
\`@method\`) (including those associated with an \`@interface\`).
|
|
78
78
|
|
|
79
79
|
See the ["AST and Selectors"](../#advanced-ast-and-selectors)
|
|
80
|
-
section of our Advanced docs for more on the expected format
|
|
81
|
-
`,
|
|
80
|
+
section of our Advanced docs for more on the expected format.`,
|
|
82
81
|
items: {
|
|
83
82
|
anyOf: [
|
|
84
83
|
{
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
|
|
17
17
|
export default iterateJsdoc(({
|
|
18
18
|
context,
|
|
19
|
+
indent,
|
|
19
20
|
jsdoc,
|
|
20
21
|
settings,
|
|
21
22
|
sourceCode,
|
|
@@ -363,10 +364,14 @@ export default iterateJsdoc(({
|
|
|
363
364
|
enableFixer ? (fixer) => {
|
|
364
365
|
getFixer(element.value, [])();
|
|
365
366
|
|
|
366
|
-
const programNode = sourceCode.
|
|
367
|
+
const programNode = sourceCode.ast;
|
|
368
|
+
const commentNodes = sourceCode.getCommentsBefore(programNode);
|
|
367
369
|
return fixer.insertTextBefore(
|
|
368
|
-
|
|
369
|
-
|
|
370
|
+
// @ts-expect-error Ok
|
|
371
|
+
commentNodes[0] ?? programNode,
|
|
372
|
+
`/** @import * as ${element.value} from '${element.value}'; */${
|
|
373
|
+
commentNodes[0] ? '\n' + indent : ''
|
|
374
|
+
}`,
|
|
370
375
|
);
|
|
371
376
|
} : null,
|
|
372
377
|
);
|
|
@@ -346,8 +346,7 @@ All other tags will treat the text following the tag name, a space, and
|
|
|
346
346
|
an optional curly-bracketed type expression (and another space) as part of
|
|
347
347
|
its "description" (e.g., for \`@returns {someType} some description\`, the
|
|
348
348
|
description is \`some description\` while for \`@some-tag xyz\`, the description
|
|
349
|
-
is \`xyz\`)
|
|
350
|
-
`,
|
|
349
|
+
is \`xyz\`).`,
|
|
351
350
|
items: {
|
|
352
351
|
type: 'string',
|
|
353
352
|
},
|
|
@@ -176,9 +176,7 @@ have a way to allow multiple licenses for the whole page by using the SPDX
|
|
|
176
176
|
Note that the tag names are the main JSDoc tag name, so you should use \`file\`
|
|
177
177
|
in this configuration object regardless of whether you have configured
|
|
178
178
|
\`fileoverview\` instead of \`file\` on \`tagNamePreference\` (i.e., \`fileoverview\`
|
|
179
|
-
will be checked, but you must use \`file\` on the configuration object)
|
|
180
|
-
|
|
181
|
-
`,
|
|
179
|
+
will be checked, but you must use \`file\` on the configuration object).`,
|
|
182
180
|
patternProperties: {
|
|
183
181
|
'.*': {
|
|
184
182
|
additionalProperties: false,
|
|
@@ -199,8 +199,7 @@ other tags besides the \`@param\` tag (or the \`@arg\` tag if so set).`,
|
|
|
199
199
|
to ensure \`@property\` never uses hyphens. A key can also be set as \`*\`, e.g.,
|
|
200
200
|
\`'*': 'always'\` to apply hyphen checking to any tag (besides the preferred
|
|
201
201
|
\`@param\` tag which follows the main string option setting and besides any
|
|
202
|
-
other \`tags\` entries)
|
|
203
|
-
`,
|
|
202
|
+
other \`tags\` entries).`,
|
|
204
203
|
},
|
|
205
204
|
},
|
|
206
205
|
type: 'object',
|
|
@@ -60,8 +60,7 @@ no parameters or return values are found.`,
|
|
|
60
60
|
boolean, this option can be set to the string \`"no-setter"\` to indicate that
|
|
61
61
|
getters should be checked but only when there is no setter. This may be useful
|
|
62
62
|
if one only wishes documentation on one of the two accessors. Defaults to
|
|
63
|
-
\`false
|
|
64
|
-
`,
|
|
63
|
+
\`false\`.`,
|
|
65
64
|
},
|
|
66
65
|
checkSetters: {
|
|
67
66
|
anyOf: [
|
|
@@ -143,8 +142,7 @@ Defaults to \`true\`.`,
|
|
|
143
142
|
functions/methods with no parameters or return values (intended where
|
|
144
143
|
function/method names are sufficient for themselves as documentation).
|
|
145
144
|
|
|
146
|
-
Defaults to \`false
|
|
147
|
-
`,
|
|
145
|
+
Defaults to \`false\`.`,
|
|
148
146
|
type: 'boolean',
|
|
149
147
|
},
|
|
150
148
|
exemptOverloadedImplementations: {
|
|
@@ -178,8 +176,7 @@ otherwise noted):
|
|
|
178
176
|
- \`ancestorsOnly\` - Optimization to only check node ancestors to check if node is exported
|
|
179
177
|
- \`esm\` - ESM exports are checked for JSDoc comments (Defaults to \`true\`)
|
|
180
178
|
- \`cjs\` - CommonJS exports are checked for JSDoc comments (Defaults to \`true\`)
|
|
181
|
-
- \`window\` - Window global exports are checked for JSDoc comments
|
|
182
|
-
`,
|
|
179
|
+
- \`window\` - Window global exports are checked for JSDoc comments`,
|
|
183
180
|
oneOf: [
|
|
184
181
|
{
|
|
185
182
|
default: false,
|
|
@@ -548,15 +548,13 @@ export default iterateJsdoc(({
|
|
|
548
548
|
autoIncrementBase: {
|
|
549
549
|
default: 0,
|
|
550
550
|
description: `Numeric to indicate the number at which to begin auto-incrementing roots.
|
|
551
|
-
Defaults to \`0
|
|
552
|
-
`,
|
|
551
|
+
Defaults to \`0\`.`,
|
|
553
552
|
type: 'integer',
|
|
554
553
|
},
|
|
555
554
|
checkConstructors: {
|
|
556
555
|
default: true,
|
|
557
556
|
description: `A value indicating whether \`constructor\`s should be checked. Defaults to
|
|
558
|
-
\`true
|
|
559
|
-
`,
|
|
557
|
+
\`true\`.`,
|
|
560
558
|
type: 'boolean',
|
|
561
559
|
},
|
|
562
560
|
checkDestructured: {
|
|
@@ -574,8 +572,7 @@ the \`{a, b}\` object parameter).
|
|
|
574
572
|
If \`checkDestructuredRoots\` is \`false\`, \`checkDestructured\` will also be
|
|
575
573
|
implied to be \`false\` (i.e., the inside of the roots will not be checked
|
|
576
574
|
either, e.g., it will also not complain if \`a\` or \`b\` do not have their own
|
|
577
|
-
documentation). Defaults to \`true
|
|
578
|
-
`,
|
|
575
|
+
documentation). Defaults to \`true\`.`,
|
|
579
576
|
type: 'boolean',
|
|
580
577
|
},
|
|
581
578
|
checkGetters: {
|
|
@@ -634,8 +631,7 @@ Nor will this:
|
|
|
634
631
|
*/
|
|
635
632
|
function quux ({num, ...extra}) {
|
|
636
633
|
}
|
|
637
|
-
|
|
638
|
-
`,
|
|
634
|
+
\`\`\``,
|
|
639
635
|
type: 'boolean',
|
|
640
636
|
},
|
|
641
637
|
checkSetters: {
|
|
@@ -689,8 +685,7 @@ Overrides the default contexts (\`ArrowFunctionExpression\`, \`FunctionDeclarati
|
|
|
689
685
|
which are checked.
|
|
690
686
|
|
|
691
687
|
See the ["AST and Selectors"](../#advanced-ast-and-selectors)
|
|
692
|
-
section of our Advanced docs for more on the expected format
|
|
693
|
-
`,
|
|
688
|
+
section of our Advanced docs for more on the expected format.`,
|
|
694
689
|
items: {
|
|
695
690
|
anyOf: [
|
|
696
691
|
{
|
|
@@ -749,8 +744,7 @@ function baar ([a, ...extra]) {
|
|
|
749
744
|
Note that the type \`any\` is included since we don't know of any specific
|
|
750
745
|
type to use.
|
|
751
746
|
|
|
752
|
-
Defaults to \`true
|
|
753
|
-
`,
|
|
747
|
+
Defaults to \`true\`.`,
|
|
754
748
|
type: 'boolean',
|
|
755
749
|
},
|
|
756
750
|
enableRootFixer: {
|
|
@@ -38,8 +38,7 @@ expression, i.e., \`@callback\` or \`@function\` (or its aliases \`@func\` or
|
|
|
38
38
|
\`@method\`) (including those associated with an \`@interface\`).
|
|
39
39
|
|
|
40
40
|
See the ["AST and Selectors"](../#advanced-ast-and-selectors)
|
|
41
|
-
section of our Advanced docs for more on the expected format
|
|
42
|
-
`,
|
|
41
|
+
section of our Advanced docs for more on the expected format.`,
|
|
43
42
|
items: {
|
|
44
43
|
anyOf: [
|
|
45
44
|
{
|
|
@@ -254,8 +254,7 @@ otherwise noted):
|
|
|
254
254
|
- \`ancestorsOnly\` - Optimization to only check node ancestors to check if node is exported
|
|
255
255
|
- \`esm\` - ESM exports are checked for \`@returns\` JSDoc comments (Defaults to \`true\`)
|
|
256
256
|
- \`cjs\` - CommonJS exports are checked for \`@returns\` JSDoc comments (Defaults to \`true\`)
|
|
257
|
-
- \`window\` - Window global exports are checked for \`@returns\` JSDoc comments
|
|
258
|
-
`,
|
|
257
|
+
- \`window\` - Window global exports are checked for \`@returns\` JSDoc comments`,
|
|
259
258
|
oneOf: [
|
|
260
259
|
{
|
|
261
260
|
default: false,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import iterateJsdoc from '../iterateJsdoc.js';
|
|
2
|
+
import {
|
|
3
|
+
strictNativeTypes,
|
|
4
|
+
} from '../jsdocUtils.js';
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* @param {import('../iterateJsdoc.js').Utils} utils
|
|
@@ -43,6 +46,7 @@ export default iterateJsdoc(({
|
|
|
43
46
|
const {
|
|
44
47
|
exemptAsync = true,
|
|
45
48
|
exemptGenerators = settings.mode === 'typescript',
|
|
49
|
+
noNativeTypes = true,
|
|
46
50
|
reportMissingReturnForUndefinedTypes = false,
|
|
47
51
|
} = context.options[0] || {};
|
|
48
52
|
|
|
@@ -50,7 +54,8 @@ export default iterateJsdoc(({
|
|
|
50
54
|
return;
|
|
51
55
|
}
|
|
52
56
|
|
|
53
|
-
|
|
57
|
+
const isAsync = utils.isAsync();
|
|
58
|
+
if (exemptAsync && isAsync) {
|
|
54
59
|
return;
|
|
55
60
|
}
|
|
56
61
|
|
|
@@ -92,6 +97,11 @@ export default iterateJsdoc(({
|
|
|
92
97
|
return;
|
|
93
98
|
}
|
|
94
99
|
|
|
100
|
+
if (noNativeTypes && isAsync && strictNativeTypes.includes(type)) {
|
|
101
|
+
report('Function is async or otherwise returns a Promise but the return type is a native type.');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
95
105
|
// In case a return value is declared in JSDoc, we also expect one in the code.
|
|
96
106
|
if (
|
|
97
107
|
!returnNever &&
|
|
@@ -147,6 +157,11 @@ one might be more likely to take advantage of \`@yields\`). Set it to \`false\`
|
|
|
147
157
|
if you wish for a missing \`return\` to be flagged regardless.`,
|
|
148
158
|
type: 'boolean',
|
|
149
159
|
},
|
|
160
|
+
noNativeTypes: {
|
|
161
|
+
description: `Whether to check that async functions do not
|
|
162
|
+
indicate they return non-native types. Defaults to \`true\`.`,
|
|
163
|
+
type: 'boolean',
|
|
164
|
+
},
|
|
150
165
|
reportMissingReturnForUndefinedTypes: {
|
|
151
166
|
default: false,
|
|
152
167
|
description: `If \`true\` and no return or
|