eslint-plugin-jsdoc 56.0.0 → 56.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.
- package/package.json +4 -4
- package/dist/cjs/WarnSettings.js +0 -30
- package/dist/cjs/alignTransform.js +0 -285
- package/dist/cjs/defaultTagOrder.js +0 -152
- package/dist/cjs/exportParser.js +0 -754
- package/dist/cjs/getDefaultTagStructureForMode.js +0 -840
- package/dist/cjs/getJsdocProcessorPlugin.cjs +0 -4
- package/dist/cjs/getJsdocProcessorPlugin.js +0 -553
- package/dist/cjs/index-cjs.js +0 -492
- package/dist/cjs/index.cjs.cjs +0 -6
- package/dist/cjs/iterateJsdoc.cjs +0 -38
- package/dist/cjs/iterateJsdoc.js +0 -1981
- package/dist/cjs/jsdocUtils.js +0 -1470
- package/dist/cjs/rules/checkAccess.js +0 -35
- package/dist/cjs/rules/checkAlignment.js +0 -63
- package/dist/cjs/rules/checkExamples.js +0 -486
- package/dist/cjs/rules/checkIndentation.js +0 -66
- package/dist/cjs/rules/checkLineAlignment.js +0 -297
- package/dist/cjs/rules/checkParamNames.js +0 -320
- package/dist/cjs/rules/checkPropertyNames.js +0 -105
- package/dist/cjs/rules/checkSyntax.js +0 -27
- package/dist/cjs/rules/checkTagNames.js +0 -252
- package/dist/cjs/rules/checkTemplateNames.js +0 -189
- package/dist/cjs/rules/checkTypes.js +0 -421
- package/dist/cjs/rules/checkValues.js +0 -163
- package/dist/cjs/rules/convertToJsdocComments.js +0 -313
- package/dist/cjs/rules/emptyTags.js +0 -79
- package/dist/cjs/rules/implementsOnClasses.js +0 -63
- package/dist/cjs/rules/importsAsDependencies.js +0 -105
- package/dist/cjs/rules/informativeDocs.js +0 -153
- package/dist/cjs/rules/linesBeforeBlock.js +0 -106
- package/dist/cjs/rules/matchDescription.js +0 -240
- package/dist/cjs/rules/matchName.js +0 -122
- package/dist/cjs/rules/multilineBlocks.js +0 -339
- package/dist/cjs/rules/noBadBlocks.js +0 -88
- package/dist/cjs/rules/noBlankBlockDescriptions.js +0 -56
- package/dist/cjs/rules/noBlankBlocks.js +0 -41
- package/dist/cjs/rules/noDefaults.js +0 -84
- package/dist/cjs/rules/noMissingSyntax.js +0 -164
- package/dist/cjs/rules/noMultiAsterisks.js +0 -83
- package/dist/cjs/rules/noRestrictedSyntax.js +0 -75
- package/dist/cjs/rules/noTypes.js +0 -88
- package/dist/cjs/rules/noUndefinedTypes.js +0 -451
- package/dist/cjs/rules/requireAsteriskPrefix.js +0 -144
- package/dist/cjs/rules/requireDescription.js +0 -136
- package/dist/cjs/rules/requireDescriptionCompleteSentence.js +0 -258
- package/dist/cjs/rules/requireExample.js +0 -103
- package/dist/cjs/rules/requireFileOverview.js +0 -117
- package/dist/cjs/rules/requireHyphenBeforeParamDescription.js +0 -144
- package/dist/cjs/rules/requireJsdoc.js +0 -629
- package/dist/cjs/rules/requireParam.js +0 -480
- package/dist/cjs/rules/requireParamDescription.js +0 -77
- package/dist/cjs/rules/requireParamName.js +0 -52
- package/dist/cjs/rules/requireParamType.js +0 -77
- package/dist/cjs/rules/requireProperty.js +0 -44
- package/dist/cjs/rules/requirePropertyDescription.js +0 -22
- package/dist/cjs/rules/requirePropertyName.js +0 -22
- package/dist/cjs/rules/requirePropertyType.js +0 -22
- package/dist/cjs/rules/requireReturns.js +0 -197
- package/dist/cjs/rules/requireReturnsCheck.js +0 -108
- package/dist/cjs/rules/requireReturnsDescription.js +0 -58
- package/dist/cjs/rules/requireReturnsType.js +0 -52
- package/dist/cjs/rules/requireTemplate.js +0 -173
- package/dist/cjs/rules/requireThrows.js +0 -101
- package/dist/cjs/rules/requireYields.js +0 -172
- package/dist/cjs/rules/requireYieldsCheck.js +0 -164
- package/dist/cjs/rules/sortTags.js +0 -392
- package/dist/cjs/rules/tagLines.js +0 -259
- package/dist/cjs/rules/textEscaping.js +0 -125
- package/dist/cjs/rules/typeFormatting.js +0 -328
- package/dist/cjs/rules/validTypes.js +0 -333
- package/dist/cjs/tagNames.js +0 -209
- package/dist/cjs/utils/hasReturnValue.js +0 -469
|
@@ -1,421 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const iterateJsdoc_js_1 = __importDefault(require("../iterateJsdoc.js"));
|
|
7
|
-
const jsdoccomment_1 = require("@es-joy/jsdoccomment");
|
|
8
|
-
const strictNativeTypes = [
|
|
9
|
-
'undefined',
|
|
10
|
-
'null',
|
|
11
|
-
'boolean',
|
|
12
|
-
'number',
|
|
13
|
-
'bigint',
|
|
14
|
-
'string',
|
|
15
|
-
'symbol',
|
|
16
|
-
'object',
|
|
17
|
-
'Array',
|
|
18
|
-
'Function',
|
|
19
|
-
'Date',
|
|
20
|
-
'RegExp',
|
|
21
|
-
];
|
|
22
|
-
/**
|
|
23
|
-
* Adjusts the parent type node `meta` for generic matches (or type node
|
|
24
|
-
* `type` for `JsdocTypeAny`) and sets the type node `value`.
|
|
25
|
-
* @param {string} type The actual type
|
|
26
|
-
* @param {string} preferred The preferred type
|
|
27
|
-
* @param {boolean} isGenericMatch
|
|
28
|
-
* @param {string} typeNodeName
|
|
29
|
-
* @param {import('jsdoc-type-pratt-parser').NonRootResult} node
|
|
30
|
-
* @param {import('jsdoc-type-pratt-parser').NonRootResult|undefined} parentNode
|
|
31
|
-
* @returns {void}
|
|
32
|
-
*/
|
|
33
|
-
const adjustNames = (type, preferred, isGenericMatch, typeNodeName, node, parentNode) => {
|
|
34
|
-
let ret = preferred;
|
|
35
|
-
if (isGenericMatch) {
|
|
36
|
-
const parentMeta = /** @type {import('jsdoc-type-pratt-parser').GenericResult} */ (parentNode).meta;
|
|
37
|
-
if (preferred === '[]') {
|
|
38
|
-
parentMeta.brackets = 'square';
|
|
39
|
-
parentMeta.dot = false;
|
|
40
|
-
ret = 'Array';
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
const dotBracketEnd = preferred.match(/\.(?:<>)?$/v);
|
|
44
|
-
if (dotBracketEnd) {
|
|
45
|
-
parentMeta.brackets = 'angle';
|
|
46
|
-
parentMeta.dot = true;
|
|
47
|
-
ret = preferred.slice(0, -dotBracketEnd[0].length);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
const bracketEnd = preferred.endsWith('<>');
|
|
51
|
-
if (bracketEnd) {
|
|
52
|
-
parentMeta.brackets = 'angle';
|
|
53
|
-
parentMeta.dot = false;
|
|
54
|
-
ret = preferred.slice(0, -2);
|
|
55
|
-
}
|
|
56
|
-
else if (parentMeta?.brackets === 'square' &&
|
|
57
|
-
(typeNodeName === '[]' || typeNodeName === 'Array')) {
|
|
58
|
-
parentMeta.brackets = 'angle';
|
|
59
|
-
parentMeta.dot = false;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else if (type === 'JsdocTypeAny') {
|
|
65
|
-
node.type = 'JsdocTypeName';
|
|
66
|
-
}
|
|
67
|
-
/** @type {import('jsdoc-type-pratt-parser').NameResult} */ (node).value = ret.replace(/(?:\.|<>|\.<>|\[\])$/v, '');
|
|
68
|
-
// For bare pseudo-types like `<>`
|
|
69
|
-
if (!ret) {
|
|
70
|
-
/** @type {import('jsdoc-type-pratt-parser').NameResult} */ (node).value = typeNodeName;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* @param {boolean} [upperCase]
|
|
75
|
-
* @returns {string}
|
|
76
|
-
*/
|
|
77
|
-
const getMessage = (upperCase) => {
|
|
78
|
-
return 'Use object shorthand or index signatures instead of ' +
|
|
79
|
-
'`' + (upperCase ? 'O' : 'o') + 'bject`, e.g., `{[key: string]: string}`';
|
|
80
|
-
};
|
|
81
|
-
exports.default = (0, iterateJsdoc_js_1.default)(({ context, jsdocNode, report, settings, sourceCode, utils, }) => {
|
|
82
|
-
const jsdocTagsWithPossibleType = utils.filterTags((tag) => {
|
|
83
|
-
return Boolean(utils.tagMightHaveTypePosition(tag.tag));
|
|
84
|
-
});
|
|
85
|
-
const
|
|
86
|
-
/**
|
|
87
|
-
* @type {{
|
|
88
|
-
* preferredTypes: import('../iterateJsdoc.js').PreferredTypes,
|
|
89
|
-
* structuredTags: import('../iterateJsdoc.js').StructuredTags,
|
|
90
|
-
* mode: import('../jsdocUtils.js').ParserMode
|
|
91
|
-
* }}
|
|
92
|
-
*/
|
|
93
|
-
{ mode, preferredTypes: preferredTypesOriginal, structuredTags, } = settings;
|
|
94
|
-
const injectObjectPreferredTypes = !('Object' in preferredTypesOriginal ||
|
|
95
|
-
'object' in preferredTypesOriginal ||
|
|
96
|
-
'object.<>' in preferredTypesOriginal ||
|
|
97
|
-
'Object.<>' in preferredTypesOriginal ||
|
|
98
|
-
'object<>' in preferredTypesOriginal);
|
|
99
|
-
/**
|
|
100
|
-
* @type {{
|
|
101
|
-
* message: string,
|
|
102
|
-
* replacement: false
|
|
103
|
-
* }}
|
|
104
|
-
*/
|
|
105
|
-
const info = {
|
|
106
|
-
message: getMessage(),
|
|
107
|
-
replacement: false,
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* @type {{
|
|
111
|
-
* message: string,
|
|
112
|
-
* replacement: false
|
|
113
|
-
* }}
|
|
114
|
-
*/
|
|
115
|
-
const infoUC = {
|
|
116
|
-
message: getMessage(true),
|
|
117
|
-
replacement: false,
|
|
118
|
-
};
|
|
119
|
-
/** @type {import('../iterateJsdoc.js').PreferredTypes} */
|
|
120
|
-
const typeToInject = mode === 'typescript' ?
|
|
121
|
-
{
|
|
122
|
-
Object: 'object',
|
|
123
|
-
'object.<>': info,
|
|
124
|
-
'Object.<>': infoUC,
|
|
125
|
-
'object<>': info,
|
|
126
|
-
'Object<>': infoUC,
|
|
127
|
-
} :
|
|
128
|
-
{
|
|
129
|
-
Object: 'object',
|
|
130
|
-
'object.<>': 'Object<>',
|
|
131
|
-
'Object.<>': 'Object<>',
|
|
132
|
-
'object<>': 'Object<>',
|
|
133
|
-
};
|
|
134
|
-
/** @type {import('../iterateJsdoc.js').PreferredTypes} */
|
|
135
|
-
const preferredTypes = {
|
|
136
|
-
...injectObjectPreferredTypes ?
|
|
137
|
-
typeToInject :
|
|
138
|
-
{},
|
|
139
|
-
...preferredTypesOriginal,
|
|
140
|
-
};
|
|
141
|
-
const
|
|
142
|
-
/**
|
|
143
|
-
* @type {{
|
|
144
|
-
* noDefaults: boolean,
|
|
145
|
-
* unifyParentAndChildTypeChecks: boolean,
|
|
146
|
-
* exemptTagContexts: ({
|
|
147
|
-
* tag: string,
|
|
148
|
-
* types: true|string[]
|
|
149
|
-
* })[]
|
|
150
|
-
* }}
|
|
151
|
-
*/ { exemptTagContexts = [], noDefaults, unifyParentAndChildTypeChecks, } = context.options[0] || {};
|
|
152
|
-
/**
|
|
153
|
-
* Gets information about the preferred type: whether there is a matching
|
|
154
|
-
* preferred type, what the type is, and whether it is a match to a generic.
|
|
155
|
-
* @param {string} _type Not currently in use
|
|
156
|
-
* @param {string} typeNodeName
|
|
157
|
-
* @param {import('jsdoc-type-pratt-parser').NonRootResult|undefined} parentNode
|
|
158
|
-
* @param {string|undefined} property
|
|
159
|
-
* @returns {[hasMatchingPreferredType: boolean, typeName: string, isGenericMatch: boolean]}
|
|
160
|
-
*/
|
|
161
|
-
const getPreferredTypeInfo = (_type, typeNodeName, parentNode, property) => {
|
|
162
|
-
let hasMatchingPreferredType = false;
|
|
163
|
-
let isGenericMatch = false;
|
|
164
|
-
let typeName = typeNodeName;
|
|
165
|
-
const isNameOfGeneric = parentNode !== undefined && parentNode.type === 'JsdocTypeGeneric' && property === 'left';
|
|
166
|
-
if (unifyParentAndChildTypeChecks || isNameOfGeneric) {
|
|
167
|
-
const brackets = /** @type {import('jsdoc-type-pratt-parser').GenericResult} */ (parentNode)?.meta?.brackets;
|
|
168
|
-
const dot = /** @type {import('jsdoc-type-pratt-parser').GenericResult} */ (parentNode)?.meta?.dot;
|
|
169
|
-
if (brackets === 'angle') {
|
|
170
|
-
const checkPostFixes = dot ? [
|
|
171
|
-
'.', '.<>',
|
|
172
|
-
] : [
|
|
173
|
-
'<>',
|
|
174
|
-
];
|
|
175
|
-
isGenericMatch = checkPostFixes.some((checkPostFix) => {
|
|
176
|
-
if (preferredTypes?.[typeNodeName + checkPostFix] !== undefined) {
|
|
177
|
-
typeName += checkPostFix;
|
|
178
|
-
return true;
|
|
179
|
-
}
|
|
180
|
-
return false;
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
if (!isGenericMatch && property &&
|
|
184
|
-
/** @type {import('jsdoc-type-pratt-parser').NonRootResult} */ (parentNode).type === 'JsdocTypeGeneric') {
|
|
185
|
-
const checkPostFixes = dot ? [
|
|
186
|
-
'.', '.<>',
|
|
187
|
-
] : [
|
|
188
|
-
brackets === 'angle' ? '<>' : '[]',
|
|
189
|
-
];
|
|
190
|
-
isGenericMatch = checkPostFixes.some((checkPostFix) => {
|
|
191
|
-
if (preferredTypes?.[checkPostFix] !== undefined) {
|
|
192
|
-
typeName = checkPostFix;
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
return false;
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
const directNameMatch = preferredTypes?.[typeNodeName] !== undefined &&
|
|
200
|
-
!Object.values(preferredTypes).includes(typeNodeName);
|
|
201
|
-
const unifiedSyntaxParentMatch = property && directNameMatch && unifyParentAndChildTypeChecks;
|
|
202
|
-
isGenericMatch = isGenericMatch || Boolean(unifiedSyntaxParentMatch);
|
|
203
|
-
hasMatchingPreferredType = isGenericMatch ||
|
|
204
|
-
directNameMatch && !property;
|
|
205
|
-
return [
|
|
206
|
-
hasMatchingPreferredType, typeName, isGenericMatch,
|
|
207
|
-
];
|
|
208
|
-
};
|
|
209
|
-
/**
|
|
210
|
-
* Iterates strict types to see if any should be added to `invalidTypes` (and
|
|
211
|
-
* the the relevant strict type returned as the new preferred type).
|
|
212
|
-
* @param {string} typeNodeName
|
|
213
|
-
* @param {string|undefined} preferred
|
|
214
|
-
* @param {import('jsdoc-type-pratt-parser').NonRootResult|undefined} parentNode
|
|
215
|
-
* @param {(string|false|undefined)[][]} invalidTypes
|
|
216
|
-
* @returns {string|undefined} The `preferred` type string, optionally changed
|
|
217
|
-
*/
|
|
218
|
-
const checkNativeTypes = (typeNodeName, preferred, parentNode, invalidTypes) => {
|
|
219
|
-
let changedPreferred = preferred;
|
|
220
|
-
for (const strictNativeType of strictNativeTypes) {
|
|
221
|
-
if (strictNativeType === 'object' &&
|
|
222
|
-
(
|
|
223
|
-
// This is not set to remap with exact type match (e.g.,
|
|
224
|
-
// `object: 'Object'`), so can ignore (including if circular)
|
|
225
|
-
!preferredTypes?.[typeNodeName] ||
|
|
226
|
-
// Although present on `preferredTypes` for remapping, this is a
|
|
227
|
-
// parent object without a parent match (and not
|
|
228
|
-
// `unifyParentAndChildTypeChecks`) and we don't want
|
|
229
|
-
// `object<>` given TypeScript issue https://github.com/microsoft/TypeScript/issues/20555
|
|
230
|
-
/**
|
|
231
|
-
* @type {import('jsdoc-type-pratt-parser').GenericResult}
|
|
232
|
-
*/
|
|
233
|
-
(parentNode)?.elements?.length && (
|
|
234
|
-
/**
|
|
235
|
-
* @type {import('jsdoc-type-pratt-parser').GenericResult}
|
|
236
|
-
*/
|
|
237
|
-
(parentNode)?.left?.type === 'JsdocTypeName' &&
|
|
238
|
-
/**
|
|
239
|
-
* @type {import('jsdoc-type-pratt-parser').GenericResult}
|
|
240
|
-
*/
|
|
241
|
-
(parentNode)?.left?.value === 'Object'))) {
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
if (strictNativeType !== typeNodeName &&
|
|
245
|
-
strictNativeType.toLowerCase() === typeNodeName.toLowerCase() &&
|
|
246
|
-
// Don't report if user has own map for a strict native type
|
|
247
|
-
(!preferredTypes || preferredTypes?.[strictNativeType] === undefined)) {
|
|
248
|
-
changedPreferred = strictNativeType;
|
|
249
|
-
invalidTypes.push([
|
|
250
|
-
typeNodeName, changedPreferred,
|
|
251
|
-
]);
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return changedPreferred;
|
|
256
|
-
};
|
|
257
|
-
/**
|
|
258
|
-
* Collect invalid type info.
|
|
259
|
-
* @param {string} type
|
|
260
|
-
* @param {string} value
|
|
261
|
-
* @param {string} tagName
|
|
262
|
-
* @param {string} nameInTag
|
|
263
|
-
* @param {number} idx
|
|
264
|
-
* @param {string|undefined} property
|
|
265
|
-
* @param {import('jsdoc-type-pratt-parser').NonRootResult} node
|
|
266
|
-
* @param {import('jsdoc-type-pratt-parser').NonRootResult|undefined} parentNode
|
|
267
|
-
* @param {(string|false|undefined)[][]} invalidTypes
|
|
268
|
-
* @returns {void}
|
|
269
|
-
*/
|
|
270
|
-
const getInvalidTypes = (type, value, tagName, nameInTag, idx, property, node, parentNode, invalidTypes) => {
|
|
271
|
-
let typeNodeName = type === 'JsdocTypeAny' ? '*' : value;
|
|
272
|
-
const [hasMatchingPreferredType, typeName, isGenericMatch,] = getPreferredTypeInfo(type, typeNodeName, parentNode, property);
|
|
273
|
-
let preferred;
|
|
274
|
-
let types;
|
|
275
|
-
if (hasMatchingPreferredType) {
|
|
276
|
-
const preferredSetting = preferredTypes[typeName];
|
|
277
|
-
typeNodeName = typeName === '[]' ? typeName : typeNodeName;
|
|
278
|
-
if (!preferredSetting) {
|
|
279
|
-
invalidTypes.push([
|
|
280
|
-
typeNodeName,
|
|
281
|
-
]);
|
|
282
|
-
}
|
|
283
|
-
else if (typeof preferredSetting === 'string') {
|
|
284
|
-
preferred = preferredSetting;
|
|
285
|
-
invalidTypes.push([
|
|
286
|
-
typeNodeName, preferred,
|
|
287
|
-
]);
|
|
288
|
-
}
|
|
289
|
-
else if (preferredSetting && typeof preferredSetting === 'object') {
|
|
290
|
-
const nextItem = preferredSetting.skipRootChecking && jsdocTagsWithPossibleType[idx + 1];
|
|
291
|
-
if (!nextItem || !nextItem.name.startsWith(`${nameInTag}.`)) {
|
|
292
|
-
preferred = preferredSetting.replacement;
|
|
293
|
-
invalidTypes.push([
|
|
294
|
-
typeNodeName,
|
|
295
|
-
preferred,
|
|
296
|
-
preferredSetting.message,
|
|
297
|
-
]);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
utils.reportSettings('Invalid `settings.jsdoc.preferredTypes`. Values must be falsy, a string, or an object.');
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
else if (Object.entries(structuredTags).some(([tag, { type: typs, },]) => {
|
|
306
|
-
types = typs;
|
|
307
|
-
return tag === tagName &&
|
|
308
|
-
Array.isArray(types) &&
|
|
309
|
-
!types.includes(typeNodeName);
|
|
310
|
-
})) {
|
|
311
|
-
invalidTypes.push([
|
|
312
|
-
typeNodeName, types,
|
|
313
|
-
]);
|
|
314
|
-
}
|
|
315
|
-
else if (!noDefaults && type === 'JsdocTypeName') {
|
|
316
|
-
preferred = checkNativeTypes(typeNodeName, preferred, parentNode, invalidTypes);
|
|
317
|
-
}
|
|
318
|
-
// For fixer
|
|
319
|
-
if (preferred) {
|
|
320
|
-
adjustNames(type, preferred, isGenericMatch, typeNodeName, node, parentNode);
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
for (const [idx, jsdocTag,] of jsdocTagsWithPossibleType.entries()) {
|
|
324
|
-
/** @type {(string|false|undefined)[][]} */
|
|
325
|
-
const invalidTypes = [];
|
|
326
|
-
let typeAst;
|
|
327
|
-
try {
|
|
328
|
-
typeAst = mode === 'permissive' ? (0, jsdoccomment_1.tryParse)(jsdocTag.type) : (0, jsdoccomment_1.parse)(jsdocTag.type, mode);
|
|
329
|
-
}
|
|
330
|
-
catch {
|
|
331
|
-
continue;
|
|
332
|
-
}
|
|
333
|
-
const { name: nameInTag, tag: tagName, } = jsdocTag;
|
|
334
|
-
(0, jsdoccomment_1.traverse)(typeAst, (node, parentNode, property) => {
|
|
335
|
-
const { type, value, } =
|
|
336
|
-
/**
|
|
337
|
-
* @type {import('jsdoc-type-pratt-parser').NameResult}
|
|
338
|
-
*/ (node);
|
|
339
|
-
if (![
|
|
340
|
-
'JsdocTypeAny', 'JsdocTypeName',
|
|
341
|
-
].includes(type)) {
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
getInvalidTypes(type, value, tagName, nameInTag, idx, property, node, parentNode, invalidTypes);
|
|
345
|
-
});
|
|
346
|
-
if (invalidTypes.length) {
|
|
347
|
-
const fixedType = (0, jsdoccomment_1.stringify)(typeAst);
|
|
348
|
-
/**
|
|
349
|
-
* @type {import('eslint').Rule.ReportFixer}
|
|
350
|
-
*/
|
|
351
|
-
const fix = (fixer) => {
|
|
352
|
-
return fixer.replaceText(jsdocNode, sourceCode.getText(jsdocNode).replace(`{${jsdocTag.type}}`, `{${fixedType}}`));
|
|
353
|
-
};
|
|
354
|
-
for (const [badType, preferredType = '', msg,] of invalidTypes) {
|
|
355
|
-
const tagValue = jsdocTag.name ? ` "${jsdocTag.name}"` : '';
|
|
356
|
-
if (exemptTagContexts.some(({ tag, types, }) => {
|
|
357
|
-
return tag === tagName &&
|
|
358
|
-
(types === true || types.includes(jsdocTag.type));
|
|
359
|
-
})) {
|
|
360
|
-
continue;
|
|
361
|
-
}
|
|
362
|
-
report(msg ||
|
|
363
|
-
`Invalid JSDoc @${tagName}${tagValue} type "${badType}"` +
|
|
364
|
-
(preferredType ? '; ' : '.') +
|
|
365
|
-
(preferredType ? `prefer: ${JSON.stringify(preferredType)}.` : ''), preferredType ? fix : null, jsdocTag, msg ? {
|
|
366
|
-
tagName,
|
|
367
|
-
tagValue,
|
|
368
|
-
} : undefined);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}, {
|
|
373
|
-
iterateAllJsdocs: true,
|
|
374
|
-
meta: {
|
|
375
|
-
docs: {
|
|
376
|
-
description: 'Reports invalid types.',
|
|
377
|
-
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-types.md#repos-sticky-header',
|
|
378
|
-
},
|
|
379
|
-
fixable: 'code',
|
|
380
|
-
schema: [
|
|
381
|
-
{
|
|
382
|
-
additionalProperties: false,
|
|
383
|
-
properties: {
|
|
384
|
-
exemptTagContexts: {
|
|
385
|
-
items: {
|
|
386
|
-
additionalProperties: false,
|
|
387
|
-
properties: {
|
|
388
|
-
tag: {
|
|
389
|
-
type: 'string',
|
|
390
|
-
},
|
|
391
|
-
types: {
|
|
392
|
-
oneOf: [
|
|
393
|
-
{
|
|
394
|
-
type: 'boolean',
|
|
395
|
-
},
|
|
396
|
-
{
|
|
397
|
-
items: {
|
|
398
|
-
type: 'string',
|
|
399
|
-
},
|
|
400
|
-
type: 'array',
|
|
401
|
-
},
|
|
402
|
-
],
|
|
403
|
-
},
|
|
404
|
-
},
|
|
405
|
-
type: 'object',
|
|
406
|
-
},
|
|
407
|
-
type: 'array',
|
|
408
|
-
},
|
|
409
|
-
noDefaults: {
|
|
410
|
-
type: 'boolean',
|
|
411
|
-
},
|
|
412
|
-
unifyParentAndChildTypeChecks: {
|
|
413
|
-
type: 'boolean',
|
|
414
|
-
},
|
|
415
|
-
},
|
|
416
|
-
type: 'object',
|
|
417
|
-
},
|
|
418
|
-
],
|
|
419
|
-
type: 'suggestion',
|
|
420
|
-
},
|
|
421
|
-
});
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const iterateJsdoc_js_1 = __importDefault(require("../iterateJsdoc.js"));
|
|
7
|
-
const parse_imports_exports_1 = require("parse-imports-exports");
|
|
8
|
-
const semver_1 = __importDefault(require("semver"));
|
|
9
|
-
const spdx_expression_parse_1 = __importDefault(require("spdx-expression-parse"));
|
|
10
|
-
const allowedKinds = new Set([
|
|
11
|
-
'class',
|
|
12
|
-
'constant',
|
|
13
|
-
'event',
|
|
14
|
-
'external',
|
|
15
|
-
'file',
|
|
16
|
-
'function',
|
|
17
|
-
'member',
|
|
18
|
-
'mixin',
|
|
19
|
-
'module',
|
|
20
|
-
'namespace',
|
|
21
|
-
'typedef',
|
|
22
|
-
]);
|
|
23
|
-
exports.default = (0, iterateJsdoc_js_1.default)(({ context, report, settings, utils, }) => {
|
|
24
|
-
const options = context.options[0] || {};
|
|
25
|
-
const { allowedAuthors = null, allowedLicenses = null, licensePattern = '/([^\n\r]*)/gv', numericOnlyVariation = false, } = options;
|
|
26
|
-
utils.forEachPreferredTag('version', (jsdocParameter, targetTagName) => {
|
|
27
|
-
const version = /** @type {string} */ (utils.getTagDescription(jsdocParameter)).trim();
|
|
28
|
-
if (!version) {
|
|
29
|
-
report(`Missing JSDoc @${targetTagName} value.`, null, jsdocParameter);
|
|
30
|
-
}
|
|
31
|
-
else if (!semver_1.default.valid(version)) {
|
|
32
|
-
report(`Invalid JSDoc @${targetTagName}: "${utils.getTagDescription(jsdocParameter)}".`, null, jsdocParameter);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
utils.forEachPreferredTag('kind', (jsdocParameter, targetTagName) => {
|
|
36
|
-
const kind = /** @type {string} */ (utils.getTagDescription(jsdocParameter)).trim();
|
|
37
|
-
if (!kind) {
|
|
38
|
-
report(`Missing JSDoc @${targetTagName} value.`, null, jsdocParameter);
|
|
39
|
-
}
|
|
40
|
-
else if (!allowedKinds.has(kind)) {
|
|
41
|
-
report(`Invalid JSDoc @${targetTagName}: "${utils.getTagDescription(jsdocParameter)}"; ` +
|
|
42
|
-
`must be one of: ${[
|
|
43
|
-
...allowedKinds,
|
|
44
|
-
].join(', ')}.`, null, jsdocParameter);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
if (numericOnlyVariation) {
|
|
48
|
-
utils.forEachPreferredTag('variation', (jsdocParameter, targetTagName) => {
|
|
49
|
-
const variation = /** @type {string} */ (utils.getTagDescription(jsdocParameter)).trim();
|
|
50
|
-
if (!variation) {
|
|
51
|
-
report(`Missing JSDoc @${targetTagName} value.`, null, jsdocParameter);
|
|
52
|
-
}
|
|
53
|
-
else if (!Number.isInteger(Number(variation)) ||
|
|
54
|
-
Number(variation) <= 0) {
|
|
55
|
-
report(`Invalid JSDoc @${targetTagName}: "${utils.getTagDescription(jsdocParameter)}".`, null, jsdocParameter);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
utils.forEachPreferredTag('since', (jsdocParameter, targetTagName) => {
|
|
60
|
-
const version = /** @type {string} */ (utils.getTagDescription(jsdocParameter)).trim();
|
|
61
|
-
if (!version) {
|
|
62
|
-
report(`Missing JSDoc @${targetTagName} value.`, null, jsdocParameter);
|
|
63
|
-
}
|
|
64
|
-
else if (!semver_1.default.valid(version)) {
|
|
65
|
-
report(`Invalid JSDoc @${targetTagName}: "${utils.getTagDescription(jsdocParameter)}".`, null, jsdocParameter);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
utils.forEachPreferredTag('license', (jsdocParameter, targetTagName) => {
|
|
69
|
-
const licenseRegex = utils.getRegexFromString(licensePattern, 'g');
|
|
70
|
-
const matches = /** @type {string} */ (utils.getTagDescription(jsdocParameter)).matchAll(licenseRegex);
|
|
71
|
-
let positiveMatch = false;
|
|
72
|
-
for (const match of matches) {
|
|
73
|
-
const license = match[1] || match[0];
|
|
74
|
-
if (license) {
|
|
75
|
-
positiveMatch = true;
|
|
76
|
-
}
|
|
77
|
-
if (!license.trim()) {
|
|
78
|
-
// Avoid reporting again as empty match
|
|
79
|
-
if (positiveMatch) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
report(`Missing JSDoc @${targetTagName} value.`, null, jsdocParameter);
|
|
83
|
-
}
|
|
84
|
-
else if (allowedLicenses) {
|
|
85
|
-
if (allowedLicenses !== true && !allowedLicenses.includes(license)) {
|
|
86
|
-
report(`Invalid JSDoc @${targetTagName}: "${license}"; expected one of ${allowedLicenses.join(', ')}.`, null, jsdocParameter);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
try {
|
|
91
|
-
(0, spdx_expression_parse_1.default)(license);
|
|
92
|
-
}
|
|
93
|
-
catch {
|
|
94
|
-
report(`Invalid JSDoc @${targetTagName}: "${license}"; expected SPDX expression: https://spdx.org/licenses/.`, null, jsdocParameter);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
if (settings.mode === 'typescript') {
|
|
100
|
-
utils.forEachPreferredTag('import', (tag) => {
|
|
101
|
-
const { description, name, type, } = tag;
|
|
102
|
-
const typePart = type ? `{${type}} ` : '';
|
|
103
|
-
const imprt = 'import ' + (description ?
|
|
104
|
-
`${typePart}${name} ${description}` :
|
|
105
|
-
`${typePart}${name}`);
|
|
106
|
-
const importsExports = (0, parse_imports_exports_1.parseImportsExports)(imprt.trim());
|
|
107
|
-
if (importsExports.errors) {
|
|
108
|
-
report('Bad @import tag', null, tag);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
utils.forEachPreferredTag('author', (jsdocParameter, targetTagName) => {
|
|
113
|
-
const author = /** @type {string} */ (utils.getTagDescription(jsdocParameter)).trim();
|
|
114
|
-
if (!author) {
|
|
115
|
-
report(`Missing JSDoc @${targetTagName} value.`, null, jsdocParameter);
|
|
116
|
-
}
|
|
117
|
-
else if (allowedAuthors && !allowedAuthors.includes(author)) {
|
|
118
|
-
report(`Invalid JSDoc @${targetTagName}: "${utils.getTagDescription(jsdocParameter)}"; expected one of ${allowedAuthors.join(', ')}.`, null, jsdocParameter);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}, {
|
|
122
|
-
iterateAllJsdocs: true,
|
|
123
|
-
meta: {
|
|
124
|
-
docs: {
|
|
125
|
-
description: 'This rule checks the values for a handful of tags: `@version`, `@since`, `@license` and `@author`.',
|
|
126
|
-
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-values.md#repos-sticky-header',
|
|
127
|
-
},
|
|
128
|
-
schema: [
|
|
129
|
-
{
|
|
130
|
-
additionalProperties: false,
|
|
131
|
-
properties: {
|
|
132
|
-
allowedAuthors: {
|
|
133
|
-
items: {
|
|
134
|
-
type: 'string',
|
|
135
|
-
},
|
|
136
|
-
type: 'array',
|
|
137
|
-
},
|
|
138
|
-
allowedLicenses: {
|
|
139
|
-
anyOf: [
|
|
140
|
-
{
|
|
141
|
-
items: {
|
|
142
|
-
type: 'string',
|
|
143
|
-
},
|
|
144
|
-
type: 'array',
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
type: 'boolean',
|
|
148
|
-
},
|
|
149
|
-
],
|
|
150
|
-
},
|
|
151
|
-
licensePattern: {
|
|
152
|
-
type: 'string',
|
|
153
|
-
},
|
|
154
|
-
numericOnlyVariation: {
|
|
155
|
-
type: 'boolean',
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
type: 'object',
|
|
159
|
-
},
|
|
160
|
-
],
|
|
161
|
-
type: 'suggestion',
|
|
162
|
-
},
|
|
163
|
-
});
|