eslint-plugin-jsdoc 50.6.17 → 50.7.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.
- package/dist/alignTransform.cjs +10 -10
- package/dist/alignTransform.cjs.map +1 -1
- package/dist/exportParser.cjs +141 -135
- package/dist/exportParser.cjs.map +1 -1
- package/dist/generateRule.cjs +10 -12
- package/dist/generateRule.cjs.map +1 -1
- package/dist/getDefaultTagStructureForMode.cjs +73 -73
- package/dist/getDefaultTagStructureForMode.cjs.map +1 -1
- package/dist/getJsdocProcessorPlugin.cjs +121 -110
- package/dist/getJsdocProcessorPlugin.cjs.map +1 -1
- package/dist/index.cjs +17 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/iterateJsdoc.cjs +87 -66
- package/dist/iterateJsdoc.cjs.map +1 -1
- package/dist/jsdocUtils.cjs +144 -142
- package/dist/jsdocUtils.cjs.map +1 -1
- package/dist/rules/checkAlignment.cjs +2 -2
- package/dist/rules/checkAlignment.cjs.map +1 -1
- package/dist/rules/checkExamples.cjs +22 -28
- package/dist/rules/checkExamples.cjs.map +1 -1
- package/dist/rules/checkIndentation.cjs +2 -2
- package/dist/rules/checkIndentation.cjs.map +1 -1
- package/dist/rules/checkLineAlignment.cjs +14 -14
- package/dist/rules/checkLineAlignment.cjs.map +1 -1
- package/dist/rules/checkParamNames.cjs +21 -15
- package/dist/rules/checkParamNames.cjs.map +1 -1
- package/dist/rules/checkPropertyNames.cjs +2 -2
- package/dist/rules/checkPropertyNames.cjs.map +1 -1
- package/dist/rules/checkTagNames.cjs +11 -11
- package/dist/rules/checkTagNames.cjs.map +1 -1
- package/dist/rules/checkTemplateNames.cjs +21 -22
- package/dist/rules/checkTemplateNames.cjs.map +1 -1
- package/dist/rules/checkTypes.cjs +10 -10
- package/dist/rules/checkTypes.cjs.map +1 -1
- package/dist/rules/checkValues.cjs +11 -14
- package/dist/rules/checkValues.cjs.map +1 -1
- package/dist/rules/convertToJsdocComments.cjs +26 -27
- package/dist/rules/convertToJsdocComments.cjs.map +1 -1
- package/dist/rules/emptyTags.cjs +6 -6
- package/dist/rules/emptyTags.cjs.map +1 -1
- package/dist/rules/importsAsDependencies.cjs.map +1 -1
- package/dist/rules/informativeDocs.cjs +12 -12
- package/dist/rules/informativeDocs.cjs.map +1 -1
- package/dist/rules/linesBeforeBlock.cjs +12 -12
- package/dist/rules/linesBeforeBlock.cjs.map +1 -1
- package/dist/rules/matchDescription.cjs +1 -1
- package/dist/rules/matchDescription.cjs.map +1 -1
- package/dist/rules/matchName.cjs +4 -4
- package/dist/rules/matchName.cjs.map +1 -1
- package/dist/rules/multilineBlocks.cjs +10 -10
- package/dist/rules/multilineBlocks.cjs.map +1 -1
- package/dist/rules/noBadBlocks.cjs +3 -3
- package/dist/rules/noBadBlocks.cjs.map +1 -1
- package/dist/rules/noMultiAsterisks.cjs +6 -6
- package/dist/rules/noMultiAsterisks.cjs.map +1 -1
- package/dist/rules/noRestrictedSyntax.cjs +2 -2
- package/dist/rules/noRestrictedSyntax.cjs.map +1 -1
- package/dist/rules/noTypes.cjs.map +1 -1
- package/dist/rules/noUndefinedTypes.cjs +17 -20
- package/dist/rules/noUndefinedTypes.cjs.map +1 -1
- package/dist/rules/requireAsteriskPrefix.cjs +4 -4
- package/dist/rules/requireAsteriskPrefix.cjs.map +1 -1
- package/dist/rules/requireDescription.cjs +2 -2
- package/dist/rules/requireDescription.cjs.map +1 -1
- package/dist/rules/requireDescriptionCompleteSentence.cjs +8 -8
- package/dist/rules/requireDescriptionCompleteSentence.cjs.map +1 -1
- package/dist/rules/requireFileOverview.cjs +6 -6
- package/dist/rules/requireFileOverview.cjs.map +1 -1
- package/dist/rules/requireHyphenBeforeParamDescription.cjs +1 -4
- package/dist/rules/requireHyphenBeforeParamDescription.cjs.map +1 -1
- package/dist/rules/requireJsdoc.cjs +19 -19
- package/dist/rules/requireJsdoc.cjs.map +1 -1
- package/dist/rules/requireParam.cjs +12 -12
- package/dist/rules/requireParam.cjs.map +1 -1
- package/dist/rules/requireProperty.cjs +1 -1
- package/dist/rules/requireProperty.cjs.map +1 -1
- package/dist/rules/requireReturns.cjs +3 -3
- package/dist/rules/requireReturns.cjs.map +1 -1
- package/dist/rules/requireReturnsCheck.cjs +1 -1
- package/dist/rules/requireReturnsCheck.cjs.map +1 -1
- package/dist/rules/requireReturnsDescription.cjs +1 -1
- package/dist/rules/requireReturnsDescription.cjs.map +1 -1
- package/dist/rules/requireTemplate.cjs +16 -15
- package/dist/rules/requireTemplate.cjs.map +1 -1
- package/dist/rules/requireYields.cjs +4 -4
- package/dist/rules/requireYields.cjs.map +1 -1
- package/dist/rules/requireYieldsCheck.cjs +6 -6
- package/dist/rules/requireYieldsCheck.cjs.map +1 -1
- package/dist/rules/sortTags.cjs +13 -13
- package/dist/rules/sortTags.cjs.map +1 -1
- package/dist/rules/tagLines.cjs +11 -11
- package/dist/rules/tagLines.cjs.map +1 -1
- package/dist/rules/textEscaping.cjs +2 -2
- package/dist/rules/textEscaping.cjs.map +1 -1
- package/dist/rules/validTypes.cjs +15 -15
- package/dist/rules/validTypes.cjs.map +1 -1
- package/dist/tagNames.cjs +1 -1
- package/dist/tagNames.cjs.map +1 -1
- package/dist/utils/hasReturnValue.cjs +176 -176
- package/dist/utils/hasReturnValue.cjs.map +1 -1
- package/eslint.config.js +36 -32
- package/package.json +29 -29
- package/pnpm-workspace.yaml +1 -0
- package/src/alignTransform.js +15 -15
- package/src/exportParser.js +386 -373
- package/src/getDefaultTagStructureForMode.js +45 -45
- package/src/getJsdocProcessorPlugin.js +175 -128
- package/src/index.js +66 -37
- package/src/iterateJsdoc.js +61 -28
- package/src/jsdocUtils.js +354 -338
- package/src/rules/checkAlignment.js +2 -2
- package/src/rules/checkExamples.js +16 -20
- package/src/rules/checkIndentation.js +2 -2
- package/src/rules/checkLineAlignment.js +10 -10
- package/src/rules/checkParamNames.js +22 -14
- package/src/rules/checkPropertyNames.js +1 -1
- package/src/rules/checkTagNames.js +7 -7
- package/src/rules/checkTemplateNames.js +52 -38
- package/src/rules/checkTypes.js +7 -7
- package/src/rules/checkValues.js +16 -17
- package/src/rules/convertToJsdocComments.js +47 -37
- package/src/rules/emptyTags.js +14 -7
- package/src/rules/importsAsDependencies.js +3 -1
- package/src/rules/informativeDocs.js +58 -58
- package/src/rules/linesBeforeBlock.js +25 -17
- package/src/rules/matchDescription.js +1 -1
- package/src/rules/matchName.js +2 -2
- package/src/rules/multilineBlocks.js +10 -10
- package/src/rules/noBadBlocks.js +3 -3
- package/src/rules/noMultiAsterisks.js +4 -4
- package/src/rules/noRestrictedSyntax.js +1 -1
- package/src/rules/noTypes.js +1 -1
- package/src/rules/noUndefinedTypes.js +29 -23
- package/src/rules/requireAsteriskPrefix.js +3 -3
- package/src/rules/requireDescription.js +1 -1
- package/src/rules/requireDescriptionCompleteSentence.js +6 -6
- package/src/rules/requireFileOverview.js +3 -3
- package/src/rules/requireHyphenBeforeParamDescription.js +2 -5
- package/src/rules/requireJsdoc.js +14 -14
- package/src/rules/requireParam.js +9 -9
- package/src/rules/requireProperty.js +1 -1
- package/src/rules/requireReturns.js +1 -1
- package/src/rules/requireReturnsCheck.js +1 -1
- package/src/rules/requireReturnsDescription.js +1 -1
- package/src/rules/requireTemplate.js +59 -38
- package/src/rules/requireYields.js +3 -3
- package/src/rules/requireYieldsCheck.js +1 -1
- package/src/rules/sortTags.js +7 -7
- package/src/rules/tagLines.js +8 -8
- package/src/rules/textEscaping.js +2 -0
- package/src/rules/validTypes.js +29 -29
- package/src/tagNames.js +2 -2
- package/src/utils/hasReturnValue.js +298 -283
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import iterateJsdoc from '../iterateJsdoc.js';
|
|
2
1
|
import {
|
|
3
2
|
getSettings,
|
|
4
3
|
} from '../iterateJsdoc.js';
|
|
5
4
|
import {
|
|
6
|
-
getIndent,
|
|
7
|
-
getContextObject,
|
|
8
5
|
enforcedContexts,
|
|
6
|
+
getContextObject,
|
|
7
|
+
getIndent,
|
|
9
8
|
} from '../jsdocUtils.js';
|
|
10
9
|
import {
|
|
11
|
-
getNonJsdocComment,
|
|
12
10
|
getDecorator,
|
|
13
|
-
getReducedASTNode,
|
|
14
11
|
getFollowingComment,
|
|
12
|
+
getNonJsdocComment,
|
|
13
|
+
getReducedASTNode,
|
|
15
14
|
} from '@es-joy/jsdoccomment';
|
|
16
15
|
|
|
17
16
|
/** @type {import('eslint').Rule.RuleModule} */
|
|
@@ -44,15 +43,17 @@ export default {
|
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
const {
|
|
46
|
+
allowedPrefixes = [
|
|
47
|
+
'@ts-', 'istanbul ', 'c8 ', 'v8 ', 'eslint', 'prettier-',
|
|
48
|
+
],
|
|
47
49
|
contexts = settings.contexts || [],
|
|
48
50
|
contextsAfter = /** @type {string[]} */ ([]),
|
|
49
51
|
contextsBeforeAndAfter = [
|
|
50
|
-
'VariableDeclarator', 'TSPropertySignature', 'PropertyDefinition'
|
|
52
|
+
'VariableDeclarator', 'TSPropertySignature', 'PropertyDefinition',
|
|
51
53
|
],
|
|
52
54
|
enableFixer = true,
|
|
53
55
|
enforceJsdocLineStyle = 'multi',
|
|
54
56
|
lineOrBlockStyle = 'both',
|
|
55
|
-
allowedPrefixes = ['@ts-', 'istanbul ', 'c8 ', 'v8 ', 'eslint', 'prettier-']
|
|
56
57
|
} = context.options[0] ?? {};
|
|
57
58
|
|
|
58
59
|
let reportingNonJsdoc = false;
|
|
@@ -75,7 +76,7 @@ export default {
|
|
|
75
76
|
column: 0,
|
|
76
77
|
/* c8 ignore next 2 -- Guard */
|
|
77
78
|
// @ts-expect-error Ok
|
|
78
|
-
line: (comment.loc?.start?.line ?? 1)
|
|
79
|
+
line: (comment.loc?.start?.line ?? 1),
|
|
79
80
|
},
|
|
80
81
|
};
|
|
81
82
|
|
|
@@ -110,7 +111,7 @@ export default {
|
|
|
110
111
|
|
|
111
112
|
const decorator = getDecorator(
|
|
112
113
|
/** @type {import('eslint').Rule.Node} */
|
|
113
|
-
(baseNode)
|
|
114
|
+
(baseNode),
|
|
114
115
|
);
|
|
115
116
|
if (decorator) {
|
|
116
117
|
baseNode = /** @type {import('@typescript-eslint/types').TSESTree.Decorator} */ (
|
|
@@ -169,6 +170,7 @@ export default {
|
|
|
169
170
|
if (lineOrBlockStyle === 'line') {
|
|
170
171
|
return;
|
|
171
172
|
}
|
|
173
|
+
|
|
172
174
|
report('blockCommentsJsdocStyle', comment, node, fixer);
|
|
173
175
|
return;
|
|
174
176
|
}
|
|
@@ -177,6 +179,7 @@ export default {
|
|
|
177
179
|
if (lineOrBlockStyle === 'block') {
|
|
178
180
|
return;
|
|
179
181
|
}
|
|
182
|
+
|
|
180
183
|
report('lineCommentsJsdocStyle', comment, node, fixer);
|
|
181
184
|
}
|
|
182
185
|
};
|
|
@@ -200,17 +203,18 @@ export default {
|
|
|
200
203
|
reportingNonJsdoc = true;
|
|
201
204
|
|
|
202
205
|
/** @type {AddComment} */
|
|
203
|
-
|
|
206
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping -- Avoid conflicts
|
|
207
|
+
const addComment = (inlineCommentBlock, commentToAdd, indent, lines, fixer) => {
|
|
204
208
|
const insertion = (
|
|
205
|
-
inlineCommentBlock || enforceJsdocLineStyle === 'single'
|
|
206
|
-
|
|
207
|
-
|
|
209
|
+
inlineCommentBlock || enforceJsdocLineStyle === 'single' ?
|
|
210
|
+
`/** ${commentToAdd.value.trim()} ` :
|
|
211
|
+
`/**\n${indent}*${commentToAdd.value.trimEnd()}\n${indent}`
|
|
208
212
|
) +
|
|
209
213
|
`*/${'\n'.repeat((lines || 1) - 1)}`;
|
|
210
214
|
|
|
211
215
|
return fixer.replaceText(
|
|
212
216
|
/** @type {import('eslint').AST.Token} */
|
|
213
|
-
(
|
|
217
|
+
(commentToAdd),
|
|
214
218
|
insertion,
|
|
215
219
|
);
|
|
216
220
|
};
|
|
@@ -237,21 +241,23 @@ export default {
|
|
|
237
241
|
}
|
|
238
242
|
|
|
239
243
|
/** @type {AddComment} */
|
|
240
|
-
const addComment = (inlineCommentBlock,
|
|
244
|
+
const addComment = (inlineCommentBlock, commentToAdd, indent, lines, fixer) => {
|
|
241
245
|
const insertion = (
|
|
242
|
-
inlineCommentBlock || enforceJsdocLineStyle === 'single'
|
|
243
|
-
|
|
244
|
-
|
|
246
|
+
inlineCommentBlock || enforceJsdocLineStyle === 'single' ?
|
|
247
|
+
`/** ${commentToAdd.value.trim()} ` :
|
|
248
|
+
`/**\n${indent}*${commentToAdd.value.trimEnd()}\n${indent}`
|
|
245
249
|
) +
|
|
246
250
|
`*/${'\n'.repeat((lines || 1) - 1)}${lines ? `\n${indent.slice(1)}` : ' '}`;
|
|
247
251
|
|
|
248
|
-
return [
|
|
252
|
+
return [
|
|
253
|
+
fixer.remove(
|
|
249
254
|
/** @type {import('eslint').AST.Token} */
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
+
(commentToAdd),
|
|
256
|
+
), fixer.insertTextBefore(
|
|
257
|
+
node.type === 'VariableDeclarator' ? node.parent : node,
|
|
258
|
+
insertion,
|
|
259
|
+
),
|
|
260
|
+
];
|
|
255
261
|
};
|
|
256
262
|
|
|
257
263
|
reportings(comment, node, addComment, ctxts);
|
|
@@ -276,31 +282,31 @@ export default {
|
|
|
276
282
|
if (!reportingNonJsdoc) {
|
|
277
283
|
checkNonJsdocAfter(node, contextsBeforeAndAfter);
|
|
278
284
|
}
|
|
279
|
-
}
|
|
280
|
-
)
|
|
285
|
+
},
|
|
286
|
+
),
|
|
281
287
|
};
|
|
282
288
|
},
|
|
283
289
|
meta: {
|
|
290
|
+
docs: {
|
|
291
|
+
description: 'Converts non-JSDoc comments preceding or following nodes into JSDoc ones',
|
|
292
|
+
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/convert-to-jsdoc-comments.md#repos-sticky-header',
|
|
293
|
+
},
|
|
294
|
+
|
|
284
295
|
fixable: 'code',
|
|
285
296
|
|
|
286
297
|
messages: {
|
|
287
298
|
blockCommentsJsdocStyle: 'Block comments should be JSDoc-style.',
|
|
288
299
|
lineCommentsJsdocStyle: 'Line comments should be JSDoc-style.',
|
|
289
300
|
},
|
|
290
|
-
|
|
291
|
-
docs: {
|
|
292
|
-
description: 'Converts non-JSDoc comments preceding or following nodes into JSDoc ones',
|
|
293
|
-
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/convert-to-jsdoc-comments.md#repos-sticky-header',
|
|
294
|
-
},
|
|
295
301
|
schema: [
|
|
296
302
|
{
|
|
297
303
|
additionalProperties: false,
|
|
298
304
|
properties: {
|
|
299
305
|
allowedPrefixes: {
|
|
300
|
-
type: 'array',
|
|
301
306
|
items: {
|
|
302
|
-
type: 'string'
|
|
303
|
-
}
|
|
307
|
+
type: 'string',
|
|
308
|
+
},
|
|
309
|
+
type: 'array',
|
|
304
310
|
},
|
|
305
311
|
contexts: {
|
|
306
312
|
items: {
|
|
@@ -369,15 +375,19 @@ export default {
|
|
|
369
375
|
type: 'array',
|
|
370
376
|
},
|
|
371
377
|
enableFixer: {
|
|
372
|
-
type: 'boolean'
|
|
378
|
+
type: 'boolean',
|
|
373
379
|
},
|
|
374
380
|
enforceJsdocLineStyle: {
|
|
381
|
+
enum: [
|
|
382
|
+
'multi', 'single',
|
|
383
|
+
],
|
|
375
384
|
type: 'string',
|
|
376
|
-
enum: ['multi', 'single']
|
|
377
385
|
},
|
|
378
386
|
lineOrBlockStyle: {
|
|
387
|
+
enum: [
|
|
388
|
+
'block', 'line', 'both',
|
|
389
|
+
],
|
|
379
390
|
type: 'string',
|
|
380
|
-
enum: ['block', 'line', 'both']
|
|
381
391
|
},
|
|
382
392
|
},
|
|
383
393
|
type: 'object',
|
package/src/rules/emptyTags.js
CHANGED
|
@@ -2,22 +2,26 @@ import iterateJsdoc from '../iterateJsdoc.js';
|
|
|
2
2
|
|
|
3
3
|
const defaultEmptyTags = new Set([
|
|
4
4
|
'abstract', 'async', 'generator', 'global', 'hideconstructor',
|
|
5
|
-
'ignore', 'inner', 'instance', 'override', 'readonly',
|
|
6
5
|
|
|
7
6
|
// jsdoc doesn't use this form in its docs, but allow for compatibility with
|
|
8
7
|
// TypeScript which allows and Closure which requires
|
|
9
|
-
'
|
|
8
|
+
'ignore',
|
|
10
9
|
|
|
11
10
|
// jsdoc doesn't use but allow for TypeScript
|
|
11
|
+
'inheritDoc', 'inner', 'instance',
|
|
12
12
|
'internal',
|
|
13
|
+
|
|
13
14
|
'overload',
|
|
15
|
+
|
|
16
|
+
'override',
|
|
17
|
+
'readonly',
|
|
14
18
|
]);
|
|
15
19
|
|
|
16
20
|
const emptyIfNotClosure = new Set([
|
|
17
|
-
'package', 'private', 'protected', 'public', 'static',
|
|
18
|
-
|
|
19
21
|
// Closure doesn't allow with this casing
|
|
20
|
-
'inheritdoc',
|
|
22
|
+
'inheritdoc', 'package', 'private', 'protected', 'public',
|
|
23
|
+
|
|
24
|
+
'static',
|
|
21
25
|
]);
|
|
22
26
|
|
|
23
27
|
const emptyIfClosure = new Set([
|
|
@@ -25,8 +29,8 @@ const emptyIfClosure = new Set([
|
|
|
25
29
|
]);
|
|
26
30
|
|
|
27
31
|
export default iterateJsdoc(({
|
|
28
|
-
settings,
|
|
29
32
|
jsdoc,
|
|
33
|
+
settings,
|
|
30
34
|
utils,
|
|
31
35
|
}) => {
|
|
32
36
|
const emptyTags = utils.filterTags(({
|
|
@@ -42,7 +46,10 @@ export default iterateJsdoc(({
|
|
|
42
46
|
settings.mode !== 'closure' && emptyIfNotClosure.has(tagName);
|
|
43
47
|
});
|
|
44
48
|
|
|
45
|
-
for (const [
|
|
49
|
+
for (const [
|
|
50
|
+
key,
|
|
51
|
+
tag,
|
|
52
|
+
] of emptyTags.entries()) {
|
|
46
53
|
const content = tag.name || tag.description || tag.type;
|
|
47
54
|
if (content.trim() && (
|
|
48
55
|
// Allow for JSDoc-block final asterisks
|
|
@@ -21,72 +21,72 @@ const defaultUselessWords = [
|
|
|
21
21
|
*/
|
|
22
22
|
const getNamesFromNode = (node) => {
|
|
23
23
|
switch (node?.type) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
case 'AccessorProperty':
|
|
25
|
+
case 'MethodDefinition':
|
|
26
|
+
case 'PropertyDefinition':
|
|
27
|
+
case 'TSAbstractAccessorProperty':
|
|
28
|
+
case 'TSAbstractMethodDefinition':
|
|
29
|
+
case 'TSAbstractPropertyDefinition':
|
|
30
|
+
return [
|
|
31
|
+
...getNamesFromNode(
|
|
32
32
|
/** @type {import('@typescript-eslint/types').TSESTree.Node} */ (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
node.parent
|
|
34
|
+
).parent,
|
|
35
|
+
),
|
|
36
|
+
...getNamesFromNode(
|
|
37
37
|
/** @type {import('@typescript-eslint/types').TSESTree.Node} */
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
(node.key),
|
|
39
|
+
),
|
|
40
|
+
];
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
case 'TSDeclareFunction':
|
|
55
|
-
case 'TSEnumDeclaration':
|
|
56
|
-
case 'TSEnumMember':
|
|
57
|
-
case 'TSInterfaceDeclaration':
|
|
58
|
-
case 'TSTypeAliasDeclaration':
|
|
59
|
-
return getNamesFromNode(
|
|
42
|
+
case 'ClassDeclaration':
|
|
43
|
+
case 'ClassExpression':
|
|
44
|
+
case 'FunctionDeclaration':
|
|
45
|
+
case 'FunctionExpression':
|
|
46
|
+
case 'TSDeclareFunction':
|
|
47
|
+
case 'TSEnumDeclaration':
|
|
48
|
+
case 'TSEnumMember':
|
|
49
|
+
case 'TSInterfaceDeclaration':
|
|
50
|
+
case 'TSMethodSignature':
|
|
51
|
+
case 'TSModuleDeclaration':
|
|
52
|
+
case 'TSTypeAliasDeclaration':
|
|
53
|
+
return getNamesFromNode(
|
|
60
54
|
/** @type {import('@typescript-eslint/types').TSESTree.ClassDeclaration} */
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
(node).id,
|
|
56
|
+
);
|
|
57
|
+
case 'ExportDefaultDeclaration':
|
|
58
|
+
case 'ExportNamedDeclaration':
|
|
59
|
+
return getNamesFromNode(
|
|
60
|
+
/** @type {import('@typescript-eslint/types').TSESTree.ExportNamedDeclaration} */
|
|
61
|
+
(node).declaration,
|
|
62
|
+
);
|
|
63
|
+
case 'Identifier':
|
|
64
|
+
return [
|
|
65
|
+
node.name,
|
|
66
|
+
];
|
|
67
|
+
case 'Property':
|
|
68
|
+
return getNamesFromNode(
|
|
69
69
|
/** @type {import('@typescript-eslint/types').TSESTree.Node} */
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
(node.key),
|
|
71
|
+
);
|
|
72
|
+
case 'VariableDeclaration':
|
|
73
|
+
return getNamesFromNode(
|
|
74
74
|
/** @type {import('@typescript-eslint/types').TSESTree.Node} */
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
(node.declarations[0]),
|
|
76
|
+
);
|
|
77
|
+
case 'VariableDeclarator':
|
|
78
|
+
return [
|
|
79
|
+
...getNamesFromNode(
|
|
80
80
|
/** @type {import('@typescript-eslint/types').TSESTree.Node} */
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
(node.id),
|
|
82
|
+
),
|
|
83
|
+
...getNamesFromNode(
|
|
84
84
|
/** @type {import('@typescript-eslint/types').TSESTree.Node} */
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
(node.init),
|
|
86
|
+
),
|
|
87
|
+
].filter(Boolean);
|
|
88
|
+
default:
|
|
89
|
+
return [];
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
92
|
/* eslint-enable complexity -- Temporary */
|
|
@@ -5,27 +5,33 @@ import iterateJsdoc from '../iterateJsdoc.js';
|
|
|
5
5
|
* `[` starts an array, `{` starts an object or block, `(` starts a grouping, and `=` starts a
|
|
6
6
|
* declaration (like a variable or a type alias).
|
|
7
7
|
*/
|
|
8
|
-
const startPunctuators = new Set([
|
|
8
|
+
const startPunctuators = new Set([
|
|
9
|
+
'(', '=', '[', '{',
|
|
10
|
+
]);
|
|
9
11
|
|
|
10
12
|
export default iterateJsdoc(({
|
|
11
13
|
context,
|
|
12
14
|
jsdocNode,
|
|
13
|
-
sourceCode,
|
|
14
15
|
report,
|
|
16
|
+
sourceCode,
|
|
15
17
|
utils,
|
|
16
18
|
}) => {
|
|
17
19
|
const {
|
|
18
20
|
checkBlockStarts,
|
|
19
|
-
|
|
21
|
+
excludedTags = [
|
|
22
|
+
'type',
|
|
23
|
+
],
|
|
20
24
|
ignoreSameLine = true,
|
|
21
|
-
|
|
25
|
+
lines = 1,
|
|
22
26
|
} = context.options[0] || {};
|
|
23
27
|
|
|
24
28
|
if (utils.hasATag(excludedTags)) {
|
|
25
29
|
return;
|
|
26
30
|
}
|
|
27
31
|
|
|
28
|
-
const tokensBefore = sourceCode.getTokensBefore(jsdocNode, {
|
|
32
|
+
const tokensBefore = sourceCode.getTokensBefore(jsdocNode, {
|
|
33
|
+
includeComments: true,
|
|
34
|
+
});
|
|
29
35
|
const tokenBefore = tokensBefore.at(-1);
|
|
30
36
|
if (
|
|
31
37
|
!tokenBefore || (
|
|
@@ -38,9 +44,9 @@ export default iterateJsdoc(({
|
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
if (tokenBefore.loc?.end?.line + lines >=
|
|
41
|
-
|
|
47
|
+
/** @type {number} */
|
|
42
48
|
(jsdocNode.loc?.start?.line)
|
|
43
|
-
|
|
49
|
+
) {
|
|
44
50
|
const startLine = jsdocNode.loc?.start?.line;
|
|
45
51
|
const sameLine = tokenBefore.loc?.end?.line === startLine;
|
|
46
52
|
|
|
@@ -53,11 +59,11 @@ export default iterateJsdoc(({
|
|
|
53
59
|
let indent = '';
|
|
54
60
|
if (sameLine) {
|
|
55
61
|
const spaceDiff = /** @type {number} */ (jsdocNode.loc?.start?.column) -
|
|
56
|
-
|
|
62
|
+
/** @type {number} */ (tokenBefore.loc?.end?.column);
|
|
57
63
|
// @ts-expect-error Should be a comment
|
|
58
64
|
indent = /** @type {import('estree').Comment} */ (
|
|
59
65
|
jsdocNode
|
|
60
|
-
).value.match(/^\*\n([
|
|
66
|
+
).value.match(/^\*\n([\t ]*) \*/u)?.[1]?.slice(spaceDiff);
|
|
61
67
|
if (!indent) {
|
|
62
68
|
/** @type {import('eslint').AST.Token|import('estree').Comment|undefined} */
|
|
63
69
|
let tokenPrior = tokenBefore;
|
|
@@ -66,9 +72,10 @@ export default iterateJsdoc(({
|
|
|
66
72
|
startColumn = tokenPrior.loc?.start?.column;
|
|
67
73
|
tokenPrior = tokensBefore.pop();
|
|
68
74
|
}
|
|
75
|
+
|
|
69
76
|
indent = ' '.repeat(
|
|
70
77
|
/* c8 ignore next */
|
|
71
|
-
/** @type {number} */ (startColumn ? startColumn - 1 : 0)
|
|
78
|
+
/** @type {number} */ (startColumn ? startColumn - 1 : 0),
|
|
72
79
|
);
|
|
73
80
|
}
|
|
74
81
|
}
|
|
@@ -77,19 +84,20 @@ export default iterateJsdoc(({
|
|
|
77
84
|
/** @type {import('eslint').AST.Token} */
|
|
78
85
|
(tokenBefore),
|
|
79
86
|
'\n'.repeat(lines) +
|
|
80
|
-
(sameLine ? '\n' + indent : '')
|
|
87
|
+
(sameLine ? '\n' + indent : ''),
|
|
81
88
|
);
|
|
82
89
|
};
|
|
90
|
+
|
|
83
91
|
report(`Required ${lines} line(s) before JSDoc block`, fix);
|
|
84
92
|
}
|
|
85
93
|
}, {
|
|
86
94
|
iterateAllJsdocs: true,
|
|
87
95
|
meta: {
|
|
88
|
-
fixable: 'code',
|
|
89
96
|
docs: {
|
|
90
97
|
description: 'Enforces minimum number of newlines before JSDoc comment blocks',
|
|
91
98
|
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/lines-before-block.md#repos-sticky-header',
|
|
92
99
|
},
|
|
100
|
+
fixable: 'code',
|
|
93
101
|
schema: [
|
|
94
102
|
{
|
|
95
103
|
additionalProperties: false,
|
|
@@ -98,17 +106,17 @@ export default iterateJsdoc(({
|
|
|
98
106
|
type: 'boolean',
|
|
99
107
|
},
|
|
100
108
|
excludedTags: {
|
|
101
|
-
type: 'array',
|
|
102
109
|
items: {
|
|
103
|
-
type: 'string'
|
|
104
|
-
}
|
|
110
|
+
type: 'string',
|
|
111
|
+
},
|
|
112
|
+
type: 'array',
|
|
105
113
|
},
|
|
106
114
|
ignoreSameLine: {
|
|
107
115
|
type: 'boolean',
|
|
108
116
|
},
|
|
109
117
|
lines: {
|
|
110
|
-
type: 'integer'
|
|
111
|
-
}
|
|
118
|
+
type: 'integer',
|
|
119
|
+
},
|
|
112
120
|
},
|
|
113
121
|
type: 'object',
|
|
114
122
|
},
|
package/src/rules/matchName.js
CHANGED
|
@@ -7,17 +7,17 @@ export default iterateJsdoc(({
|
|
|
7
7
|
}) => {
|
|
8
8
|
const {
|
|
9
9
|
allowMultipleTags = true,
|
|
10
|
+
minimumLengthForMultiline = Number.POSITIVE_INFINITY,
|
|
11
|
+
multilineTags = [
|
|
12
|
+
'*',
|
|
13
|
+
],
|
|
10
14
|
noFinalLineText = true,
|
|
11
|
-
|
|
15
|
+
noMultilineBlocks = false,
|
|
12
16
|
noSingleLineBlocks = false,
|
|
17
|
+
noZeroLineText = true,
|
|
13
18
|
singleLineTags = [
|
|
14
19
|
'lends', 'type',
|
|
15
20
|
],
|
|
16
|
-
noMultilineBlocks = false,
|
|
17
|
-
minimumLengthForMultiline = Number.POSITIVE_INFINITY,
|
|
18
|
-
multilineTags = [
|
|
19
|
-
'*',
|
|
20
|
-
],
|
|
21
21
|
} = context.options[0] || {};
|
|
22
22
|
|
|
23
23
|
const {
|
|
@@ -209,13 +209,13 @@ export default iterateJsdoc(({
|
|
|
209
209
|
tokens: jsdoc.source.reduce((obj, {
|
|
210
210
|
tokens: {
|
|
211
211
|
description: desc,
|
|
212
|
-
tag: tg,
|
|
213
|
-
type: typ,
|
|
214
|
-
name: nme,
|
|
215
212
|
lineEnd,
|
|
216
|
-
|
|
213
|
+
name: nme,
|
|
217
214
|
postName,
|
|
218
215
|
postTag,
|
|
216
|
+
postType,
|
|
217
|
+
tag: tg,
|
|
218
|
+
type: typ,
|
|
219
219
|
},
|
|
220
220
|
}) => {
|
|
221
221
|
if (typ) {
|
package/src/rules/noBadBlocks.js
CHANGED
|
@@ -9,10 +9,10 @@ const commentRegexp = /^\/\*(?!\*)/u;
|
|
|
9
9
|
const extraAsteriskCommentRegexp = /^\/\*{3,}/u;
|
|
10
10
|
|
|
11
11
|
export default iterateJsdoc(({
|
|
12
|
-
context,
|
|
13
|
-
sourceCode,
|
|
14
12
|
allComments,
|
|
13
|
+
context,
|
|
15
14
|
makeReport,
|
|
15
|
+
sourceCode,
|
|
16
16
|
}) => {
|
|
17
17
|
const [
|
|
18
18
|
{
|
|
@@ -34,7 +34,7 @@ export default iterateJsdoc(({
|
|
|
34
34
|
|
|
35
35
|
const initialText = commentText.replace(commentRegexp, '').trimStart();
|
|
36
36
|
if ([
|
|
37
|
-
'eslint'
|
|
37
|
+
'eslint',
|
|
38
38
|
].some((directive) => {
|
|
39
39
|
return initialText.startsWith(directive);
|
|
40
40
|
})) {
|
|
@@ -24,17 +24,17 @@ export default iterateJsdoc(({
|
|
|
24
24
|
|
|
25
25
|
// eslint-disable-next-line complexity -- Todo
|
|
26
26
|
jsdoc.source.some(({
|
|
27
|
-
tokens,
|
|
28
27
|
number,
|
|
28
|
+
tokens,
|
|
29
29
|
}) => {
|
|
30
30
|
const {
|
|
31
31
|
delimiter,
|
|
32
|
-
tag,
|
|
33
|
-
name,
|
|
34
|
-
type,
|
|
35
32
|
description,
|
|
36
33
|
end,
|
|
34
|
+
name,
|
|
37
35
|
postDelimiter,
|
|
36
|
+
tag,
|
|
37
|
+
type,
|
|
38
38
|
} = tokens;
|
|
39
39
|
|
|
40
40
|
if (
|
package/src/rules/noTypes.js
CHANGED