eslint-plugin-jsdoc 63.3.3 → 64.0.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/package.json +23 -48
- package/src/index.js +3 -6
- package/dist/WarnSettings.cjs +0 -38
- package/dist/WarnSettings.cjs.map +0 -1
- package/dist/alignTransform.cjs +0 -402
- package/dist/alignTransform.cjs.map +0 -1
- package/dist/buildForbidRuleDefinition.cjs +0 -101
- package/dist/buildForbidRuleDefinition.cjs.map +0 -1
- package/dist/buildRejectOrPreferRuleDefinition.cjs +0 -352
- package/dist/buildRejectOrPreferRuleDefinition.cjs.map +0 -1
- package/dist/cjs/WarnSettings.d.ts +0 -16
- package/dist/cjs/alignTransform.d.ts +0 -33
- package/dist/cjs/buildForbidRuleDefinition.d.ts +0 -14
- package/dist/cjs/buildRejectOrPreferRuleDefinition.d.ts +0 -8
- package/dist/cjs/defaultTagOrder.d.ts +0 -4
- package/dist/cjs/exportParser.d.ts +0 -40
- package/dist/cjs/getDefaultTagStructureForMode.d.ts +0 -10
- package/dist/cjs/getJsdocProcessorPlugin.d.cts +0 -5
- package/dist/cjs/getJsdocProcessorPlugin.d.ts +0 -66
- package/dist/cjs/index-cjs.d.ts +0 -26
- package/dist/cjs/index.cjs.d.cts +0 -2
- package/dist/cjs/iterateJsdoc.d.cts +0 -7
- package/dist/cjs/iterateJsdoc.d.ts +0 -495
- package/dist/cjs/jsdocUtils.d.ts +0 -500
- package/dist/cjs/rules/checkAccess.d.ts +0 -2
- package/dist/cjs/rules/checkAlignment.d.ts +0 -2
- package/dist/cjs/rules/checkExamples.d.ts +0 -3
- package/dist/cjs/rules/checkIndentation.d.ts +0 -2
- package/dist/cjs/rules/checkLineAlignment.d.ts +0 -9
- package/dist/cjs/rules/checkParamNames.d.ts +0 -2
- package/dist/cjs/rules/checkPropertyNames.d.ts +0 -2
- package/dist/cjs/rules/checkSyntax.d.ts +0 -2
- package/dist/cjs/rules/checkTagNames.d.ts +0 -2
- package/dist/cjs/rules/checkTemplateNames.d.ts +0 -2
- package/dist/cjs/rules/checkTypes.d.ts +0 -7
- package/dist/cjs/rules/checkValues.d.ts +0 -2
- package/dist/cjs/rules/convertToJsdocComments.d.ts +0 -266
- package/dist/cjs/rules/emptyTags.d.ts +0 -2
- package/dist/cjs/rules/escapeInlineTags.d.ts +0 -2
- package/dist/cjs/rules/implementsOnClasses.d.ts +0 -2
- package/dist/cjs/rules/importsAsDependencies.d.ts +0 -2
- package/dist/cjs/rules/informativeDocs.d.ts +0 -2
- package/dist/cjs/rules/linesBeforeBlock.d.ts +0 -2
- package/dist/cjs/rules/matchDescription.d.ts +0 -2
- package/dist/cjs/rules/matchName.d.ts +0 -2
- package/dist/cjs/rules/multilineBlocks.d.ts +0 -2
- package/dist/cjs/rules/noBadBlocks.d.ts +0 -2
- package/dist/cjs/rules/noBlankBlockDescriptions.d.ts +0 -2
- package/dist/cjs/rules/noBlankBlocks.d.ts +0 -2
- package/dist/cjs/rules/noDefaults.d.ts +0 -2
- package/dist/cjs/rules/noMissingSyntax.d.ts +0 -9
- package/dist/cjs/rules/noMultiAsterisks.d.ts +0 -2
- package/dist/cjs/rules/noRestrictedSyntax.d.ts +0 -2
- package/dist/cjs/rules/noTypes.d.ts +0 -2
- package/dist/cjs/rules/noUndefinedTypes.d.ts +0 -2
- package/dist/cjs/rules/normalizeSeeLinks.d.ts +0 -2
- package/dist/cjs/rules/preferImportTag.d.ts +0 -2
- package/dist/cjs/rules/requireAsteriskPrefix.d.ts +0 -2
- package/dist/cjs/rules/requireDescription.d.ts +0 -2
- package/dist/cjs/rules/requireDescriptionCompleteSentence.d.ts +0 -2
- package/dist/cjs/rules/requireExample.d.ts +0 -2
- package/dist/cjs/rules/requireFileOverview.d.ts +0 -2
- package/dist/cjs/rules/requireHyphenBeforeParamDescription.d.ts +0 -2
- package/dist/cjs/rules/requireJsdoc.d.ts +0 -24
- package/dist/cjs/rules/requireParam.d.ts +0 -3
- package/dist/cjs/rules/requireParamDescription.d.ts +0 -2
- package/dist/cjs/rules/requireParamName.d.ts +0 -2
- package/dist/cjs/rules/requireParamType.d.ts +0 -2
- package/dist/cjs/rules/requireProperty.d.ts +0 -2
- package/dist/cjs/rules/requirePropertyDescription.d.ts +0 -2
- package/dist/cjs/rules/requirePropertyName.d.ts +0 -2
- package/dist/cjs/rules/requirePropertyType.d.ts +0 -2
- package/dist/cjs/rules/requireRejects.d.ts +0 -2
- package/dist/cjs/rules/requireReturns.d.ts +0 -2
- package/dist/cjs/rules/requireReturnsCheck.d.ts +0 -2
- package/dist/cjs/rules/requireReturnsDescription.d.ts +0 -2
- package/dist/cjs/rules/requireReturnsType.d.ts +0 -2
- package/dist/cjs/rules/requireTags.d.ts +0 -2
- package/dist/cjs/rules/requireTemplate.d.ts +0 -2
- package/dist/cjs/rules/requireThrows.d.ts +0 -2
- package/dist/cjs/rules/requireYields.d.ts +0 -2
- package/dist/cjs/rules/requireYieldsCheck.d.ts +0 -2
- package/dist/cjs/rules/sortTags.d.ts +0 -2
- package/dist/cjs/rules/tagLines.d.ts +0 -2
- package/dist/cjs/rules/textEscaping.d.ts +0 -2
- package/dist/cjs/rules/tsMethodSignatureStyle.d.ts +0 -2
- package/dist/cjs/rules/tsNoEmptyObjectType.d.ts +0 -2
- package/dist/cjs/rules/tsNoUnnecessaryTemplateExpression.d.ts +0 -2
- package/dist/cjs/rules/tsPreferFunctionType.d.ts +0 -2
- package/dist/cjs/rules/typeFormatting.d.ts +0 -2
- package/dist/cjs/rules/validTypes.d.ts +0 -2
- package/dist/cjs/tagNames.d.ts +0 -15
- package/dist/cjs/utils/hasReturnValue.d.ts +0 -19
- package/dist/defaultTagOrder.cjs +0 -46
- package/dist/defaultTagOrder.cjs.map +0 -1
- package/dist/exportParser.cjs +0 -732
- package/dist/exportParser.cjs.map +0 -1
- package/dist/generateDocs.cjs +0 -342
- package/dist/generateDocs.cjs.map +0 -1
- package/dist/generateOptions.cjs +0 -62
- package/dist/generateOptions.cjs.map +0 -1
- package/dist/generateRule.cjs +0 -248
- package/dist/generateRule.cjs.map +0 -1
- package/dist/generateRuleTypes.cjs +0 -24
- package/dist/generateRuleTypes.cjs.map +0 -1
- package/dist/getDefaultTagStructureForMode.cjs +0 -289
- package/dist/getDefaultTagStructureForMode.cjs.map +0 -1
- package/dist/getJsdocProcessorPlugin.cjs +0 -587
- package/dist/getJsdocProcessorPlugin.cjs.map +0 -1
- package/dist/getJsdocProcessorPlugin.cts +0 -5
- package/dist/index-cjs.cjs +0 -600
- package/dist/index-cjs.cjs.map +0 -1
- package/dist/index-cjs.d.ts +0 -27
- package/dist/index-esm.cjs +0 -162
- package/dist/index-esm.cjs.map +0 -1
- package/dist/index-esm.d.ts +0 -72
- package/dist/index.cjs +0 -748
- package/dist/index.cjs.cts +0 -3
- package/dist/index.cjs.map +0 -1
- package/dist/iterateJsdoc.cjs +0 -2150
- package/dist/iterateJsdoc.cjs.map +0 -1
- package/dist/iterateJsdoc.cts +0 -7
- package/dist/jsdocUtils.cjs +0 -1786
- package/dist/jsdocUtils.cjs.map +0 -1
- package/dist/rules/checkAccess.cjs +0 -40
- package/dist/rules/checkAccess.cjs.map +0 -1
- package/dist/rules/checkAlignment.cjs +0 -78
- package/dist/rules/checkAlignment.cjs.map +0 -1
- package/dist/rules/checkExamples.cjs +0 -521
- package/dist/rules/checkExamples.cjs.map +0 -1
- package/dist/rules/checkIndentation.cjs +0 -170
- package/dist/rules/checkIndentation.cjs.map +0 -1
- package/dist/rules/checkLineAlignment.cjs +0 -398
- package/dist/rules/checkLineAlignment.cjs.map +0 -1
- package/dist/rules/checkParamNames.cjs +0 -407
- package/dist/rules/checkParamNames.cjs.map +0 -1
- package/dist/rules/checkPropertyNames.cjs +0 -135
- package/dist/rules/checkPropertyNames.cjs.map +0 -1
- package/dist/rules/checkSyntax.cjs +0 -38
- package/dist/rules/checkSyntax.cjs.map +0 -1
- package/dist/rules/checkTagNames.cjs +0 -312
- package/dist/rules/checkTagNames.cjs.map +0 -1
- package/dist/rules/checkTemplateNames.cjs +0 -192
- package/dist/rules/checkTemplateNames.cjs.map +0 -1
- package/dist/rules/checkTypes.cjs +0 -111
- package/dist/rules/checkTypes.cjs.map +0 -1
- package/dist/rules/checkValues.cjs +0 -166
- package/dist/rules/checkValues.cjs.map +0 -1
- package/dist/rules/convertToJsdocComments.cjs +0 -356
- package/dist/rules/convertToJsdocComments.cjs.map +0 -1
- package/dist/rules/emptyTags.cjs +0 -98
- package/dist/rules/emptyTags.cjs.map +0 -1
- package/dist/rules/escapeInlineTags.cjs +0 -234
- package/dist/rules/escapeInlineTags.cjs.map +0 -1
- package/dist/rules/implementsOnClasses.cjs +0 -74
- package/dist/rules/implementsOnClasses.cjs.map +0 -1
- package/dist/rules/importsAsDependencies.cjs +0 -104
- package/dist/rules/importsAsDependencies.cjs.map +0 -1
- package/dist/rules/informativeDocs.cjs +0 -187
- package/dist/rules/informativeDocs.cjs.map +0 -1
- package/dist/rules/linesBeforeBlock.cjs +0 -120
- package/dist/rules/linesBeforeBlock.cjs.map +0 -1
- package/dist/rules/matchDescription.cjs +0 -356
- package/dist/rules/matchDescription.cjs.map +0 -1
- package/dist/rules/matchName.cjs +0 -160
- package/dist/rules/matchName.cjs.map +0 -1
- package/dist/rules/multilineBlocks.cjs +0 -431
- package/dist/rules/multilineBlocks.cjs.map +0 -1
- package/dist/rules/noBadBlocks.cjs +0 -100
- package/dist/rules/noBadBlocks.cjs.map +0 -1
- package/dist/rules/noBlankBlockDescriptions.cjs +0 -63
- package/dist/rules/noBlankBlockDescriptions.cjs.map +0 -1
- package/dist/rules/noBlankBlocks.cjs +0 -54
- package/dist/rules/noBlankBlocks.cjs.map +0 -1
- package/dist/rules/noDefaults.cjs +0 -102
- package/dist/rules/noDefaults.cjs.map +0 -1
- package/dist/rules/noMissingSyntax.cjs +0 -196
- package/dist/rules/noMissingSyntax.cjs.map +0 -1
- package/dist/rules/noMultiAsterisks.cjs +0 -126
- package/dist/rules/noMultiAsterisks.cjs.map +0 -1
- package/dist/rules/noRestrictedSyntax.cjs +0 -68
- package/dist/rules/noRestrictedSyntax.cjs.map +0 -1
- package/dist/rules/noTypes.cjs +0 -101
- package/dist/rules/noTypes.cjs.map +0 -1
- package/dist/rules/noUndefinedTypes.cjs +0 -616
- package/dist/rules/noUndefinedTypes.cjs.map +0 -1
- package/dist/rules/normalizeSeeLinks.cjs +0 -271
- package/dist/rules/normalizeSeeLinks.cjs.map +0 -1
- package/dist/rules/preferImportTag.cjs +0 -362
- package/dist/rules/preferImportTag.cjs.map +0 -1
- package/dist/rules/requireAsteriskPrefix.cjs +0 -190
- package/dist/rules/requireAsteriskPrefix.cjs.map +0 -1
- package/dist/rules/requireDescription.cjs +0 -164
- package/dist/rules/requireDescription.cjs.map +0 -1
- package/dist/rules/requireDescriptionCompleteSentence.cjs +0 -321
- package/dist/rules/requireDescriptionCompleteSentence.cjs.map +0 -1
- package/dist/rules/requireExample.cjs +0 -136
- package/dist/rules/requireExample.cjs.map +0 -1
- package/dist/rules/requireFileOverview.cjs +0 -194
- package/dist/rules/requireFileOverview.cjs.map +0 -1
- package/dist/rules/requireHyphenBeforeParamDescription.cjs +0 -166
- package/dist/rules/requireHyphenBeforeParamDescription.cjs.map +0 -1
- package/dist/rules/requireJsdoc.cjs +0 -721
- package/dist/rules/requireJsdoc.cjs.map +0 -1
- package/dist/rules/requireParam.cjs +0 -772
- package/dist/rules/requireParam.cjs.map +0 -1
- package/dist/rules/requireParamDescription.cjs +0 -105
- package/dist/rules/requireParamDescription.cjs.map +0 -1
- package/dist/rules/requireParamName.cjs +0 -68
- package/dist/rules/requireParamName.cjs.map +0 -1
- package/dist/rules/requireParamType.cjs +0 -104
- package/dist/rules/requireParamType.cjs.map +0 -1
- package/dist/rules/requireProperty.cjs +0 -63
- package/dist/rules/requireProperty.cjs.map +0 -1
- package/dist/rules/requirePropertyDescription.cjs +0 -29
- package/dist/rules/requirePropertyDescription.cjs.map +0 -1
- package/dist/rules/requirePropertyName.cjs +0 -29
- package/dist/rules/requirePropertyName.cjs.map +0 -1
- package/dist/rules/requirePropertyType.cjs +0 -29
- package/dist/rules/requirePropertyType.cjs.map +0 -1
- package/dist/rules/requireRejects.cjs +0 -226
- package/dist/rules/requireRejects.cjs.map +0 -1
- package/dist/rules/requireReturns.cjs +0 -262
- package/dist/rules/requireReturns.cjs.map +0 -1
- package/dist/rules/requireReturnsCheck.cjs +0 -225
- package/dist/rules/requireReturnsCheck.cjs.map +0 -1
- package/dist/rules/requireReturnsDescription.cjs +0 -72
- package/dist/rules/requireReturnsDescription.cjs.map +0 -1
- package/dist/rules/requireReturnsType.cjs +0 -68
- package/dist/rules/requireReturnsType.cjs.map +0 -1
- package/dist/rules/requireTags.cjs +0 -74
- package/dist/rules/requireTags.cjs.map +0 -1
- package/dist/rules/requireTemplate.cjs +0 -220
- package/dist/rules/requireTemplate.cjs.map +0 -1
- package/dist/rules/requireThrows.cjs +0 -118
- package/dist/rules/requireThrows.cjs.map +0 -1
- package/dist/rules/requireYields.cjs +0 -224
- package/dist/rules/requireYields.cjs.map +0 -1
- package/dist/rules/requireYieldsCheck.cjs +0 -179
- package/dist/rules/requireYieldsCheck.cjs.map +0 -1
- package/dist/rules/sortTags.cjs +0 -656
- package/dist/rules/sortTags.cjs.map +0 -1
- package/dist/rules/tagLines.cjs +0 -374
- package/dist/rules/tagLines.cjs.map +0 -1
- package/dist/rules/textEscaping.cjs +0 -141
- package/dist/rules/textEscaping.cjs.map +0 -1
- package/dist/rules/tsMethodSignatureStyle.cjs +0 -240
- package/dist/rules/tsMethodSignatureStyle.cjs.map +0 -1
- package/dist/rules/tsNoEmptyObjectType.cjs +0 -62
- package/dist/rules/tsNoEmptyObjectType.cjs.map +0 -1
- package/dist/rules/tsNoUnnecessaryTemplateExpression.cjs +0 -104
- package/dist/rules/tsNoUnnecessaryTemplateExpression.cjs.map +0 -1
- package/dist/rules/tsPreferFunctionType.cjs +0 -110
- package/dist/rules/tsPreferFunctionType.cjs.map +0 -1
- package/dist/rules/typeFormatting.cjs +0 -607
- package/dist/rules/typeFormatting.cjs.map +0 -1
- package/dist/rules/validTypes.cjs +0 -324
- package/dist/rules/validTypes.cjs.map +0 -1
- package/dist/tagNames.cjs +0 -244
- package/dist/tagNames.cjs.map +0 -1
- package/dist/to-valid-identifier.cjs +0 -263
- package/dist/utils/hasReturnValue.cjs +0 -495
- package/dist/utils/hasReturnValue.cjs.map +0 -1
- package/rollup.config.js +0 -16
- package/src/getJsdocProcessorPlugin.cts +0 -5
- package/src/index-cjs.js +0 -760
- package/src/index-esm.js +0 -196
- package/src/index.cjs.cts +0 -3
- package/src/iterateJsdoc.cts +0 -7
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _iterateJsdoc = _interopRequireDefault(require("../iterateJsdoc.cjs"));
|
|
8
|
-
var _escapeStringRegexp = _interopRequireDefault(require("escape-string-regexp"));
|
|
9
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
// https://babeljs.io/docs/en/babel-plugin-transform-react-jsx/
|
|
11
|
-
const jsxTagNames = new Set(['jsx', 'jsxFrag', 'jsxImportSource', 'jsxRuntime']);
|
|
12
|
-
const typedTagsAlwaysUnnecessary = new Set(['augments', 'callback', 'class', 'enum', 'implements', 'private', 'property', 'protected', 'public', 'readonly', 'this', 'type', 'typedef']);
|
|
13
|
-
const typedTagsNeedingName = new Set(['template']);
|
|
14
|
-
const typedTagsUnnecessaryOutsideDeclare = new Set(['abstract', 'access', 'class', 'constant', 'constructs', 'default', 'enum', 'export', 'exports', 'function', 'global', 'inherits', 'instance', 'interface', 'member', 'memberof', 'memberOf', 'method', 'mixes', 'mixin', 'module', 'name', 'namespace', 'override', 'property', 'requires', 'static', 'this']);
|
|
15
|
-
var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
16
|
-
context,
|
|
17
|
-
jsdoc,
|
|
18
|
-
jsdocNode,
|
|
19
|
-
node,
|
|
20
|
-
report,
|
|
21
|
-
settings,
|
|
22
|
-
sourceCode,
|
|
23
|
-
utils
|
|
24
|
-
}) => {
|
|
25
|
-
const
|
|
26
|
-
/**
|
|
27
|
-
* @type {{
|
|
28
|
-
* definedTags: string[],
|
|
29
|
-
* enableFixer: boolean,
|
|
30
|
-
* inlineTags: string[],
|
|
31
|
-
* jsxTags: boolean,
|
|
32
|
-
* typed: boolean
|
|
33
|
-
}} */
|
|
34
|
-
{
|
|
35
|
-
definedTags = [],
|
|
36
|
-
enableFixer = true,
|
|
37
|
-
inlineTags = [
|
|
38
|
-
// jsdoc
|
|
39
|
-
'link', 'linkcode', 'linkplain', 'tutorial',
|
|
40
|
-
// https://tsdoc.org/pages/spec/tag_kinds/#inline-tags
|
|
41
|
-
'inheritDoc', 'label',
|
|
42
|
-
// https://typedoc.org/documents/Tags.html#inline-tags
|
|
43
|
-
'include', 'includeCode'],
|
|
44
|
-
jsxTags,
|
|
45
|
-
typed
|
|
46
|
-
} = context.options[0] || {};
|
|
47
|
-
|
|
48
|
-
/** @type {(string|undefined)[]} */
|
|
49
|
-
let definedPreferredTags = [];
|
|
50
|
-
const {
|
|
51
|
-
structuredTags,
|
|
52
|
-
tagNamePreference
|
|
53
|
-
} = settings;
|
|
54
|
-
const definedStructuredTags = Object.keys(structuredTags);
|
|
55
|
-
const definedNonPreferredTags = Object.keys(tagNamePreference);
|
|
56
|
-
if (definedNonPreferredTags.length) {
|
|
57
|
-
definedPreferredTags = Object.values(tagNamePreference).map(preferredTag => {
|
|
58
|
-
if (typeof preferredTag === 'string') {
|
|
59
|
-
// May become an empty string but will be filtered out below
|
|
60
|
-
return preferredTag;
|
|
61
|
-
}
|
|
62
|
-
if (!preferredTag) {
|
|
63
|
-
return undefined;
|
|
64
|
-
}
|
|
65
|
-
if (typeof preferredTag !== 'object') {
|
|
66
|
-
utils.reportSettings('Invalid `settings.jsdoc.tagNamePreference`. Values must be falsy, a string, or an object.');
|
|
67
|
-
}
|
|
68
|
-
return preferredTag.replacement;
|
|
69
|
-
}).filter(Boolean);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @param {import('eslint').Rule.Node} subNode
|
|
74
|
-
* @returns {boolean}
|
|
75
|
-
*/
|
|
76
|
-
const isInAmbientContext = subNode => {
|
|
77
|
-
return subNode.type === 'Program' ? /* c8 ignore next 2 -- Support old ESLint */
|
|
78
|
-
// @ts-expect-error ESLint < 10
|
|
79
|
-
(context.filename ?? context.getFilename()).endsWith('.d.ts') : Boolean(/** @type {import('@typescript-eslint/types').TSESTree.VariableDeclaration} */subNode.declare) || isInAmbientContext(subNode.parent);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* @param {import('comment-parser').Spec} jsdocTag
|
|
84
|
-
* @returns {boolean}
|
|
85
|
-
*/
|
|
86
|
-
const tagIsRedundantWhenTyped = jsdocTag => {
|
|
87
|
-
if (!typedTagsUnnecessaryOutsideDeclare.has(jsdocTag.tag)) {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
if (jsdocTag.tag === 'default') {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
if (node === null) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/* c8 ignore next 2 -- Support old ESLint */
|
|
98
|
-
// @ts-expect-error ESLint < 10
|
|
99
|
-
if ((context.filename ?? context.getFilename()).endsWith('.d.ts') && [null, 'Program', undefined].includes(node?.parent?.type)) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
if (isInAmbientContext(/** @type {import('eslint').Rule.Node} */node)) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
return true;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* @param {string} message
|
|
110
|
-
* @param {import('comment-parser').Spec} jsdocTag
|
|
111
|
-
* @param {import('../iterateJsdoc.js').Integer} tagIndex
|
|
112
|
-
* @param {Partial<import('comment-parser').Tokens>} [additionalTagChanges]
|
|
113
|
-
* @returns {void}
|
|
114
|
-
*/
|
|
115
|
-
const reportWithTagRemovalFixer = (message, jsdocTag, tagIndex, additionalTagChanges) => {
|
|
116
|
-
utils.reportJSDoc(message, jsdocTag, enableFixer ? () => {
|
|
117
|
-
if (jsdocTag.description.trim()) {
|
|
118
|
-
utils.changeTag(jsdocTag, {
|
|
119
|
-
postType: '',
|
|
120
|
-
type: '',
|
|
121
|
-
...additionalTagChanges
|
|
122
|
-
});
|
|
123
|
-
} else {
|
|
124
|
-
utils.removeTag(tagIndex, {
|
|
125
|
-
removeEmptyBlock: true
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
} : null, true);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* @param {import('comment-parser').Spec} jsdocTag
|
|
133
|
-
* @param {import('../iterateJsdoc.js').Integer} tagIndex
|
|
134
|
-
* @returns {boolean}
|
|
135
|
-
*/
|
|
136
|
-
const checkTagForTypedValidity = (jsdocTag, tagIndex) => {
|
|
137
|
-
if (typedTagsAlwaysUnnecessary.has(jsdocTag.tag)) {
|
|
138
|
-
reportWithTagRemovalFixer(`'@${jsdocTag.tag}' is redundant when using a type system.`, jsdocTag, tagIndex, {
|
|
139
|
-
postTag: '',
|
|
140
|
-
tag: ''
|
|
141
|
-
});
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
if (tagIsRedundantWhenTyped(jsdocTag)) {
|
|
145
|
-
reportWithTagRemovalFixer(`'@${jsdocTag.tag}' is redundant outside of ambient (\`declare\`/\`.d.ts\`) contexts when using a type system.`, jsdocTag, tagIndex);
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
if (typedTagsNeedingName.has(jsdocTag.tag) && !jsdocTag.name) {
|
|
149
|
-
reportWithTagRemovalFixer(`'@${jsdocTag.tag}' without a name is redundant when using a type system.`, jsdocTag, tagIndex);
|
|
150
|
-
return true;
|
|
151
|
-
}
|
|
152
|
-
return false;
|
|
153
|
-
};
|
|
154
|
-
for (let tagIndex = 0; tagIndex < jsdoc.tags.length; tagIndex += 1) {
|
|
155
|
-
const jsdocTag = jsdoc.tags[tagIndex];
|
|
156
|
-
const tagName = jsdocTag.tag;
|
|
157
|
-
if (jsxTags && jsxTagNames.has(tagName)) {
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
if (typed && checkTagForTypedValidity(jsdocTag, tagIndex)) {
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
const validTags = [...definedTags, ...(/** @type {string[]} */definedPreferredTags), ...definedNonPreferredTags, ...definedStructuredTags, ...(typed ? typedTagsNeedingName : [])];
|
|
164
|
-
if (utils.isValidTag(tagName, validTags)) {
|
|
165
|
-
let preferredTagName = utils.getPreferredTagName({
|
|
166
|
-
allowObjectReturn: true,
|
|
167
|
-
defaultMessage: `Blacklisted tag found (\`@${tagName}\`)`,
|
|
168
|
-
tagName
|
|
169
|
-
});
|
|
170
|
-
if (!preferredTagName) {
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
let message;
|
|
174
|
-
if (typeof preferredTagName === 'object') {
|
|
175
|
-
({
|
|
176
|
-
message,
|
|
177
|
-
replacement: preferredTagName
|
|
178
|
-
} = /** @type {{message: string; replacement?: string | undefined;}} */
|
|
179
|
-
preferredTagName);
|
|
180
|
-
}
|
|
181
|
-
if (!message) {
|
|
182
|
-
message = `Invalid JSDoc tag (preference). Replace "${tagName}" JSDoc tag with "${preferredTagName}".`;
|
|
183
|
-
}
|
|
184
|
-
if (preferredTagName !== tagName) {
|
|
185
|
-
report(message, fixer => {
|
|
186
|
-
const replacement = sourceCode.getText(jsdocNode).replace(new RegExp(`@${(0, _escapeStringRegexp.default)(tagName)}\\b`, 'v'), `@${preferredTagName}`);
|
|
187
|
-
return fixer.replaceText(jsdocNode, replacement);
|
|
188
|
-
}, jsdocTag);
|
|
189
|
-
}
|
|
190
|
-
} else {
|
|
191
|
-
report(`Invalid JSDoc tag name "${tagName}".`, null, jsdocTag);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
for (const inlineTag of utils.getInlineTags()) {
|
|
195
|
-
if (!inlineTags.includes(inlineTag.tag)) {
|
|
196
|
-
report(`Invalid JSDoc inline tag name "${inlineTag.tag}"`, null, inlineTag);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}, {
|
|
200
|
-
iterateAllJsdocs: true,
|
|
201
|
-
meta: {
|
|
202
|
-
docs: {
|
|
203
|
-
description: 'Reports invalid block tag names.',
|
|
204
|
-
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-tag-names.md#repos-sticky-header'
|
|
205
|
-
},
|
|
206
|
-
fixable: 'code',
|
|
207
|
-
schema: [{
|
|
208
|
-
additionalProperties: false,
|
|
209
|
-
properties: {
|
|
210
|
-
definedTags: {
|
|
211
|
-
description: `Use an array of \`definedTags\` strings to configure additional, allowed tags.
|
|
212
|
-
The format is as follows:
|
|
213
|
-
|
|
214
|
-
\`\`\`json
|
|
215
|
-
{
|
|
216
|
-
"definedTags": ["note", "record"]
|
|
217
|
-
}
|
|
218
|
-
\`\`\``,
|
|
219
|
-
items: {
|
|
220
|
-
type: 'string'
|
|
221
|
-
},
|
|
222
|
-
type: 'array'
|
|
223
|
-
},
|
|
224
|
-
enableFixer: {
|
|
225
|
-
description: 'Set to `false` to disable auto-removal of types that are redundant with the [`typed` option](#typed).',
|
|
226
|
-
type: 'boolean'
|
|
227
|
-
},
|
|
228
|
-
inlineTags: {
|
|
229
|
-
description: `List of tags to allow inline.
|
|
230
|
-
|
|
231
|
-
Defaults to array of \`'link', 'linkcode', 'linkplain', 'tutorial', 'inheritDoc', 'label', 'include', and 'includeCode'\``,
|
|
232
|
-
items: {
|
|
233
|
-
type: 'string'
|
|
234
|
-
},
|
|
235
|
-
type: 'array'
|
|
236
|
-
},
|
|
237
|
-
jsxTags: {
|
|
238
|
-
description: `If this is set to \`true\`, all of the following tags used to control JSX output are allowed:
|
|
239
|
-
|
|
240
|
-
\`\`\`
|
|
241
|
-
jsx
|
|
242
|
-
jsxFrag
|
|
243
|
-
jsxImportSource
|
|
244
|
-
jsxRuntime
|
|
245
|
-
\`\`\`
|
|
246
|
-
|
|
247
|
-
For more information, see the [babel documentation](https://babeljs.io/docs/en/babel-plugin-transform-react-jsx).`,
|
|
248
|
-
type: 'boolean'
|
|
249
|
-
},
|
|
250
|
-
typed: {
|
|
251
|
-
description: `If this is set to \`true\`, additionally checks for tag names that are redundant when using a type checker such as TypeScript.
|
|
252
|
-
|
|
253
|
-
These tags are always unnecessary when using TypeScript or similar:
|
|
254
|
-
|
|
255
|
-
\`\`\`
|
|
256
|
-
augments
|
|
257
|
-
callback
|
|
258
|
-
class
|
|
259
|
-
enum
|
|
260
|
-
implements
|
|
261
|
-
private
|
|
262
|
-
property
|
|
263
|
-
protected
|
|
264
|
-
public
|
|
265
|
-
readonly
|
|
266
|
-
this
|
|
267
|
-
type
|
|
268
|
-
typedef
|
|
269
|
-
\`\`\`
|
|
270
|
-
|
|
271
|
-
These tags are unnecessary except when inside a TypeScript \`declare\` context:
|
|
272
|
-
|
|
273
|
-
\`\`\`
|
|
274
|
-
abstract
|
|
275
|
-
access
|
|
276
|
-
class
|
|
277
|
-
constant
|
|
278
|
-
constructs
|
|
279
|
-
default
|
|
280
|
-
enum
|
|
281
|
-
export
|
|
282
|
-
exports
|
|
283
|
-
function
|
|
284
|
-
global
|
|
285
|
-
inherits
|
|
286
|
-
instance
|
|
287
|
-
interface
|
|
288
|
-
member
|
|
289
|
-
memberof
|
|
290
|
-
memberOf
|
|
291
|
-
method
|
|
292
|
-
mixes
|
|
293
|
-
mixin
|
|
294
|
-
module
|
|
295
|
-
name
|
|
296
|
-
namespace
|
|
297
|
-
override
|
|
298
|
-
property
|
|
299
|
-
requires
|
|
300
|
-
static
|
|
301
|
-
this
|
|
302
|
-
\`\`\``,
|
|
303
|
-
type: 'boolean'
|
|
304
|
-
}
|
|
305
|
-
},
|
|
306
|
-
type: 'object'
|
|
307
|
-
}],
|
|
308
|
-
type: 'suggestion'
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
module.exports = exports.default;
|
|
312
|
-
//# sourceMappingURL=checkTagNames.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkTagNames.cjs","names":["iterateJsdoc","escapeStringRegexp"],"sources":["../../src/rules/checkTagNames.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\nimport escapeStringRegexp from 'escape-string-regexp';\n\n// https://babeljs.io/docs/en/babel-plugin-transform-react-jsx/\nconst jsxTagNames = new Set([\n 'jsx',\n 'jsxFrag',\n 'jsxImportSource',\n 'jsxRuntime',\n]);\n\nconst typedTagsAlwaysUnnecessary = new Set([\n 'augments',\n 'callback',\n 'class',\n 'enum',\n 'implements',\n 'private',\n 'property',\n 'protected',\n 'public',\n 'readonly',\n 'this',\n 'type',\n 'typedef',\n]);\n\nconst typedTagsNeedingName = new Set([\n 'template',\n]);\n\nconst typedTagsUnnecessaryOutsideDeclare = new Set([\n 'abstract',\n 'access',\n 'class',\n 'constant',\n 'constructs',\n 'default',\n 'enum',\n 'export',\n 'exports',\n 'function',\n 'global',\n 'inherits',\n 'instance',\n 'interface',\n 'member',\n 'memberof',\n 'memberOf',\n 'method',\n 'mixes',\n 'mixin',\n 'module',\n 'name',\n 'namespace',\n 'override',\n 'property',\n 'requires',\n 'static',\n 'this',\n]);\n\nexport default iterateJsdoc(({\n context,\n jsdoc,\n jsdocNode,\n node,\n report,\n settings,\n sourceCode,\n utils,\n}) => {\n const\n /**\n * @type {{\n * definedTags: string[],\n * enableFixer: boolean,\n * inlineTags: string[],\n * jsxTags: boolean,\n * typed: boolean\n }} */ {\n definedTags = [],\n enableFixer = true,\n inlineTags = [\n // jsdoc\n 'link', 'linkcode', 'linkplain', 'tutorial',\n // https://tsdoc.org/pages/spec/tag_kinds/#inline-tags\n 'inheritDoc',\n 'label',\n // https://typedoc.org/documents/Tags.html#inline-tags\n 'include', 'includeCode',\n ],\n jsxTags,\n typed,\n } = context.options[0] || {};\n\n /** @type {(string|undefined)[]} */\n let definedPreferredTags = [];\n const {\n structuredTags,\n tagNamePreference,\n } = settings;\n const definedStructuredTags = Object.keys(structuredTags);\n const definedNonPreferredTags = Object.keys(tagNamePreference);\n if (definedNonPreferredTags.length) {\n definedPreferredTags = Object.values(tagNamePreference).map((preferredTag) => {\n if (typeof preferredTag === 'string') {\n // May become an empty string but will be filtered out below\n return preferredTag;\n }\n\n if (!preferredTag) {\n return undefined;\n }\n\n if (typeof preferredTag !== 'object') {\n utils.reportSettings(\n 'Invalid `settings.jsdoc.tagNamePreference`. Values must be falsy, a string, or an object.',\n );\n }\n\n return preferredTag.replacement;\n })\n .filter(Boolean);\n }\n\n /**\n * @param {import('eslint').Rule.Node} subNode\n * @returns {boolean}\n */\n const isInAmbientContext = (subNode) => {\n return subNode.type === 'Program' ?\n /* c8 ignore next 2 -- Support old ESLint */\n // @ts-expect-error ESLint < 10\n (context.filename ?? context.getFilename()).endsWith('.d.ts') :\n Boolean(\n /** @type {import('@typescript-eslint/types').TSESTree.VariableDeclaration} */ (\n subNode\n ).declare,\n ) || isInAmbientContext(subNode.parent);\n };\n\n /**\n * @param {import('comment-parser').Spec} jsdocTag\n * @returns {boolean}\n */\n const tagIsRedundantWhenTyped = (jsdocTag) => {\n if (!typedTagsUnnecessaryOutsideDeclare.has(jsdocTag.tag)) {\n return false;\n }\n\n if (jsdocTag.tag === 'default') {\n return false;\n }\n\n if (node === null) {\n return false;\n }\n\n /* c8 ignore next 2 -- Support old ESLint */\n // @ts-expect-error ESLint < 10\n if ((context.filename ?? context.getFilename()).endsWith('.d.ts') && [\n null, 'Program', undefined,\n ].includes(node?.parent?.type)) {\n return false;\n }\n\n if (isInAmbientContext(/** @type {import('eslint').Rule.Node} */ (node))) {\n return false;\n }\n\n return true;\n };\n\n /**\n * @param {string} message\n * @param {import('comment-parser').Spec} jsdocTag\n * @param {import('../iterateJsdoc.js').Integer} tagIndex\n * @param {Partial<import('comment-parser').Tokens>} [additionalTagChanges]\n * @returns {void}\n */\n const reportWithTagRemovalFixer = (message, jsdocTag, tagIndex, additionalTagChanges) => {\n utils.reportJSDoc(message, jsdocTag, enableFixer ? () => {\n if (jsdocTag.description.trim()) {\n utils.changeTag(jsdocTag, {\n postType: '',\n type: '',\n ...additionalTagChanges,\n });\n } else {\n utils.removeTag(tagIndex, {\n removeEmptyBlock: true,\n });\n }\n } : null, true);\n };\n\n /**\n * @param {import('comment-parser').Spec} jsdocTag\n * @param {import('../iterateJsdoc.js').Integer} tagIndex\n * @returns {boolean}\n */\n const checkTagForTypedValidity = (jsdocTag, tagIndex) => {\n if (typedTagsAlwaysUnnecessary.has(jsdocTag.tag)) {\n reportWithTagRemovalFixer(\n `'@${jsdocTag.tag}' is redundant when using a type system.`,\n jsdocTag,\n tagIndex,\n {\n postTag: '',\n tag: '',\n },\n );\n return true;\n }\n\n if (tagIsRedundantWhenTyped(jsdocTag)) {\n reportWithTagRemovalFixer(\n `'@${jsdocTag.tag}' is redundant outside of ambient (\\`declare\\`/\\`.d.ts\\`) contexts when using a type system.`,\n jsdocTag,\n tagIndex,\n );\n return true;\n }\n\n if (typedTagsNeedingName.has(jsdocTag.tag) && !jsdocTag.name) {\n reportWithTagRemovalFixer(\n `'@${jsdocTag.tag}' without a name is redundant when using a type system.`,\n jsdocTag,\n tagIndex,\n );\n return true;\n }\n\n return false;\n };\n\n for (let tagIndex = 0; tagIndex < jsdoc.tags.length; tagIndex += 1) {\n const jsdocTag = jsdoc.tags[tagIndex];\n const tagName = jsdocTag.tag;\n if (jsxTags && jsxTagNames.has(tagName)) {\n continue;\n }\n\n if (typed && checkTagForTypedValidity(jsdocTag, tagIndex)) {\n continue;\n }\n\n const validTags = [\n ...definedTags,\n ...(/** @type {string[]} */ (definedPreferredTags)),\n ...definedNonPreferredTags,\n ...definedStructuredTags,\n ...typed ? typedTagsNeedingName : [],\n ];\n\n if (utils.isValidTag(tagName, validTags)) {\n let preferredTagName = utils.getPreferredTagName({\n allowObjectReturn: true,\n defaultMessage: `Blacklisted tag found (\\`@${tagName}\\`)`,\n tagName,\n });\n if (!preferredTagName) {\n continue;\n }\n\n let message;\n if (typeof preferredTagName === 'object') {\n ({\n message,\n replacement: preferredTagName,\n } = /** @type {{message: string; replacement?: string | undefined;}} */ (\n preferredTagName\n ));\n }\n\n if (!message) {\n message = `Invalid JSDoc tag (preference). Replace \"${tagName}\" JSDoc tag with \"${preferredTagName}\".`;\n }\n\n if (preferredTagName !== tagName) {\n report(message, (fixer) => {\n const replacement = sourceCode.getText(jsdocNode).replace(\n new RegExp(`@${escapeStringRegexp(tagName)}\\\\b`, 'v'),\n `@${preferredTagName}`,\n );\n\n return fixer.replaceText(jsdocNode, replacement);\n }, jsdocTag);\n }\n } else {\n report(`Invalid JSDoc tag name \"${tagName}\".`, null, jsdocTag);\n }\n }\n\n for (const inlineTag of utils.getInlineTags()) {\n if (!inlineTags.includes(inlineTag.tag)) {\n report(`Invalid JSDoc inline tag name \"${inlineTag.tag}\"`, null, inlineTag);\n }\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Reports invalid block tag names.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-tag-names.md#repos-sticky-header',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n definedTags: {\n description: `Use an array of \\`definedTags\\` strings to configure additional, allowed tags.\nThe format is as follows:\n\n\\`\\`\\`json\n{\n \"definedTags\": [\"note\", \"record\"]\n}\n\\`\\`\\``,\n items: {\n type: 'string',\n },\n type: 'array',\n },\n enableFixer: {\n description: 'Set to `false` to disable auto-removal of types that are redundant with the [`typed` option](#typed).',\n type: 'boolean',\n },\n inlineTags: {\n description: `List of tags to allow inline.\n\nDefaults to array of \\`'link', 'linkcode', 'linkplain', 'tutorial', 'inheritDoc', 'label', 'include', and 'includeCode'\\``,\n items: {\n type: 'string',\n },\n type: 'array',\n },\n jsxTags: {\n description: `If this is set to \\`true\\`, all of the following tags used to control JSX output are allowed:\n\n\\`\\`\\`\njsx\njsxFrag\njsxImportSource\njsxRuntime\n\\`\\`\\`\n\nFor more information, see the [babel documentation](https://babeljs.io/docs/en/babel-plugin-transform-react-jsx).`,\n type: 'boolean',\n },\n typed: {\n description: `If this is set to \\`true\\`, additionally checks for tag names that are redundant when using a type checker such as TypeScript.\n\nThese tags are always unnecessary when using TypeScript or similar:\n\n\\`\\`\\`\naugments\ncallback\nclass\nenum\nimplements\nprivate\nproperty\nprotected\npublic\nreadonly\nthis\ntype\ntypedef\n\\`\\`\\`\n\nThese tags are unnecessary except when inside a TypeScript \\`declare\\` context:\n\n\\`\\`\\`\nabstract\naccess\nclass\nconstant\nconstructs\ndefault\nenum\nexport\nexports\nfunction\nglobal\ninherits\ninstance\ninterface\nmember\nmemberof\nmemberOf\nmethod\nmixes\nmixin\nmodule\nname\nnamespace\noverride\nproperty\nrequires\nstatic\nthis\n\\`\\`\\``,\n type: 'boolean',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA;AACA;AAAsD;AAEtD;AACA,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAC1B,KAAK,EACL,SAAS,EACT,iBAAiB,EACjB,YAAY,CACb,CAAC;AAEF,MAAM,0BAA0B,GAAG,IAAI,GAAG,CAAC,CACzC,UAAU,EACV,UAAU,EACV,OAAO,EACP,MAAM,EACN,YAAY,EACZ,SAAS,EACT,UAAU,EACV,WAAW,EACX,QAAQ,EACR,UAAU,EACV,MAAM,EACN,MAAM,EACN,SAAS,CACV,CAAC;AAEF,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CACnC,UAAU,CACX,CAAC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A;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;UACK,IAAI,EAAE;QACR;MACF,CAAC;MACD,IAAI,EAAE;IACR,CAAC,CACF;IACD,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAA","ignoreList":[]}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _iterateJsdoc = _interopRequireWildcard(require("../iterateJsdoc.cjs"));
|
|
8
|
-
var _jsdocUtils = require("../jsdocUtils.cjs");
|
|
9
|
-
var _jsdoccomment = require("@es-joy/jsdoccomment");
|
|
10
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
11
|
-
var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
12
|
-
jsdoc,
|
|
13
|
-
node,
|
|
14
|
-
report,
|
|
15
|
-
settings,
|
|
16
|
-
sourceCode,
|
|
17
|
-
utils
|
|
18
|
-
}) => {
|
|
19
|
-
const {
|
|
20
|
-
mode
|
|
21
|
-
} = settings;
|
|
22
|
-
const tgName = /** @type {string} */utils.getPreferredTagName({
|
|
23
|
-
tagName: 'template'
|
|
24
|
-
});
|
|
25
|
-
if (!tgName) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const templateTags = utils.getTags(tgName);
|
|
29
|
-
const usedNames = new Set();
|
|
30
|
-
/**
|
|
31
|
-
* @param {string} potentialType
|
|
32
|
-
*/
|
|
33
|
-
const checkForUsedTypes = potentialType => {
|
|
34
|
-
let parsedType;
|
|
35
|
-
try {
|
|
36
|
-
parsedType = mode === 'permissive' ? (0, _jsdoccomment.tryParse)(/** @type {string} */potentialType) : (0, _jsdoccomment.parse)(/** @type {string} */potentialType, mode);
|
|
37
|
-
} catch {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
(0, _jsdoccomment.traverse)(parsedType, nde => {
|
|
41
|
-
const {
|
|
42
|
-
type,
|
|
43
|
-
value
|
|
44
|
-
} = /** @type {import('jsdoc-type-pratt-parser').NameResult} */nde;
|
|
45
|
-
if (type === 'JsdocTypeName') {
|
|
46
|
-
usedNames.add(value);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
const checkParamsAndReturnsTags = (jsdc = jsdoc) => {
|
|
51
|
-
const paramName = /** @type {string} */utils.getPreferredTagName({
|
|
52
|
-
tagName: 'param'
|
|
53
|
-
});
|
|
54
|
-
const paramTags = (0, _jsdocUtils.getTags)(jsdc, paramName);
|
|
55
|
-
for (const paramTag of paramTags) {
|
|
56
|
-
checkForUsedTypes(paramTag.type);
|
|
57
|
-
}
|
|
58
|
-
const returnsName = /** @type {string} */utils.getPreferredTagName({
|
|
59
|
-
tagName: 'returns'
|
|
60
|
-
});
|
|
61
|
-
const returnsTags = (0, _jsdocUtils.getTags)(jsdc, returnsName);
|
|
62
|
-
for (const returnsTag of returnsTags) {
|
|
63
|
-
checkForUsedTypes(returnsTag.type);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
const checkTemplateTags = () => {
|
|
67
|
-
for (const tag of templateTags) {
|
|
68
|
-
const names = utils.parseClosureTemplateTag(tag);
|
|
69
|
-
for (const nme of names) {
|
|
70
|
-
if (!usedNames.has(nme)) {
|
|
71
|
-
report(`@${tgName} ${nme} not in use`, null, tag);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* @param {import('@typescript-eslint/types').TSESTree.FunctionDeclaration|
|
|
79
|
-
* import('@typescript-eslint/types').TSESTree.ClassDeclaration|
|
|
80
|
-
* import('@typescript-eslint/types').TSESTree.TSInterfaceDeclaration|
|
|
81
|
-
* import('@typescript-eslint/types').TSESTree.TSTypeAliasDeclaration} aliasDeclaration
|
|
82
|
-
* @param {boolean} [checkParamsAndReturns]
|
|
83
|
-
*/
|
|
84
|
-
const checkParameters = (aliasDeclaration, checkParamsAndReturns) => {
|
|
85
|
-
/* c8 ignore next -- Guard */
|
|
86
|
-
const {
|
|
87
|
-
params
|
|
88
|
-
} = aliasDeclaration.typeParameters ?? {
|
|
89
|
-
params: []
|
|
90
|
-
};
|
|
91
|
-
for (const {
|
|
92
|
-
name: {
|
|
93
|
-
name
|
|
94
|
-
}
|
|
95
|
-
} of params) {
|
|
96
|
-
usedNames.add(name);
|
|
97
|
-
}
|
|
98
|
-
if (checkParamsAndReturns) {
|
|
99
|
-
checkParamsAndReturnsTags();
|
|
100
|
-
} else if (aliasDeclaration.type === 'ClassDeclaration') {
|
|
101
|
-
/* c8 ignore next -- TS */
|
|
102
|
-
for (const nde of aliasDeclaration?.body?.body ?? []) {
|
|
103
|
-
const commentNode = (0, _jsdoccomment.getJSDocComment)(sourceCode, nde, settings);
|
|
104
|
-
if (!commentNode) {
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
const innerJsdoc = (0, _iterateJsdoc.parseComment)(commentNode, '');
|
|
108
|
-
checkParamsAndReturnsTags(innerJsdoc);
|
|
109
|
-
const typeName = /** @type {string} */utils.getPreferredTagName({
|
|
110
|
-
tagName: 'type'
|
|
111
|
-
});
|
|
112
|
-
const typeTags = (0, _jsdocUtils.getTags)(innerJsdoc, typeName);
|
|
113
|
-
for (const typeTag of typeTags) {
|
|
114
|
-
checkForUsedTypes(typeTag.type);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Template names may be used only within the heritage clause types of a
|
|
120
|
-
// class/interface, e.g. `@template T` used in `@augments {Base<T>}`.
|
|
121
|
-
for (const heritageTagName of ['augments', 'extends', 'implements']) {
|
|
122
|
-
for (const heritageTag of (0, _jsdocUtils.getTags)(jsdoc, heritageTagName)) {
|
|
123
|
-
checkForUsedTypes(heritageTag.type);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
checkTemplateTags();
|
|
127
|
-
};
|
|
128
|
-
const handleTypeAliases = () => {
|
|
129
|
-
const nde = /** @type {import('@typescript-eslint/types').TSESTree.Node} */
|
|
130
|
-
node;
|
|
131
|
-
if (!nde) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
switch (nde.type) {
|
|
135
|
-
case 'ClassDeclaration':
|
|
136
|
-
case 'TSInterfaceDeclaration':
|
|
137
|
-
case 'TSTypeAliasDeclaration':
|
|
138
|
-
checkParameters(nde);
|
|
139
|
-
break;
|
|
140
|
-
case 'ExportDefaultDeclaration':
|
|
141
|
-
case 'ExportNamedDeclaration':
|
|
142
|
-
switch (nde.declaration?.type) {
|
|
143
|
-
case 'ClassDeclaration':
|
|
144
|
-
case 'TSInterfaceDeclaration':
|
|
145
|
-
case 'TSTypeAliasDeclaration':
|
|
146
|
-
checkParameters(nde.declaration);
|
|
147
|
-
break;
|
|
148
|
-
case 'FunctionDeclaration':
|
|
149
|
-
checkParameters(nde.declaration, true);
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
break;
|
|
153
|
-
case 'FunctionDeclaration':
|
|
154
|
-
checkParameters(nde, true);
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
const callbackTags = utils.getTags('callback');
|
|
159
|
-
const functionTags = utils.getTags('function');
|
|
160
|
-
if (callbackTags.length || functionTags.length) {
|
|
161
|
-
checkParamsAndReturnsTags();
|
|
162
|
-
checkTemplateTags();
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
const typedefTags = utils.getTags('typedef');
|
|
166
|
-
if (!typedefTags.length || typedefTags.length >= 2) {
|
|
167
|
-
handleTypeAliases();
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
const potentialTypedefType = typedefTags[0].type;
|
|
171
|
-
checkForUsedTypes(potentialTypedefType);
|
|
172
|
-
const propertyName = /** @type {string} */utils.getPreferredTagName({
|
|
173
|
-
tagName: 'property'
|
|
174
|
-
});
|
|
175
|
-
const propertyTags = utils.getTags(propertyName);
|
|
176
|
-
for (const propertyTag of propertyTags) {
|
|
177
|
-
checkForUsedTypes(propertyTag.type);
|
|
178
|
-
}
|
|
179
|
-
checkTemplateTags();
|
|
180
|
-
}, {
|
|
181
|
-
iterateAllJsdocs: true,
|
|
182
|
-
meta: {
|
|
183
|
-
docs: {
|
|
184
|
-
description: 'Checks that any `@template` names are actually used in the connected `@typedef` or type alias.',
|
|
185
|
-
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-template-names.md#repos-sticky-header'
|
|
186
|
-
},
|
|
187
|
-
schema: [],
|
|
188
|
-
type: 'suggestion'
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
module.exports = exports.default;
|
|
192
|
-
//# sourceMappingURL=checkTemplateNames.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkTemplateNames.cjs","names":["iterateJsdoc","tryParseType","parseType","traverse","getTags","getJSDocComment","parseComment"],"sources":["../../src/rules/checkTemplateNames.js"],"sourcesContent":["import iterateJsdoc, {\n parseComment,\n} from '../iterateJsdoc.js';\nimport {\n getTags,\n} from '../jsdocUtils.js';\nimport {\n getJSDocComment,\n parse as parseType,\n traverse,\n tryParse as tryParseType,\n} from '@es-joy/jsdoccomment';\n\nexport default iterateJsdoc(({\n jsdoc,\n node,\n report,\n settings,\n sourceCode,\n utils,\n}) => {\n const {\n mode,\n } = settings;\n\n const tgName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'template',\n }));\n if (!tgName) {\n return;\n }\n\n const templateTags = utils.getTags(tgName);\n\n const usedNames = new Set();\n /**\n * @param {string} potentialType\n */\n const checkForUsedTypes = (potentialType) => {\n let parsedType;\n try {\n parsedType = mode === 'permissive' ?\n tryParseType(/** @type {string} */ (potentialType)) :\n parseType(/** @type {string} */ (potentialType), mode);\n } catch {\n return;\n }\n\n traverse(parsedType, (nde) => {\n const {\n type,\n value,\n } = /** @type {import('jsdoc-type-pratt-parser').NameResult} */ (nde);\n if (type === 'JsdocTypeName') {\n usedNames.add(value);\n }\n });\n };\n\n const checkParamsAndReturnsTags = (jsdc = jsdoc) => {\n const paramName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'param',\n }));\n const paramTags = getTags(jsdc, paramName);\n for (const paramTag of paramTags) {\n checkForUsedTypes(paramTag.type);\n }\n\n const returnsName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'returns',\n }));\n const returnsTags = getTags(jsdc, returnsName);\n for (const returnsTag of returnsTags) {\n checkForUsedTypes(returnsTag.type);\n }\n };\n\n const checkTemplateTags = () => {\n for (const tag of templateTags) {\n const names = utils.parseClosureTemplateTag(tag);\n for (const nme of names) {\n if (!usedNames.has(nme)) {\n report(`@${tgName} ${nme} not in use`, null, tag);\n }\n }\n }\n };\n\n /**\n * @param {import('@typescript-eslint/types').TSESTree.FunctionDeclaration|\n * import('@typescript-eslint/types').TSESTree.ClassDeclaration|\n * import('@typescript-eslint/types').TSESTree.TSInterfaceDeclaration|\n * import('@typescript-eslint/types').TSESTree.TSTypeAliasDeclaration} aliasDeclaration\n * @param {boolean} [checkParamsAndReturns]\n */\n const checkParameters = (aliasDeclaration, checkParamsAndReturns) => {\n /* c8 ignore next -- Guard */\n const {\n params,\n } = aliasDeclaration.typeParameters ?? {\n params: [],\n };\n for (const {\n name: {\n name,\n },\n } of params) {\n usedNames.add(name);\n }\n\n if (checkParamsAndReturns) {\n checkParamsAndReturnsTags();\n } else if (aliasDeclaration.type === 'ClassDeclaration') {\n /* c8 ignore next -- TS */\n for (const nde of aliasDeclaration?.body?.body ?? []) {\n const commentNode = getJSDocComment(sourceCode, nde, settings);\n if (!commentNode) {\n continue;\n }\n\n const innerJsdoc = parseComment(commentNode, '');\n checkParamsAndReturnsTags(innerJsdoc);\n\n const typeName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'type',\n }));\n const typeTags = getTags(innerJsdoc, typeName);\n for (const typeTag of typeTags) {\n checkForUsedTypes(typeTag.type);\n }\n }\n }\n\n // Template names may be used only within the heritage clause types of a\n // class/interface, e.g. `@template T` used in `@augments {Base<T>}`.\n for (const heritageTagName of [\n 'augments', 'extends', 'implements',\n ]) {\n for (const heritageTag of getTags(jsdoc, heritageTagName)) {\n checkForUsedTypes(heritageTag.type);\n }\n }\n\n checkTemplateTags();\n };\n\n const handleTypeAliases = () => {\n const nde = /** @type {import('@typescript-eslint/types').TSESTree.Node} */ (\n node\n );\n if (!nde) {\n return;\n }\n\n switch (nde.type) {\n case 'ClassDeclaration':\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n checkParameters(nde);\n break;\n case 'ExportDefaultDeclaration':\n case 'ExportNamedDeclaration':\n switch (nde.declaration?.type) {\n case 'ClassDeclaration':\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n checkParameters(nde.declaration);\n break;\n case 'FunctionDeclaration':\n checkParameters(nde.declaration, true);\n break;\n }\n\n break;\n case 'FunctionDeclaration':\n checkParameters(nde, true);\n break;\n }\n };\n\n const callbackTags = utils.getTags('callback');\n const functionTags = utils.getTags('function');\n if (callbackTags.length || functionTags.length) {\n checkParamsAndReturnsTags();\n checkTemplateTags();\n return;\n }\n\n const typedefTags = utils.getTags('typedef');\n if (!typedefTags.length || typedefTags.length >= 2) {\n handleTypeAliases();\n return;\n }\n\n const potentialTypedefType = typedefTags[0].type;\n checkForUsedTypes(potentialTypedefType);\n\n const propertyName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'property',\n }));\n const propertyTags = utils.getTags(propertyName);\n for (const propertyTag of propertyTags) {\n checkForUsedTypes(propertyTag.type);\n }\n\n checkTemplateTags();\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Checks that any `@template` names are actually used in the connected `@typedef` or type alias.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-template-names.md#repos-sticky-header',\n },\n schema: [],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA;AAGA;AAGA;AAK8B;AAAA,iCAEf,IAAAA,qBAAY,EAAC,CAAC;EAC3B,KAAK;EACL,IAAI;EACJ,MAAM;EACN,QAAQ;EACR,UAAU;EACV;AACF,CAAC,KAAK;EACJ,MAAM;IACJ;EACF,CAAC,GAAG,QAAQ;EAEZ,MAAM,MAAM,GAAG,qBAAuB,KAAK,CAAC,mBAAmB,CAAC;IAC9D,OAAO,EAAE;EACX,CAAC,CAAE;EACH,IAAI,CAAC,MAAM,EAAE;IACX;EACF;EAEA,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;EAE1C,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC;EAC3B;AACF;AACA;EACE,MAAM,iBAAiB,GAAI,aAAa,IAAK;IAC3C,IAAI,UAAU;IACd,IAAI;MACF,UAAU,GAAG,IAAI,KAAK,YAAY,GAChC,IAAAC,sBAAY,EAAC,qBAAuB,aAAc,CAAC,GACnD,IAAAC,mBAAS,EAAC,qBAAuB,aAAa,EAAG,IAAI,CAAC;IAC1D,CAAC,CAAC,MAAM;MACN;IACF;IAEA,IAAAC,cAAA,QA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C,OAAO,CAAC,YAAY,CAAC;EAChD,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE;IACtC,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC;EACrC;EAEA,iBAAiB,CAAC,CAAC;AACrB,CAAC,EAAE;EACD,gBAAgB,EAAE,IAAI;EACtB,IAAI,EAAE;IACJ,IAAI,EAAE;MACJ,WAAW,EAAE,gGAAgG;MAC7G,GAAG,EAAE;IACP,CAAC;IACD,MAAM,EAAE,EAAE;IACV,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAA","ignoreList":[]}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _buildRejectOrPreferRuleDefinition = require("../buildRejectOrPreferRuleDefinition.cjs");
|
|
8
|
-
var _jsdocUtils = require("../jsdocUtils.cjs");
|
|
9
|
-
/**
|
|
10
|
-
* @callback CheckNativeTypes
|
|
11
|
-
* Iterates strict types to see if any should be added to `invalidTypes` (and
|
|
12
|
-
* the the relevant strict type returned as the new preferred type).
|
|
13
|
-
* @param {import('../iterateJsdoc.js').PreferredTypes} preferredTypes
|
|
14
|
-
* @param {string} typeNodeName
|
|
15
|
-
* @param {string|undefined} preferred
|
|
16
|
-
* @param {import('jsdoc-type-pratt-parser').NonRootResult|undefined} parentNode
|
|
17
|
-
* @param {(string|false|undefined)[][]} invalidTypes
|
|
18
|
-
* @returns {string|undefined} The `preferred` type string, optionally changed
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/** @type {CheckNativeTypes} */
|
|
22
|
-
const checkNativeTypes = (preferredTypes, typeNodeName, preferred, parentNode, invalidTypes) => {
|
|
23
|
-
let changedPreferred = preferred;
|
|
24
|
-
for (const strictNativeType of _jsdocUtils.strictNativeTypes) {
|
|
25
|
-
if (strictNativeType === 'object' && (
|
|
26
|
-
// This is not set to remap with exact type match (e.g.,
|
|
27
|
-
// `object: 'Object'`), so can ignore (including if circular)
|
|
28
|
-
!preferredTypes?.[typeNodeName] ||
|
|
29
|
-
// Although present on `preferredTypes` for remapping, this is a
|
|
30
|
-
// parent object without a parent match (and not
|
|
31
|
-
// `unifyParentAndChildTypeChecks`) and we don't want
|
|
32
|
-
// `object<>` given TypeScript issue https://github.com/microsoft/TypeScript/issues/20555
|
|
33
|
-
/**
|
|
34
|
-
* @type {import('jsdoc-type-pratt-parser').GenericResult}
|
|
35
|
-
*/
|
|
36
|
-
parentNode?.elements?.length && (
|
|
37
|
-
/**
|
|
38
|
-
* @type {import('jsdoc-type-pratt-parser').GenericResult}
|
|
39
|
-
*/
|
|
40
|
-
parentNode?.left?.type === 'JsdocTypeName' &&
|
|
41
|
-
/**
|
|
42
|
-
* @type {import('jsdoc-type-pratt-parser').GenericResult}
|
|
43
|
-
*/
|
|
44
|
-
parentNode?.left?.value === 'Object'))) {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
if (strictNativeType !== typeNodeName && strictNativeType.toLowerCase() === typeNodeName.toLowerCase() && (
|
|
48
|
-
// Don't report if user has own map for a strict native type
|
|
49
|
-
!preferredTypes || preferredTypes?.[strictNativeType] === undefined)) {
|
|
50
|
-
changedPreferred = strictNativeType;
|
|
51
|
-
invalidTypes.push([typeNodeName, changedPreferred]);
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return changedPreferred;
|
|
56
|
-
};
|
|
57
|
-
var _default = exports.default = (0, _buildRejectOrPreferRuleDefinition.buildRejectOrPreferRuleDefinition)({
|
|
58
|
-
checkNativeTypes,
|
|
59
|
-
schema: [{
|
|
60
|
-
additionalProperties: false,
|
|
61
|
-
properties: {
|
|
62
|
-
exemptTagContexts: {
|
|
63
|
-
description: 'Avoids reporting when a bad type is found on a specified tag.',
|
|
64
|
-
items: {
|
|
65
|
-
additionalProperties: false,
|
|
66
|
-
properties: {
|
|
67
|
-
tag: {
|
|
68
|
-
description: 'Set a key `tag` to the tag to exempt',
|
|
69
|
-
type: 'string'
|
|
70
|
-
},
|
|
71
|
-
types: {
|
|
72
|
-
description: `Set to \`true\` to indicate that any types on that tag will be allowed,
|
|
73
|
-
or to an array of strings which will only allow specific bad types.
|
|
74
|
-
If an array of strings is given, these must match the type exactly,
|
|
75
|
-
e.g., if you only allow \`"object"\`, it will not allow
|
|
76
|
-
\`"object<string, string>"\`. Note that this is different from the
|
|
77
|
-
behavior of \`settings.jsdoc.preferredTypes\`. This option is useful
|
|
78
|
-
for normally restricting generic types like \`object\` with
|
|
79
|
-
\`preferredTypes\`, but allowing \`typedef\` to indicate that its base
|
|
80
|
-
type is \`object\`.`,
|
|
81
|
-
oneOf: [{
|
|
82
|
-
type: 'boolean'
|
|
83
|
-
}, {
|
|
84
|
-
items: {
|
|
85
|
-
type: 'string'
|
|
86
|
-
},
|
|
87
|
-
type: 'array'
|
|
88
|
-
}]
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
type: 'object'
|
|
92
|
-
},
|
|
93
|
-
type: 'array'
|
|
94
|
-
},
|
|
95
|
-
noDefaults: {
|
|
96
|
-
description: `Insists that only the supplied option type
|
|
97
|
-
map is to be used, and that the default preferences (such as "string"
|
|
98
|
-
over "String") will not be enforced. The option's default is \`false\`.`,
|
|
99
|
-
type: 'boolean'
|
|
100
|
-
},
|
|
101
|
-
unifyParentAndChildTypeChecks: {
|
|
102
|
-
description: `@deprecated Use the \`preferredTypes[preferredType]\` setting of the same name instead.
|
|
103
|
-
If this option is \`true\`, will currently override \`unifyParentAndChildTypeChecks\` on the \`preferredTypes\` setting.`,
|
|
104
|
-
type: 'boolean'
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
type: 'object'
|
|
108
|
-
}]
|
|
109
|
-
});
|
|
110
|
-
module.exports = exports.default;
|
|
111
|
-
//# sourceMappingURL=checkTypes.cjs.map
|