eslint-plugin-jsdoc 39.3.5 → 39.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +273 -52
- package/dist/WarnSettings.js +0 -5
- package/dist/WarnSettings.js.map +1 -1
- package/dist/alignTransform.js +69 -61
- package/dist/alignTransform.js.map +1 -1
- package/dist/bin/generateRule.js +7 -26
- package/dist/bin/generateRule.js.map +1 -1
- package/dist/defaultTagOrder.js +30 -14
- package/dist/defaultTagOrder.js.map +1 -1
- package/dist/exportParser.js +34 -143
- package/dist/exportParser.js.map +1 -1
- package/dist/generateRule.js +7 -26
- package/dist/generateRule.js.map +1 -1
- package/dist/getDefaultTagStructureForMode.js +189 -93
- package/dist/getDefaultTagStructureForMode.js.map +1 -1
- package/dist/index.js +0 -51
- package/dist/index.js.map +1 -1
- package/dist/iterateJsdoc.js +44 -207
- package/dist/iterateJsdoc.js.map +1 -1
- package/dist/jsdocUtils.js +72 -221
- package/dist/jsdocUtils.js.map +1 -1
- package/dist/rules/checkAccess.js +0 -8
- package/dist/rules/checkAccess.js.map +1 -1
- package/dist/rules/checkAlignment.js +0 -8
- package/dist/rules/checkAlignment.js.map +1 -1
- package/dist/rules/checkExamples.js +25 -63
- package/dist/rules/checkExamples.js.map +1 -1
- package/dist/rules/checkIndentation.js +0 -7
- package/dist/rules/checkIndentation.js.map +1 -1
- package/dist/rules/checkLineAlignment.js +9 -30
- package/dist/rules/checkLineAlignment.js.map +1 -1
- package/dist/rules/checkParamNames.js +9 -47
- package/dist/rules/checkParamNames.js.map +1 -1
- package/dist/rules/checkPropertyNames.js +1 -18
- package/dist/rules/checkPropertyNames.js.map +1 -1
- package/dist/rules/checkSyntax.js +2 -5
- package/dist/rules/checkSyntax.js.map +1 -1
- package/dist/rules/checkTagNames.js +0 -18
- package/dist/rules/checkTagNames.js.map +1 -1
- package/dist/rules/checkTypes.js +17 -46
- package/dist/rules/checkTypes.js.map +1 -1
- package/dist/rules/checkValues.js +0 -18
- package/dist/rules/checkValues.js.map +1 -1
- package/dist/rules/emptyTags.js +6 -11
- package/dist/rules/emptyTags.js.map +1 -1
- package/dist/rules/implementsOnClasses.js +0 -6
- package/dist/rules/implementsOnClasses.js.map +1 -1
- package/dist/rules/matchDescription.js +0 -20
- package/dist/rules/matchDescription.js.map +1 -1
- package/dist/rules/matchName.js +2 -17
- package/dist/rules/matchName.js.map +1 -1
- package/dist/rules/multilineBlocks.js +10 -34
- package/dist/rules/multilineBlocks.js.map +1 -1
- package/dist/rules/newlineAfterDescription.js +0 -8
- package/dist/rules/newlineAfterDescription.js.map +1 -1
- package/dist/rules/noBadBlocks.js +2 -16
- package/dist/rules/noBadBlocks.js.map +1 -1
- package/dist/rules/noDefaults.js +0 -7
- package/dist/rules/noDefaults.js.map +1 -1
- package/dist/rules/noMissingSyntax.js +2 -16
- package/dist/rules/noMissingSyntax.js.map +1 -1
- package/dist/rules/noMultiAsterisks.js +2 -16
- package/dist/rules/noMultiAsterisks.js.map +1 -1
- package/dist/rules/noRestrictedSyntax.js +3 -9
- package/dist/rules/noRestrictedSyntax.js.map +1 -1
- package/dist/rules/noTypes.js +0 -7
- package/dist/rules/noTypes.js.map +1 -1
- package/dist/rules/noUndefinedTypes.js +13 -34
- package/dist/rules/noUndefinedTypes.js.map +1 -1
- package/dist/rules/requireAsteriskPrefix.js +2 -26
- package/dist/rules/requireAsteriskPrefix.js.map +1 -1
- package/dist/rules/requireDescription.js +0 -17
- package/dist/rules/requireDescription.js.map +1 -1
- package/dist/rules/requireDescriptionCompleteSentence.js +13 -34
- package/dist/rules/requireDescriptionCompleteSentence.js.map +1 -1
- package/dist/rules/requireExample.js +0 -9
- package/dist/rules/requireExample.js.map +1 -1
- package/dist/rules/requireFileOverview.js +0 -16
- package/dist/rules/requireFileOverview.js.map +1 -1
- package/dist/rules/requireHyphenBeforeParamDescription.js +2 -16
- package/dist/rules/requireHyphenBeforeParamDescription.js.map +1 -1
- package/dist/rules/requireJsdoc.js +13 -58
- package/dist/rules/requireJsdoc.js.map +1 -1
- package/dist/rules/requireParam.js +6 -53
- package/dist/rules/requireParam.js.map +1 -1
- package/dist/rules/requireParamDescription.js +0 -4
- package/dist/rules/requireParamDescription.js.map +1 -1
- package/dist/rules/requireParamName.js +0 -4
- package/dist/rules/requireParamName.js.map +1 -1
- package/dist/rules/requireParamType.js +0 -4
- package/dist/rules/requireParamType.js.map +1 -1
- package/dist/rules/requireProperty.js +0 -9
- package/dist/rules/requireProperty.js.map +1 -1
- package/dist/rules/requirePropertyDescription.js +0 -4
- package/dist/rules/requirePropertyDescription.js.map +1 -1
- package/dist/rules/requirePropertyName.js +0 -4
- package/dist/rules/requirePropertyName.js.map +1 -1
- package/dist/rules/requirePropertyType.js +0 -4
- package/dist/rules/requirePropertyType.js.map +1 -1
- package/dist/rules/requireReturns.js +13 -23
- package/dist/rules/requireReturns.js.map +1 -1
- package/dist/rules/requireReturnsCheck.js +12 -20
- package/dist/rules/requireReturnsCheck.js.map +1 -1
- package/dist/rules/requireReturnsDescription.js +0 -6
- package/dist/rules/requireReturnsDescription.js.map +1 -1
- package/dist/rules/requireReturnsType.js +0 -4
- package/dist/rules/requireReturnsType.js.map +1 -1
- package/dist/rules/requireThrows.js +6 -15
- package/dist/rules/requireThrows.js.map +1 -1
- package/dist/rules/requireYields.js +13 -29
- package/dist/rules/requireYields.js.map +1 -1
- package/dist/rules/requireYieldsCheck.js +8 -29
- package/dist/rules/requireYieldsCheck.js.map +1 -1
- package/dist/rules/sortTags.js +17 -30
- package/dist/rules/sortTags.js.map +1 -1
- package/dist/rules/tagLines.js +0 -26
- package/dist/rules/tagLines.js.map +1 -1
- package/dist/rules/validTypes.js +22 -53
- package/dist/rules/validTypes.js.map +1 -1
- package/dist/tagNames.js +7 -4
- package/dist/tagNames.js.map +1 -1
- package/dist/utils/hasReturnValue.js +22 -66
- package/dist/utils/hasReturnValue.js.map +1 -1
- package/package.json +16 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requireAsteriskPrefix.js","names":["iterateJsdoc","context","jsdoc","utils","indent","defaultRequireValue","tags","tagMap","options","source","always","never","currentTag","some","number","tokens","delimiter","tag","end","description","neverFix","postDelimiter","checkNever","checkValue","includes","reportJSDoc","column","line","alwaysFix","start","checkAlways","slice","any","iterateAllJsdocs","meta","fixable","schema","enum","type","additionalProperties","properties","items"],"sources":["../../src/rules/requireAsteriskPrefix.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc';\n\nexport default iterateJsdoc(({\n context,\n jsdoc,\n utils,\n indent,\n}) => {\n const [\n defaultRequireValue = 'always',\n {\n tags: tagMap = {},\n } = {},\n ] = context.options;\n\n const {\n source,\n } = jsdoc;\n\n const always = defaultRequireValue === 'always';\n const never = defaultRequireValue === 'never';\n\n let currentTag;\n source.some(({\n number,\n tokens,\n }) => {\n const {\n delimiter,\n tag,\n end,\n description,\n } = tokens;\n\n const neverFix = () => {\n tokens.delimiter = '';\n tokens.postDelimiter = '';\n };\n\n const checkNever = (checkValue) => {\n if (delimiter && delimiter !== '/**' && (\n never && !tagMap.always?.includes(checkValue) ||\n tagMap.never?.includes(checkValue)\n )) {\n utils.reportJSDoc('Expected JSDoc line to have no prefix.', {\n column: 0,\n line: number,\n }, neverFix);\n\n return true;\n }\n\n return false;\n };\n\n const alwaysFix = () => {\n if (!tokens.start) {\n tokens.start = indent + ' ';\n }\n\n tokens.delimiter = '*';\n tokens.postDelimiter = tag || description ? ' ' : '';\n };\n\n const checkAlways = (checkValue) => {\n if (\n !delimiter && (\n always && !tagMap.never?.includes(checkValue) ||\n tagMap.always?.includes(checkValue)\n )\n ) {\n utils.reportJSDoc('Expected JSDoc line to have the prefix.', {\n column: 0,\n line: number,\n }, alwaysFix);\n\n return true;\n }\n\n return false;\n };\n\n if (tag) {\n // Remove at sign\n currentTag = tag.slice(1);\n }\n\n if (\n // If this is the end but has a tag, the delimiter will also be\n // populated and will be safely ignored later\n end && !tag\n ) {\n return false;\n }\n\n if (!currentTag) {\n if (tagMap.any?.includes('*description')) {\n return false;\n }\n\n if (checkNever('*description')) {\n return true;\n }\n\n if (checkAlways('*description')) {\n return true;\n }\n\n return false;\n }\n\n if (tagMap.any?.includes(currentTag)) {\n return false;\n }\n\n if (checkNever(currentTag)) {\n return true;\n }\n\n if (checkAlways(currentTag)) {\n return true;\n }\n\n return false;\n });\n}, {\n iterateAllJsdocs: true,\n meta: {\n fixable: 'code',\n schema: [\n {\n enum: [\n 'always', 'never', 'any',\n ],\n type: 'string',\n },\n {\n additionalProperties: false,\n properties: {\n tags: {\n properties: {\n always: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n any: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n never: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n },\n type: 'object',\n },\n ],\n type: 'layout',\n },\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"requireAsteriskPrefix.js","names":["iterateJsdoc","context","jsdoc","utils","indent","defaultRequireValue","tags","tagMap","options","source","always","never","currentTag","some","number","tokens","delimiter","tag","end","description","neverFix","postDelimiter","checkNever","checkValue","includes","reportJSDoc","column","line","alwaysFix","start","checkAlways","slice","any","iterateAllJsdocs","meta","fixable","schema","enum","type","additionalProperties","properties","items"],"sources":["../../src/rules/requireAsteriskPrefix.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc';\n\nexport default iterateJsdoc(({\n context,\n jsdoc,\n utils,\n indent,\n}) => {\n const [\n defaultRequireValue = 'always',\n {\n tags: tagMap = {},\n } = {},\n ] = context.options;\n\n const {\n source,\n } = jsdoc;\n\n const always = defaultRequireValue === 'always';\n const never = defaultRequireValue === 'never';\n\n let currentTag;\n source.some(({\n number,\n tokens,\n }) => {\n const {\n delimiter,\n tag,\n end,\n description,\n } = tokens;\n\n const neverFix = () => {\n tokens.delimiter = '';\n tokens.postDelimiter = '';\n };\n\n const checkNever = (checkValue) => {\n if (delimiter && delimiter !== '/**' && (\n never && !tagMap.always?.includes(checkValue) ||\n tagMap.never?.includes(checkValue)\n )) {\n utils.reportJSDoc('Expected JSDoc line to have no prefix.', {\n column: 0,\n line: number,\n }, neverFix);\n\n return true;\n }\n\n return false;\n };\n\n const alwaysFix = () => {\n if (!tokens.start) {\n tokens.start = indent + ' ';\n }\n\n tokens.delimiter = '*';\n tokens.postDelimiter = tag || description ? ' ' : '';\n };\n\n const checkAlways = (checkValue) => {\n if (\n !delimiter && (\n always && !tagMap.never?.includes(checkValue) ||\n tagMap.always?.includes(checkValue)\n )\n ) {\n utils.reportJSDoc('Expected JSDoc line to have the prefix.', {\n column: 0,\n line: number,\n }, alwaysFix);\n\n return true;\n }\n\n return false;\n };\n\n if (tag) {\n // Remove at sign\n currentTag = tag.slice(1);\n }\n\n if (\n // If this is the end but has a tag, the delimiter will also be\n // populated and will be safely ignored later\n end && !tag\n ) {\n return false;\n }\n\n if (!currentTag) {\n if (tagMap.any?.includes('*description')) {\n return false;\n }\n\n if (checkNever('*description')) {\n return true;\n }\n\n if (checkAlways('*description')) {\n return true;\n }\n\n return false;\n }\n\n if (tagMap.any?.includes(currentTag)) {\n return false;\n }\n\n if (checkNever(currentTag)) {\n return true;\n }\n\n if (checkAlways(currentTag)) {\n return true;\n }\n\n return false;\n });\n}, {\n iterateAllJsdocs: true,\n meta: {\n fixable: 'code',\n schema: [\n {\n enum: [\n 'always', 'never', 'any',\n ],\n type: 'string',\n },\n {\n additionalProperties: false,\n properties: {\n tags: {\n properties: {\n always: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n any: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n never: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n },\n type: 'object',\n },\n ],\n type: 'layout',\n },\n});\n"],"mappings":";;;;;;AAAA;AAA2C;AAAA,eAE5B,IAAAA,qBAAY,EAAC,CAAC;EAC3BC,OAAO;EACPC,KAAK;EACLC,KAAK;EACLC;AACF,CAAC,KAAK;EAC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EAAE;IACJC,OAAO,EAAE,MAAM;IACfC,MAAM,EAAE,CACN;MACEC,IAAI,EAAE,CACJ,QAAQ,EAAE,OAAO,EAAE,KAAK,CACzB;MACDC,IAAI,EAAE;IACR,CAAC,EACD;MACEC,oBAAoB,EAAE,KAAK;MAC3BC,UAAU,EAAE;QACVlC,IAAI,EAAE;UACJkC,UAAU,EAAE;YACV9B,MAAM,EAAE;cACN+B,KAAK,EAAE;gBACLH,IAAI,EAAE;cACR,CAAC;cACDA,IAAI,EAAE;YACR,CAAC;YACDN,GAAG,EAAE;cACHS,KAAK,EAAE;gBACLH,IAAI,EAAE;cACR,CAAC;cACDA,IAAI,EAAE;YACR,CAAC;YACD3B,KAAK,EAAE;cACL8B,KAAK,EAAE;gBACLH,IAAI,EAAE;cACR,CAAC;cACDA,IAAI,EAAE;YACR;UACF,CAAC;UACDA,IAAI,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAA;AAAA"}
|
|
@@ -4,15 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _iterateJsdoc = _interopRequireDefault(require("../iterateJsdoc"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
const checkDescription = description => {
|
|
13
10
|
return description.trim().split('\n').filter(Boolean).length;
|
|
14
11
|
};
|
|
15
|
-
|
|
16
12
|
var _default = (0, _iterateJsdoc.default)(({
|
|
17
13
|
jsdoc,
|
|
18
14
|
report,
|
|
@@ -22,7 +18,6 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
22
18
|
if (utils.avoidDocs()) {
|
|
23
19
|
return;
|
|
24
20
|
}
|
|
25
|
-
|
|
26
21
|
const {
|
|
27
22
|
descriptionStyle = 'body'
|
|
28
23
|
} = context.options[0] || {};
|
|
@@ -34,29 +29,22 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
34
29
|
skipReportingBlockedTag: descriptionStyle !== 'tag',
|
|
35
30
|
tagName: 'description'
|
|
36
31
|
});
|
|
37
|
-
|
|
38
32
|
if (!targetTagName) {
|
|
39
33
|
return;
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
const isBlocked = typeof targetTagName === 'object' && targetTagName.blocked;
|
|
43
|
-
|
|
44
36
|
if (isBlocked) {
|
|
45
37
|
targetTagName = targetTagName.tagName;
|
|
46
38
|
}
|
|
47
|
-
|
|
48
39
|
if (descriptionStyle !== 'tag') {
|
|
49
40
|
const {
|
|
50
41
|
description
|
|
51
42
|
} = utils.getDescription();
|
|
52
|
-
|
|
53
43
|
if (checkDescription(description || '')) {
|
|
54
44
|
return;
|
|
55
45
|
}
|
|
56
|
-
|
|
57
46
|
if (descriptionStyle === 'body') {
|
|
58
47
|
const descTags = utils.getPresentTags(['desc', 'description']);
|
|
59
|
-
|
|
60
48
|
if (descTags.length) {
|
|
61
49
|
const [{
|
|
62
50
|
tag: tagName
|
|
@@ -65,22 +53,18 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
65
53
|
} else {
|
|
66
54
|
report('Missing JSDoc block description.');
|
|
67
55
|
}
|
|
68
|
-
|
|
69
56
|
return;
|
|
70
57
|
}
|
|
71
58
|
}
|
|
72
|
-
|
|
73
59
|
const functionExamples = isBlocked ? [] : jsdoc.tags.filter(({
|
|
74
60
|
tag
|
|
75
61
|
}) => {
|
|
76
62
|
return tag === targetTagName;
|
|
77
63
|
});
|
|
78
|
-
|
|
79
64
|
if (!functionExamples.length) {
|
|
80
65
|
report(descriptionStyle === 'any' ? `Missing JSDoc block description or @${targetTagName} declaration.` : `Missing JSDoc @${targetTagName} declaration.`);
|
|
81
66
|
return;
|
|
82
67
|
}
|
|
83
|
-
|
|
84
68
|
for (const example of functionExamples) {
|
|
85
69
|
if (!checkDescription(`${example.name} ${utils.getTagDescription(example)}`)) {
|
|
86
70
|
report(`Missing JSDoc @${targetTagName} description.`, null, example);
|
|
@@ -143,7 +127,6 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
143
127
|
type: 'suggestion'
|
|
144
128
|
}
|
|
145
129
|
});
|
|
146
|
-
|
|
147
130
|
exports.default = _default;
|
|
148
131
|
module.exports = exports.default;
|
|
149
132
|
//# sourceMappingURL=requireDescription.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requireDescription.js","names":["checkDescription","description","trim","split","filter","Boolean","length","iterateJsdoc","jsdoc","report","utils","context","avoidDocs","descriptionStyle","options","targetTagName","getPreferredTagName","skipReportingBlockedTag","tagName","isBlocked","blocked","getDescription","descTags","getPresentTags","tag","functionExamples","tags","example","name","getTagDescription","contextDefaults","meta","docs","url","schema","additionalProperties","properties","checkConstructors","default","type","checkGetters","checkSetters","contexts","items","anyOf","comment","enum","exemptedBy"],"sources":["../../src/rules/requireDescription.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc';\n\nconst checkDescription = (description) => {\n return description\n .trim()\n .split('\\n')\n .filter(Boolean)\n .length;\n};\n\nexport default iterateJsdoc(({\n jsdoc,\n report,\n utils,\n context,\n}) => {\n if (utils.avoidDocs()) {\n return;\n }\n\n const {\n descriptionStyle = 'body',\n } = context.options[0] || {};\n\n let targetTagName = utils.getPreferredTagName({\n // We skip reporting except when `@description` is essential to the rule,\n // so user can block the tag and still meaningfully use this rule\n // even if the tag is present (and `check-tag-names` is the one to\n // normally report the fact that it is blocked but present)\n skipReportingBlockedTag: descriptionStyle !== 'tag',\n tagName: 'description',\n });\n if (!targetTagName) {\n return;\n }\n\n const isBlocked = typeof targetTagName === 'object' && targetTagName.blocked;\n if (isBlocked) {\n targetTagName = targetTagName.tagName;\n }\n\n if (descriptionStyle !== 'tag') {\n const {\n description,\n } = utils.getDescription();\n if (checkDescription(description || '')) {\n return;\n }\n\n if (descriptionStyle === 'body') {\n const descTags = utils.getPresentTags([\n 'desc', 'description',\n ]);\n if (descTags.length) {\n const [\n {\n tag: tagName,\n },\n ] = descTags;\n report(`Remove the @${tagName} tag to leave a plain block description or add additional description text above the @${tagName} line.`);\n } else {\n report('Missing JSDoc block description.');\n }\n\n return;\n }\n }\n\n const functionExamples = isBlocked ?\n [] :\n jsdoc.tags.filter(({\n tag,\n }) => {\n return tag === targetTagName;\n });\n\n if (!functionExamples.length) {\n report(\n descriptionStyle === 'any' ?\n `Missing JSDoc block description or @${targetTagName} declaration.` :\n `Missing JSDoc @${targetTagName} declaration.`,\n );\n\n return;\n }\n\n for (const example of functionExamples) {\n if (!checkDescription(`${example.name} ${utils.getTagDescription(example)}`)) {\n report(`Missing JSDoc @${targetTagName} description.`, null, example);\n }\n }\n}, {\n contextDefaults: true,\n meta: {\n docs: {\n description: 'Requires that all functions have a description.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-description',\n },\n schema: [\n {\n additionalProperties: false,\n properties: {\n checkConstructors: {\n default: true,\n type: 'boolean',\n },\n checkGetters: {\n default: true,\n type: 'boolean',\n },\n checkSetters: {\n default: true,\n type: 'boolean',\n },\n contexts: {\n items: {\n anyOf: [\n {\n type: 'string',\n },\n {\n additionalProperties: false,\n properties: {\n comment: {\n type: 'string',\n },\n context: {\n type: 'string',\n },\n },\n type: 'object',\n },\n ],\n },\n type: 'array',\n },\n descriptionStyle: {\n enum: [\n 'body', 'tag', 'any',\n ],\n type: 'string',\n },\n exemptedBy: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"requireDescription.js","names":["checkDescription","description","trim","split","filter","Boolean","length","iterateJsdoc","jsdoc","report","utils","context","avoidDocs","descriptionStyle","options","targetTagName","getPreferredTagName","skipReportingBlockedTag","tagName","isBlocked","blocked","getDescription","descTags","getPresentTags","tag","functionExamples","tags","example","name","getTagDescription","contextDefaults","meta","docs","url","schema","additionalProperties","properties","checkConstructors","default","type","checkGetters","checkSetters","contexts","items","anyOf","comment","enum","exemptedBy"],"sources":["../../src/rules/requireDescription.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc';\n\nconst checkDescription = (description) => {\n return description\n .trim()\n .split('\\n')\n .filter(Boolean)\n .length;\n};\n\nexport default iterateJsdoc(({\n jsdoc,\n report,\n utils,\n context,\n}) => {\n if (utils.avoidDocs()) {\n return;\n }\n\n const {\n descriptionStyle = 'body',\n } = context.options[0] || {};\n\n let targetTagName = utils.getPreferredTagName({\n // We skip reporting except when `@description` is essential to the rule,\n // so user can block the tag and still meaningfully use this rule\n // even if the tag is present (and `check-tag-names` is the one to\n // normally report the fact that it is blocked but present)\n skipReportingBlockedTag: descriptionStyle !== 'tag',\n tagName: 'description',\n });\n if (!targetTagName) {\n return;\n }\n\n const isBlocked = typeof targetTagName === 'object' && targetTagName.blocked;\n if (isBlocked) {\n targetTagName = targetTagName.tagName;\n }\n\n if (descriptionStyle !== 'tag') {\n const {\n description,\n } = utils.getDescription();\n if (checkDescription(description || '')) {\n return;\n }\n\n if (descriptionStyle === 'body') {\n const descTags = utils.getPresentTags([\n 'desc', 'description',\n ]);\n if (descTags.length) {\n const [\n {\n tag: tagName,\n },\n ] = descTags;\n report(`Remove the @${tagName} tag to leave a plain block description or add additional description text above the @${tagName} line.`);\n } else {\n report('Missing JSDoc block description.');\n }\n\n return;\n }\n }\n\n const functionExamples = isBlocked ?\n [] :\n jsdoc.tags.filter(({\n tag,\n }) => {\n return tag === targetTagName;\n });\n\n if (!functionExamples.length) {\n report(\n descriptionStyle === 'any' ?\n `Missing JSDoc block description or @${targetTagName} declaration.` :\n `Missing JSDoc @${targetTagName} declaration.`,\n );\n\n return;\n }\n\n for (const example of functionExamples) {\n if (!checkDescription(`${example.name} ${utils.getTagDescription(example)}`)) {\n report(`Missing JSDoc @${targetTagName} description.`, null, example);\n }\n }\n}, {\n contextDefaults: true,\n meta: {\n docs: {\n description: 'Requires that all functions have a description.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-description',\n },\n schema: [\n {\n additionalProperties: false,\n properties: {\n checkConstructors: {\n default: true,\n type: 'boolean',\n },\n checkGetters: {\n default: true,\n type: 'boolean',\n },\n checkSetters: {\n default: true,\n type: 'boolean',\n },\n contexts: {\n items: {\n anyOf: [\n {\n type: 'string',\n },\n {\n additionalProperties: false,\n properties: {\n comment: {\n type: 'string',\n },\n context: {\n type: 'string',\n },\n },\n type: 'object',\n },\n ],\n },\n type: 'array',\n },\n descriptionStyle: {\n enum: [\n 'body', 'tag', 'any',\n ],\n type: 'string',\n },\n exemptedBy: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA;AAA2C;AAE3C,MAAMA,gBAAgB,GAAIC,WAAW,IAAK;EACxC,OAAOA,WAAW,CACfC,IAAI,EAAE,CACNC,KAAK,CAAC,IAAI,CAAC,CACXC,MAAM,CAACC,OAAO,CAAC,CACfC,MAAM;AACX,CAAC;AAAC,eAEa,IAAAC,qBAAY,EAAC,CAAC;EAC3BC,KAAK;EACLC,MAAM;EACNC,KAAK;EACLC;AACF,CAAC,KAAK;EACJ,IAAID,KAAK,CAACE,SAAS,EAAE,EAAE;IACrB;EACF;EAEA,MAAM;IACJC,gBAAgB,GAAG;EACrB,CAAC,GAAGF,OAAO,CAACG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;EAE5B,IAAIC,aAAa,GAAGL,KAAK,CAACM,mBAAmB,CAAC;IAC5C;IACA;IACA;IACA;IACAC,uBAAuB,EAAEJ,gBAAgB,KAAK,KAAK;IACnDK,OAAO,EAAE;EACX,CAAC,CAAC;EACF,IAAI,CAACH,aAAa,EAAE;IAClB;EACF;EAEA,MAAMI,SAAS,GAAG,OAAOJ,aAAa,KA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IACvE;EACF;AACF,CAAC,EAAE;EACDG,eAAe,EAAE,IAAI;EACrBC,IAAI,EAAE;IACJC,IAAI,EAAE;MACJ/B,WAAW,EAAE,iDAAiD;MAC9DgC,GAAG,EAAE;IACP,CAAC;IACDC,MAAM,EAAE,CACN;MACEC,oBAAoB,EAAE,KAAK;MAC3BC,UAAU,EAAE;QACVC,iBAAiB,EAAE;UACjBC,OAAO,EAAE,IAAI;UACbC,IAAI,EAAE;QACR,CAAC;QACDC,YAAY,EAAE;UACZF,OAAO,EAAE,IAAI;UACbC,IAAI,EAAE;QACR,CAAC;QACDE,YAAY,EAAE;UACZH,OAAO,EAAE,IAAI;UACbC,IAAI,EAAE;QACR,CAAC;QACDG,QAAQ,EAAE;UACRC,KAAK,EAAE;YACLC,KAAK,EAAE,CACL;cACEL,IAAI,EAAE;YACR,CAAC,EACD;cACEJ,oBAAoB,EAAE,KAAK;cAC3BC,UAAU,EAAE;gBACVS,OAAO,EAAE;kBACPN,IAAI,EAAE;gBACR,CAAC;gBACD5B,OAAO,EAAE;kBACP4B,IAAI,EAAE;gBACR;cACF,CAAC;cACDA,IAAI,EAAE;YACR,CAAC;UAEL,CAAC;UACDA,IAAI,EAAE;QACR,CAAC;QACD1B,gBAAgB,EAAE;UAChBiC,IAAI,EAAE,CACJ,MAAM,EAAE,KAAK,EAAE,KAAK,CACrB;UACDP,IAAI,EAAE;QACR,CAAC;QACDQ,UAAU,EAAE;UACVJ,KAAK,EAAE;YACLJ,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAA;AAAA"}
|
|
@@ -4,34 +4,34 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _escapeStringRegexp = _interopRequireDefault(require("escape-string-regexp"));
|
|
9
|
-
|
|
10
8
|
var _iterateJsdoc = _interopRequireDefault(require("../iterateJsdoc"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const otherDescriptiveTags = new Set([
|
|
11
|
+
// 'copyright' and 'see' might be good addition, but as the former may be
|
|
15
12
|
// sensitive text, and the latter may have just a link, they are not
|
|
16
13
|
// included by default
|
|
17
14
|
'summary', 'file', 'fileoverview', 'overview', 'classdesc', 'todo', 'deprecated', 'throws', 'exception', 'yields', 'yield']);
|
|
18
|
-
|
|
19
15
|
const extractParagraphs = text => {
|
|
20
16
|
return text.split(/(?<![;:])\n\n/u);
|
|
21
17
|
};
|
|
22
|
-
|
|
23
18
|
const extractSentences = (text, abbreviationsRegex) => {
|
|
24
|
-
const txt = text
|
|
25
|
-
|
|
19
|
+
const txt = text
|
|
20
|
+
|
|
21
|
+
// Remove all {} tags.
|
|
22
|
+
.replace(/\{[\s\S]*?\}\s*/gu, '')
|
|
23
|
+
|
|
24
|
+
// Remove custom abbreviations
|
|
26
25
|
.replace(abbreviationsRegex, '');
|
|
27
26
|
const sentenceEndGrouping = /([.?!])(?:\s+|$)/ug;
|
|
28
27
|
const puncts = txt.matchAll(sentenceEndGrouping);
|
|
29
|
-
return txt.split(/[.?!](?:\s+|$)/u)
|
|
28
|
+
return txt.split(/[.?!](?:\s+|$)/u)
|
|
29
|
+
|
|
30
|
+
// Re-add the dot.
|
|
30
31
|
.map((sentence, idx) => {
|
|
31
32
|
return /^\s*$/u.test(sentence) ? sentence : `${sentence}${puncts[idx] || ''}`;
|
|
32
33
|
});
|
|
33
34
|
};
|
|
34
|
-
|
|
35
35
|
const isNewLinePrecededByAPeriod = text => {
|
|
36
36
|
let lastLineEndsSentence;
|
|
37
37
|
const lines = text.split('\n');
|
|
@@ -39,46 +39,36 @@ const isNewLinePrecededByAPeriod = text => {
|
|
|
39
39
|
if (lastLineEndsSentence === false && /^[A-Z][a-z]/u.test(line)) {
|
|
40
40
|
return true;
|
|
41
41
|
}
|
|
42
|
-
|
|
43
42
|
lastLineEndsSentence = /[.:?!|]$/u.test(line);
|
|
44
43
|
return false;
|
|
45
44
|
});
|
|
46
45
|
};
|
|
47
|
-
|
|
48
46
|
const isCapitalized = str => {
|
|
49
47
|
return str[0] === str[0].toUpperCase();
|
|
50
48
|
};
|
|
51
|
-
|
|
52
49
|
const isTable = str => {
|
|
53
50
|
return str.charAt() === '|';
|
|
54
51
|
};
|
|
55
|
-
|
|
56
52
|
const capitalize = str => {
|
|
57
53
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
58
54
|
};
|
|
59
|
-
|
|
60
55
|
const validateDescription = (description, reportOrig, jsdocNode, abbreviationsRegex, sourceCode, tag, newlineBeforeCapsAssumesBadSentenceEnd) => {
|
|
61
56
|
if (!description || /^\n+$/u.test(description)) {
|
|
62
57
|
return false;
|
|
63
58
|
}
|
|
64
|
-
|
|
65
59
|
const paragraphs = extractParagraphs(description);
|
|
66
60
|
return paragraphs.some((paragraph, parIdx) => {
|
|
67
61
|
const sentences = extractSentences(paragraph, abbreviationsRegex);
|
|
68
|
-
|
|
69
62
|
const fix = fixer => {
|
|
70
63
|
let text = sourceCode.getText(jsdocNode);
|
|
71
|
-
|
|
72
64
|
if (!/[.:?!]$/u.test(paragraph)) {
|
|
73
65
|
const line = paragraph.split('\n').pop();
|
|
74
66
|
text = text.replace(new RegExp(`${(0, _escapeStringRegexp.default)(line)}$`, 'mu'), `${line}.`);
|
|
75
67
|
}
|
|
76
|
-
|
|
77
68
|
for (const sentence of sentences.filter(sentence_ => {
|
|
78
69
|
return !/^\s*$/u.test(sentence_) && !isCapitalized(sentence_) && !isTable(sentence_);
|
|
79
70
|
})) {
|
|
80
71
|
const beginning = sentence.split('\n')[0];
|
|
81
|
-
|
|
82
72
|
if (tag.tag) {
|
|
83
73
|
const reg = new RegExp(`(@${(0, _escapeStringRegexp.default)(tag.tag)}.*)${(0, _escapeStringRegexp.default)(beginning)}`, 'u');
|
|
84
74
|
text = text.replace(reg, (_$0, $1) => {
|
|
@@ -88,44 +78,36 @@ const validateDescription = (description, reportOrig, jsdocNode, abbreviationsRe
|
|
|
88
78
|
text = text.replace(new RegExp('((?:[.!?]|\\*|\\})\\s*)' + (0, _escapeStringRegexp.default)(beginning), 'u'), '$1' + capitalize(beginning));
|
|
89
79
|
}
|
|
90
80
|
}
|
|
91
|
-
|
|
92
81
|
return fixer.replaceText(jsdocNode, text);
|
|
93
82
|
};
|
|
94
|
-
|
|
95
83
|
const report = (msg, fixer, tagObj) => {
|
|
96
84
|
if ('line' in tagObj) {
|
|
97
85
|
tagObj.line += parIdx * 2;
|
|
98
86
|
} else {
|
|
99
87
|
tagObj.source[0].number += parIdx * 2;
|
|
100
|
-
}
|
|
101
|
-
|
|
88
|
+
}
|
|
102
89
|
|
|
90
|
+
// Avoid errors if old column doesn't exist here
|
|
103
91
|
tagObj.column = 0;
|
|
104
92
|
reportOrig(msg, fixer, tagObj);
|
|
105
93
|
};
|
|
106
|
-
|
|
107
94
|
if (sentences.some(sentence => {
|
|
108
95
|
return !/^\s*$/u.test(sentence) && !isCapitalized(sentence) && !isTable(sentence);
|
|
109
96
|
})) {
|
|
110
97
|
report('Sentence should start with an uppercase character.', fix, tag);
|
|
111
98
|
}
|
|
112
|
-
|
|
113
99
|
const paragraphNoAbbreviations = paragraph.replace(abbreviationsRegex, '');
|
|
114
|
-
|
|
115
100
|
if (!/[.!?|]\s*$/u.test(paragraphNoAbbreviations)) {
|
|
116
101
|
report('Sentence must end with a period.', fix, tag);
|
|
117
102
|
return true;
|
|
118
103
|
}
|
|
119
|
-
|
|
120
104
|
if (newlineBeforeCapsAssumesBadSentenceEnd && !isNewLinePrecededByAPeriod(paragraphNoAbbreviations)) {
|
|
121
105
|
report('A line of text is started with an uppercase character, but preceding line does not end the sentence.', null, tag);
|
|
122
106
|
return true;
|
|
123
107
|
}
|
|
124
|
-
|
|
125
108
|
return false;
|
|
126
109
|
});
|
|
127
110
|
};
|
|
128
|
-
|
|
129
111
|
var _default = (0, _iterateJsdoc.default)(({
|
|
130
112
|
sourceCode,
|
|
131
113
|
context,
|
|
@@ -145,13 +127,11 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
145
127
|
const {
|
|
146
128
|
description
|
|
147
129
|
} = utils.getDescription();
|
|
148
|
-
|
|
149
130
|
if (validateDescription(description, report, jsdocNode, abbreviationsRegex, sourceCode, {
|
|
150
131
|
line: jsdoc.source[0].number + 1
|
|
151
132
|
}, newlineBeforeCapsAssumesBadSentenceEnd)) {
|
|
152
133
|
return;
|
|
153
134
|
}
|
|
154
|
-
|
|
155
135
|
utils.forEachPreferredTag('description', matchingJsdocTag => {
|
|
156
136
|
const desc = `${matchingJsdocTag.name} ${utils.getTagDescription(matchingJsdocTag)}`.trim();
|
|
157
137
|
validateDescription(desc, report, jsdocNode, abbreviationsRegex, sourceCode, matchingJsdocTag, newlineBeforeCapsAssumesBadSentenceEnd);
|
|
@@ -210,7 +190,6 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
210
190
|
type: 'suggestion'
|
|
211
191
|
}
|
|
212
192
|
});
|
|
213
|
-
|
|
214
193
|
exports.default = _default;
|
|
215
194
|
module.exports = exports.default;
|
|
216
195
|
//# sourceMappingURL=requireDescriptionCompleteSentence.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requireDescriptionCompleteSentence.js","names":["otherDescriptiveTags","Set","extractParagraphs","text","split","extractSentences","abbreviationsRegex","txt","replace","sentenceEndGrouping","puncts","matchAll","map","sentence","idx","test","isNewLinePrecededByAPeriod","lastLineEndsSentence","lines","some","line","isCapitalized","str","toUpperCase","isTable","charAt","capitalize","slice","validateDescription","description","reportOrig","jsdocNode","sourceCode","tag","newlineBeforeCapsAssumesBadSentenceEnd","paragraphs","paragraph","parIdx","sentences","fix","fixer","getText","pop","RegExp","escapeStringRegexp","filter","sentence_","beginning","reg","_$0","$1","replaceText","report","msg","tagObj","source","number","column","paragraphNoAbbreviations","iterateJsdoc","context","jsdoc","utils","options","abbreviations","length","abbreviation","join","getDescription","forEachPreferredTag","matchingJsdocTag","desc","name","getTagDescription","trim","tagsWithNames","getTagsByType","tags","tagsWithoutNames","filterTags","tagName","has","hasOptionTag","trimEnd","iterateAllJsdocs","meta","docs","url","fixable","schema","additionalProperties","properties","items","type"],"sources":["../../src/rules/requireDescriptionCompleteSentence.js"],"sourcesContent":["import escapeStringRegexp from 'escape-string-regexp';\nimport iterateJsdoc from '../iterateJsdoc';\n\nconst otherDescriptiveTags = new Set([\n // 'copyright' and 'see' might be good addition, but as the former may be\n // sensitive text, and the latter may have just a link, they are not\n // included by default\n 'summary', 'file', 'fileoverview', 'overview', 'classdesc', 'todo',\n 'deprecated', 'throws', 'exception', 'yields', 'yield',\n]);\n\nconst extractParagraphs = (text) => {\n return text.split(/(?<![;:])\\n\\n/u);\n};\n\nconst extractSentences = (text, abbreviationsRegex) => {\n const txt = text\n\n // Remove all {} tags.\n .replace(/\\{[\\s\\S]*?\\}\\s*/gu, '')\n\n // Remove custom abbreviations\n .replace(abbreviationsRegex, '');\n\n const sentenceEndGrouping = /([.?!])(?:\\s+|$)/ug;\n\n const puncts = txt.matchAll(sentenceEndGrouping);\n\n return txt\n\n .split(/[.?!](?:\\s+|$)/u)\n\n // Re-add the dot.\n .map((sentence, idx) => {\n return /^\\s*$/u.test(sentence) ? sentence : `${sentence}${puncts[idx] || ''}`;\n });\n};\n\nconst isNewLinePrecededByAPeriod = (text) => {\n let lastLineEndsSentence;\n\n const lines = text.split('\\n');\n\n return !lines.some((line) => {\n if (lastLineEndsSentence === false && /^[A-Z][a-z]/u.test(line)) {\n return true;\n }\n\n lastLineEndsSentence = /[.:?!|]$/u.test(line);\n\n return false;\n });\n};\n\nconst isCapitalized = (str) => {\n return str[0] === str[0].toUpperCase();\n};\n\nconst isTable = (str) => {\n return str.charAt() === '|';\n};\n\nconst capitalize = (str) => {\n return str.charAt(0).toUpperCase() + str.slice(1);\n};\n\nconst validateDescription = (\n description, reportOrig, jsdocNode, abbreviationsRegex,\n sourceCode, tag, newlineBeforeCapsAssumesBadSentenceEnd,\n) => {\n if (!description || (/^\\n+$/u).test(description)) {\n return false;\n }\n\n const paragraphs = extractParagraphs(description);\n\n return paragraphs.some((paragraph, parIdx) => {\n const sentences = extractSentences(paragraph, abbreviationsRegex);\n\n const fix = (fixer) => {\n let text = sourceCode.getText(jsdocNode);\n\n if (!/[.:?!]$/u.test(paragraph)) {\n const line = paragraph.split('\\n').pop();\n\n text = text.replace(new RegExp(`${escapeStringRegexp(line)}$`, 'mu'), `${line}.`);\n }\n\n for (const sentence of sentences.filter((sentence_) => {\n return !(/^\\s*$/u).test(sentence_) && !isCapitalized(sentence_) &&\n !isTable(sentence_);\n })) {\n const beginning = sentence.split('\\n')[0];\n\n if (tag.tag) {\n const reg = new RegExp(`(@${escapeStringRegexp(tag.tag)}.*)${escapeStringRegexp(beginning)}`, 'u');\n\n text = text.replace(reg, (_$0, $1) => {\n return $1 + capitalize(beginning);\n });\n } else {\n text = text.replace(new RegExp('((?:[.!?]|\\\\*|\\\\})\\\\s*)' + escapeStringRegexp(beginning), 'u'), '$1' + capitalize(beginning));\n }\n }\n\n return fixer.replaceText(jsdocNode, text);\n };\n\n const report = (msg, fixer, tagObj) => {\n if ('line' in tagObj) {\n tagObj.line += parIdx * 2;\n } else {\n tagObj.source[0].number += parIdx * 2;\n }\n\n // Avoid errors if old column doesn't exist here\n tagObj.column = 0;\n reportOrig(msg, fixer, tagObj);\n };\n\n if (sentences.some((sentence) => {\n return !(/^\\s*$/u).test(sentence) && !isCapitalized(sentence) && !isTable(sentence);\n })) {\n report('Sentence should start with an uppercase character.', fix, tag);\n }\n\n const paragraphNoAbbreviations = paragraph.replace(abbreviationsRegex, '');\n\n if (!/[.!?|]\\s*$/u.test(paragraphNoAbbreviations)) {\n report('Sentence must end with a period.', fix, tag);\n\n return true;\n }\n\n if (newlineBeforeCapsAssumesBadSentenceEnd && !isNewLinePrecededByAPeriod(paragraphNoAbbreviations)) {\n report('A line of text is started with an uppercase character, but preceding line does not end the sentence.', null, tag);\n\n return true;\n }\n\n return false;\n });\n};\n\nexport default iterateJsdoc(({\n sourceCode,\n context,\n jsdoc,\n report,\n jsdocNode,\n utils,\n}) => {\n const options = context.options[0] || {};\n const {\n abbreviations = [],\n newlineBeforeCapsAssumesBadSentenceEnd = false,\n } = options;\n\n const abbreviationsRegex = abbreviations.length ?\n new RegExp('\\\\b' + abbreviations.map((abbreviation) => {\n return escapeStringRegexp(abbreviation.replace(/\\.$/ug, '') + '.');\n }).join('|') + '(?:$|\\\\s)', 'gu') :\n '';\n\n const {\n description,\n } = utils.getDescription();\n\n if (validateDescription(description, report, jsdocNode, abbreviationsRegex, sourceCode, {\n line: jsdoc.source[0].number + 1,\n }, newlineBeforeCapsAssumesBadSentenceEnd)) {\n return;\n }\n\n utils.forEachPreferredTag('description', (matchingJsdocTag) => {\n const desc = `${matchingJsdocTag.name} ${utils.getTagDescription(matchingJsdocTag)}`.trim();\n validateDescription(desc, report, jsdocNode, abbreviationsRegex, sourceCode, matchingJsdocTag, newlineBeforeCapsAssumesBadSentenceEnd);\n }, true);\n\n const {\n tagsWithNames,\n } = utils.getTagsByType(jsdoc.tags);\n const tagsWithoutNames = utils.filterTags(({\n tag: tagName,\n }) => {\n return otherDescriptiveTags.has(tagName) ||\n utils.hasOptionTag(tagName) && !tagsWithNames.some(({\n tag,\n }) => {\n // If user accidentally adds tags with names (or like `returns`\n // get parsed as having names), do not add to this list\n return tag === tagName;\n });\n });\n\n tagsWithNames.some((tag) => {\n const desc = utils.getTagDescription(tag).replace(/^- /u, '').trimEnd();\n\n return validateDescription(desc, report, jsdocNode, abbreviationsRegex, sourceCode, tag, newlineBeforeCapsAssumesBadSentenceEnd);\n });\n\n tagsWithoutNames.some((tag) => {\n const desc = `${tag.name} ${utils.getTagDescription(tag)}`.trim();\n\n return validateDescription(desc, report, jsdocNode, abbreviationsRegex, sourceCode, tag, newlineBeforeCapsAssumesBadSentenceEnd);\n });\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Requires that block description, explicit `@description`, and `@param`/`@returns` tag descriptions are written in complete sentences.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-description-complete-sentence',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n abbreviations: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n newlineBeforeCapsAssumesBadSentenceEnd: {\n type: 'boolean',\n },\n tags: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA,MAAMA,oBAAoB,GAAG,IAAIC,GAAJ,CAAQ,CACnC;AACA;AACA;AACA,SAJmC,EAIxB,MAJwB,EAIhB,cAJgB,EAIA,UAJA,EAIY,WAJZ,EAIyB,MAJzB,EAKnC,YALmC,EAKrB,QALqB,EAKX,WALW,EAKE,QALF,EAKY,OALZ,CAAR,CAA7B;;AAQA,MAAMC,iBAAiB,GAAIC,IAAD,IAAU;EAClC,OAAOA,IAAI,CAACC,KAAL,CAAW,gBAAX,CAAP;AACD,CAFD;;AAIA,MAAMC,gBAAgB,GAAG,CAACF,IAAD,EAAOG,kBAAP,KAA8B;EACrD,MAAMC,GAAG,GAAGJ,IAAI,CAEd;EAFc,CAGbK,OAHS,CAGD,mBAHC,EAGoB,EAHpB,EAKV;EALU,CAMTA,OANS,CAMDF,kBANC,EAMmB,EANnB,CAAZ;EAQA,MAAMG,mBAAmB,GAAG,oBAA5B;EAEA,MAAMC,MAAM,GAAGH,GAAG,CAACI,QAAJ,CAAaF,mBAAb,CAAf;EAEA,OAAOF,GAAG,CAEPH,KAFI,CAEE,iBAFF,EAIL;EAJK,CAKJQ,GALI,CAKA,CAACC,QAAD,EAAWC,GAAX,KAAmB;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;IAEA,OAAO9C,mBAAmB,CAAC2C,IAAD,EAAOnB,MAAP,EAAerB,SAAf,EAA0BzB,kBAA1B,EAA8C0B,UAA9C,EAA0DC,GAA1D,EAA+DC,sCAA/D,CAA1B;EACD,CAJD;AAKD,CA9Dc,EA8DZ;EACDkD,gBAAgB,EAAE,IADjB;EAEDC,IAAI,EAAE;IACJC,IAAI,EAAE;MACJzD,WAAW,EAAE,uIADT;MAEJ0D,GAAG,EAAE;IAFD,CADF;IAKJC,OAAO,EAAE,MALL;IAMJC,MAAM,EAAE,CACN;MACEC,oBAAoB,EAAE,KADxB;MAEEC,UAAU,EAAE;QACV3B,aAAa,EAAE;UACb4B,KAAK,EAAE;YACLC,IAAI,EAAE;UADD,CADM;UAIbA,IAAI,EAAE;QAJO,CADL;QAOV3D,sCAAsC,EAAE;UACtC2D,IAAI,EAAE;QADgC,CAP9B;QAUVhB,IAAI,EAAE;UACJe,KAAK,EAAE;YACLC,IAAI,EAAE;UADD,CADH;UAIJA,IAAI,EAAE;QAJF;MAVI,CAFd;MAmBEA,IAAI,EAAE;IAnBR,CADM,CANJ;IA6BJA,IAAI,EAAE;EA7BF;AAFL,CA9DY,C"}
|
|
1
|
+
{"version":3,"file":"requireDescriptionCompleteSentence.js","names":["otherDescriptiveTags","Set","extractParagraphs","text","split","extractSentences","abbreviationsRegex","txt","replace","sentenceEndGrouping","puncts","matchAll","map","sentence","idx","test","isNewLinePrecededByAPeriod","lastLineEndsSentence","lines","some","line","isCapitalized","str","toUpperCase","isTable","charAt","capitalize","slice","validateDescription","description","reportOrig","jsdocNode","sourceCode","tag","newlineBeforeCapsAssumesBadSentenceEnd","paragraphs","paragraph","parIdx","sentences","fix","fixer","getText","pop","RegExp","escapeStringRegexp","filter","sentence_","beginning","reg","_$0","$1","replaceText","report","msg","tagObj","source","number","column","paragraphNoAbbreviations","iterateJsdoc","context","jsdoc","utils","options","abbreviations","length","abbreviation","join","getDescription","forEachPreferredTag","matchingJsdocTag","desc","name","getTagDescription","trim","tagsWithNames","getTagsByType","tags","tagsWithoutNames","filterTags","tagName","has","hasOptionTag","trimEnd","iterateAllJsdocs","meta","docs","url","fixable","schema","additionalProperties","properties","items","type"],"sources":["../../src/rules/requireDescriptionCompleteSentence.js"],"sourcesContent":["import escapeStringRegexp from 'escape-string-regexp';\nimport iterateJsdoc from '../iterateJsdoc';\n\nconst otherDescriptiveTags = new Set([\n // 'copyright' and 'see' might be good addition, but as the former may be\n // sensitive text, and the latter may have just a link, they are not\n // included by default\n 'summary', 'file', 'fileoverview', 'overview', 'classdesc', 'todo',\n 'deprecated', 'throws', 'exception', 'yields', 'yield',\n]);\n\nconst extractParagraphs = (text) => {\n return text.split(/(?<![;:])\\n\\n/u);\n};\n\nconst extractSentences = (text, abbreviationsRegex) => {\n const txt = text\n\n // Remove all {} tags.\n .replace(/\\{[\\s\\S]*?\\}\\s*/gu, '')\n\n // Remove custom abbreviations\n .replace(abbreviationsRegex, '');\n\n const sentenceEndGrouping = /([.?!])(?:\\s+|$)/ug;\n\n const puncts = txt.matchAll(sentenceEndGrouping);\n\n return txt\n\n .split(/[.?!](?:\\s+|$)/u)\n\n // Re-add the dot.\n .map((sentence, idx) => {\n return /^\\s*$/u.test(sentence) ? sentence : `${sentence}${puncts[idx] || ''}`;\n });\n};\n\nconst isNewLinePrecededByAPeriod = (text) => {\n let lastLineEndsSentence;\n\n const lines = text.split('\\n');\n\n return !lines.some((line) => {\n if (lastLineEndsSentence === false && /^[A-Z][a-z]/u.test(line)) {\n return true;\n }\n\n lastLineEndsSentence = /[.:?!|]$/u.test(line);\n\n return false;\n });\n};\n\nconst isCapitalized = (str) => {\n return str[0] === str[0].toUpperCase();\n};\n\nconst isTable = (str) => {\n return str.charAt() === '|';\n};\n\nconst capitalize = (str) => {\n return str.charAt(0).toUpperCase() + str.slice(1);\n};\n\nconst validateDescription = (\n description, reportOrig, jsdocNode, abbreviationsRegex,\n sourceCode, tag, newlineBeforeCapsAssumesBadSentenceEnd,\n) => {\n if (!description || (/^\\n+$/u).test(description)) {\n return false;\n }\n\n const paragraphs = extractParagraphs(description);\n\n return paragraphs.some((paragraph, parIdx) => {\n const sentences = extractSentences(paragraph, abbreviationsRegex);\n\n const fix = (fixer) => {\n let text = sourceCode.getText(jsdocNode);\n\n if (!/[.:?!]$/u.test(paragraph)) {\n const line = paragraph.split('\\n').pop();\n\n text = text.replace(new RegExp(`${escapeStringRegexp(line)}$`, 'mu'), `${line}.`);\n }\n\n for (const sentence of sentences.filter((sentence_) => {\n return !(/^\\s*$/u).test(sentence_) && !isCapitalized(sentence_) &&\n !isTable(sentence_);\n })) {\n const beginning = sentence.split('\\n')[0];\n\n if (tag.tag) {\n const reg = new RegExp(`(@${escapeStringRegexp(tag.tag)}.*)${escapeStringRegexp(beginning)}`, 'u');\n\n text = text.replace(reg, (_$0, $1) => {\n return $1 + capitalize(beginning);\n });\n } else {\n text = text.replace(new RegExp('((?:[.!?]|\\\\*|\\\\})\\\\s*)' + escapeStringRegexp(beginning), 'u'), '$1' + capitalize(beginning));\n }\n }\n\n return fixer.replaceText(jsdocNode, text);\n };\n\n const report = (msg, fixer, tagObj) => {\n if ('line' in tagObj) {\n tagObj.line += parIdx * 2;\n } else {\n tagObj.source[0].number += parIdx * 2;\n }\n\n // Avoid errors if old column doesn't exist here\n tagObj.column = 0;\n reportOrig(msg, fixer, tagObj);\n };\n\n if (sentences.some((sentence) => {\n return !(/^\\s*$/u).test(sentence) && !isCapitalized(sentence) && !isTable(sentence);\n })) {\n report('Sentence should start with an uppercase character.', fix, tag);\n }\n\n const paragraphNoAbbreviations = paragraph.replace(abbreviationsRegex, '');\n\n if (!/[.!?|]\\s*$/u.test(paragraphNoAbbreviations)) {\n report('Sentence must end with a period.', fix, tag);\n\n return true;\n }\n\n if (newlineBeforeCapsAssumesBadSentenceEnd && !isNewLinePrecededByAPeriod(paragraphNoAbbreviations)) {\n report('A line of text is started with an uppercase character, but preceding line does not end the sentence.', null, tag);\n\n return true;\n }\n\n return false;\n });\n};\n\nexport default iterateJsdoc(({\n sourceCode,\n context,\n jsdoc,\n report,\n jsdocNode,\n utils,\n}) => {\n const options = context.options[0] || {};\n const {\n abbreviations = [],\n newlineBeforeCapsAssumesBadSentenceEnd = false,\n } = options;\n\n const abbreviationsRegex = abbreviations.length ?\n new RegExp('\\\\b' + abbreviations.map((abbreviation) => {\n return escapeStringRegexp(abbreviation.replace(/\\.$/ug, '') + '.');\n }).join('|') + '(?:$|\\\\s)', 'gu') :\n '';\n\n const {\n description,\n } = utils.getDescription();\n\n if (validateDescription(description, report, jsdocNode, abbreviationsRegex, sourceCode, {\n line: jsdoc.source[0].number + 1,\n }, newlineBeforeCapsAssumesBadSentenceEnd)) {\n return;\n }\n\n utils.forEachPreferredTag('description', (matchingJsdocTag) => {\n const desc = `${matchingJsdocTag.name} ${utils.getTagDescription(matchingJsdocTag)}`.trim();\n validateDescription(desc, report, jsdocNode, abbreviationsRegex, sourceCode, matchingJsdocTag, newlineBeforeCapsAssumesBadSentenceEnd);\n }, true);\n\n const {\n tagsWithNames,\n } = utils.getTagsByType(jsdoc.tags);\n const tagsWithoutNames = utils.filterTags(({\n tag: tagName,\n }) => {\n return otherDescriptiveTags.has(tagName) ||\n utils.hasOptionTag(tagName) && !tagsWithNames.some(({\n tag,\n }) => {\n // If user accidentally adds tags with names (or like `returns`\n // get parsed as having names), do not add to this list\n return tag === tagName;\n });\n });\n\n tagsWithNames.some((tag) => {\n const desc = utils.getTagDescription(tag).replace(/^- /u, '').trimEnd();\n\n return validateDescription(desc, report, jsdocNode, abbreviationsRegex, sourceCode, tag, newlineBeforeCapsAssumesBadSentenceEnd);\n });\n\n tagsWithoutNames.some((tag) => {\n const desc = `${tag.name} ${utils.getTagDescription(tag)}`.trim();\n\n return validateDescription(desc, report, jsdocNode, abbreviationsRegex, sourceCode, tag, newlineBeforeCapsAssumesBadSentenceEnd);\n });\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Requires that block description, explicit `@description`, and `@param`/`@returns` tag descriptions are written in complete sentences.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-description-complete-sentence',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n abbreviations: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n newlineBeforeCapsAssumesBadSentenceEnd: {\n type: 'boolean',\n },\n tags: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA;AACA;AAA2C;AAE3C,MAAMA,oBAAoB,GAAG,IAAIC,GAAG,CAAC;AACnC;AACA;AACA;AACA,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAClE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,CACvD,CAAC;AAEF,MAAMC,iBAAiB,GAAIC,IAAI,IAAK;EAClC,OAAOA,IAAI,CAACC,KAAK,CAAC,gBAAgB,CAAC;AACrC,CAAC;AAED,MAAMC,gBAAgB,GAAG,CAACF,IAAI,EAAEG,kBAAkB,KAAK;EACrD,MAAMC,GAAG,GAAGJ;;EAEV;EAAA,CACCK,OAAO,CAAC,mBAAmB,EAAE,EAAE;;EAEhC;EAAA,CACCA,OAAO,CAACF,kBAAkB,EAAE,EAAE,CAAC;EAElC,MAAMG,mBAAmB,GAAG,oBAAoB;EAEhD,MAAMC,MAAM,GAAGH,GAAG,CAACI,QAAQ,CAACF,mBAAmB,CAAC;EAEhD,OAAOF,GAAG,CAEPH,KAAK,CAAC,iBAAiB;;EAExB;EAAA,CACCQ,GAAG,CAAC,CAACC,QAAQ,EAAEC,GAAG,KAAK;IACtB,OAAO,QAAQ,CAACC,IAAI,CAACF,QAAQ,CAAC,GAAGA,QAAQ,GAAI,GAAEA,QAAS,GAAEH,MAAM,CAACI,GAAG,CAAC,IAAI,EAAG,EAAC;EAC/E,CAAC,CAAC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AE;MACJzD,WAAW,EAAE,uIAAuI;MACpJ0D,GAAG,EAAE;IACP,CAAC;IACDC,OAAO,EAAE,MAAM;IACfC,MAAM,EAAE,CACN;MACEC,oBAAoB,EAAE,KAAK;MAC3BC,UAAU,EAAE;QACV3B,aAAa,EAAE;UACb4B,KAAK,EAAE;YACLC,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR,CAAC;QACD3D,sCAAsC,EAAE;UACtC2D,IAAI,EAAE;QACR,CAAC;QACDhB,IAAI,EAAE;UACJe,KAAK,EAAE;YACLC,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAA;AAAA"}
|
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _iterateJsdoc = _interopRequireDefault(require("../iterateJsdoc"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
var _default = (0, _iterateJsdoc.default)(({
|
|
13
10
|
context,
|
|
14
11
|
jsdoc,
|
|
@@ -18,7 +15,6 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
18
15
|
if (utils.avoidDocs()) {
|
|
19
16
|
return;
|
|
20
17
|
}
|
|
21
|
-
|
|
22
18
|
const {
|
|
23
19
|
enableFixer = true,
|
|
24
20
|
exemptNoArguments = false
|
|
@@ -29,12 +25,10 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
29
25
|
}) => {
|
|
30
26
|
return tag === targetTagName;
|
|
31
27
|
});
|
|
32
|
-
|
|
33
28
|
if (!functionExamples.length) {
|
|
34
29
|
if (exemptNoArguments && utils.isIteratingFunction() && !utils.hasParams()) {
|
|
35
30
|
return;
|
|
36
31
|
}
|
|
37
|
-
|
|
38
32
|
utils.reportJSDoc(`Missing JSDoc @${targetTagName} declaration.`, null, () => {
|
|
39
33
|
if (enableFixer) {
|
|
40
34
|
utils.addTag(targetTagName);
|
|
@@ -42,10 +36,8 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
42
36
|
});
|
|
43
37
|
return;
|
|
44
38
|
}
|
|
45
|
-
|
|
46
39
|
for (const example of functionExamples) {
|
|
47
40
|
const exampleContent = `${example.name} ${utils.getTagDescription(example)}`.trim().split('\n').filter(Boolean);
|
|
48
|
-
|
|
49
41
|
if (!exampleContent.length) {
|
|
50
42
|
report(`Missing JSDoc @${targetTagName} description.`, null, example);
|
|
51
43
|
}
|
|
@@ -112,7 +104,6 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
112
104
|
type: 'suggestion'
|
|
113
105
|
}
|
|
114
106
|
});
|
|
115
|
-
|
|
116
107
|
exports.default = _default;
|
|
117
108
|
module.exports = exports.default;
|
|
118
109
|
//# sourceMappingURL=requireExample.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requireExample.js","names":["iterateJsdoc","context","jsdoc","report","utils","avoidDocs","enableFixer","exemptNoArguments","options","targetTagName","functionExamples","tags","filter","tag","length","isIteratingFunction","hasParams","reportJSDoc","addTag","example","exampleContent","name","getTagDescription","trim","split","Boolean","contextDefaults","meta","docs","description","url","fixable","schema","additionalProperties","properties","checkConstructors","default","type","checkGetters","checkSetters","contexts","items","anyOf","comment","exemptedBy"],"sources":["../../src/rules/requireExample.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc';\n\nexport default iterateJsdoc(({\n context,\n jsdoc,\n report,\n utils,\n}) => {\n if (utils.avoidDocs()) {\n return;\n }\n\n const {\n enableFixer = true,\n exemptNoArguments = false,\n } = context.options[0] || {};\n\n const targetTagName = 'example';\n\n const functionExamples = jsdoc.tags.filter(({\n tag,\n }) => {\n return tag === targetTagName;\n });\n\n if (!functionExamples.length) {\n if (exemptNoArguments && utils.isIteratingFunction() &&\n !utils.hasParams()\n ) {\n return;\n }\n\n utils.reportJSDoc(`Missing JSDoc @${targetTagName} declaration.`, null, () => {\n if (enableFixer) {\n utils.addTag(targetTagName);\n }\n });\n\n return;\n }\n\n for (const example of functionExamples) {\n const exampleContent = `${example.name} ${utils.getTagDescription(example)}`\n .trim()\n .split('\\n')\n .filter(Boolean);\n\n if (!exampleContent.length) {\n report(`Missing JSDoc @${targetTagName} description.`, null, example);\n }\n }\n}, {\n contextDefaults: true,\n meta: {\n docs: {\n description: 'Requires that all functions have examples.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-example',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n checkConstructors: {\n default: true,\n type: 'boolean',\n },\n checkGetters: {\n default: false,\n type: 'boolean',\n },\n checkSetters: {\n default: false,\n type: 'boolean',\n },\n contexts: {\n items: {\n anyOf: [\n {\n type: 'string',\n },\n {\n additionalProperties: false,\n properties: {\n comment: {\n type: 'string',\n },\n context: {\n type: 'string',\n },\n },\n type: 'object',\n },\n ],\n },\n type: 'array',\n },\n enableFixer: {\n default: true,\n type: 'boolean',\n },\n exemptedBy: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n exemptNoArguments: {\n default: false,\n type: 'boolean',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"requireExample.js","names":["iterateJsdoc","context","jsdoc","report","utils","avoidDocs","enableFixer","exemptNoArguments","options","targetTagName","functionExamples","tags","filter","tag","length","isIteratingFunction","hasParams","reportJSDoc","addTag","example","exampleContent","name","getTagDescription","trim","split","Boolean","contextDefaults","meta","docs","description","url","fixable","schema","additionalProperties","properties","checkConstructors","default","type","checkGetters","checkSetters","contexts","items","anyOf","comment","exemptedBy"],"sources":["../../src/rules/requireExample.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc';\n\nexport default iterateJsdoc(({\n context,\n jsdoc,\n report,\n utils,\n}) => {\n if (utils.avoidDocs()) {\n return;\n }\n\n const {\n enableFixer = true,\n exemptNoArguments = false,\n } = context.options[0] || {};\n\n const targetTagName = 'example';\n\n const functionExamples = jsdoc.tags.filter(({\n tag,\n }) => {\n return tag === targetTagName;\n });\n\n if (!functionExamples.length) {\n if (exemptNoArguments && utils.isIteratingFunction() &&\n !utils.hasParams()\n ) {\n return;\n }\n\n utils.reportJSDoc(`Missing JSDoc @${targetTagName} declaration.`, null, () => {\n if (enableFixer) {\n utils.addTag(targetTagName);\n }\n });\n\n return;\n }\n\n for (const example of functionExamples) {\n const exampleContent = `${example.name} ${utils.getTagDescription(example)}`\n .trim()\n .split('\\n')\n .filter(Boolean);\n\n if (!exampleContent.length) {\n report(`Missing JSDoc @${targetTagName} description.`, null, example);\n }\n }\n}, {\n contextDefaults: true,\n meta: {\n docs: {\n description: 'Requires that all functions have examples.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-example',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n checkConstructors: {\n default: true,\n type: 'boolean',\n },\n checkGetters: {\n default: false,\n type: 'boolean',\n },\n checkSetters: {\n default: false,\n type: 'boolean',\n },\n contexts: {\n items: {\n anyOf: [\n {\n type: 'string',\n },\n {\n additionalProperties: false,\n properties: {\n comment: {\n type: 'string',\n },\n context: {\n type: 'string',\n },\n },\n type: 'object',\n },\n ],\n },\n type: 'array',\n },\n enableFixer: {\n default: true,\n type: 'boolean',\n },\n exemptedBy: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n exemptNoArguments: {\n default: false,\n type: 'boolean',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA;AAA2C;AAAA,eAE5B,IAAAA,qBAAY,EAAC,CAAC;EAC3BC,OAAO;EACPC,KAAK;EACLC,MAAM;EACNC;AACF,CA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C,MAAM,EAAE,CACN;MACEC,oBAAoB,EAAE,KAAK;MAC3BC,UAAU,EAAE;QACVC,iBAAiB,EAAE;UACjBC,OAAO,EAAE,IAAI;UACbC,IAAI,EAAE;QACR,CAAC;QACDC,YAAY,EAAE;UACZF,OAAO,EAAE,KAAK;UACdC,IAAI,EAAE;QACR,CAAC;QACDE,YAAY,EAAE;UACZH,OAAO,EAAE,KAAK;UACdC,IAAI,EAAE;QACR,CAAC;QACDG,QAAQ,EAAE;UACRC,KAAK,EAAE;YACLC,KAAK,EAAE,CACL;cACEL,IAAI,EAAE;YACR,CAAC,EACD;cACEJ,oBAAoB,EAAE,KAAK;cAC3BC,UAAU,EAAE;gBACVS,OAAO,EAAE;kBACPN,IAAI,EAAE;gBACR,CAAC;gBACDpC,OAAO,EAAE;kBACPoC,IAAI,EAAE;gBACR;cACF,CAAC;cACDA,IAAI,EAAE;YACR,CAAC;UAEL,CAAC;UACDA,IAAI,EAAE;QACR,CAAC;QACD/B,WAAW,EAAE;UACX8B,OAAO,EAAE,IAAI;UACbC,IAAI,EAAE;QACR,CAAC;QACDO,UAAU,EAAE;UACVH,KAAK,EAAE;YACLJ,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR,CAAC;QACD9B,iBAAiB,EAAE;UACjB6B,OAAO,EAAE,KAAK;UACdC,IAAI,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAA;AAAA"}
|
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _iterateJsdoc = _interopRequireDefault(require("../iterateJsdoc"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
const defaultTags = {
|
|
13
10
|
file: {
|
|
14
11
|
initialCommentsOnly: true,
|
|
@@ -16,7 +13,6 @@ const defaultTags = {
|
|
|
16
13
|
preventDuplicates: true
|
|
17
14
|
}
|
|
18
15
|
};
|
|
19
|
-
|
|
20
16
|
const setDefaults = state => {
|
|
21
17
|
// First iteration
|
|
22
18
|
if (!state.globalTags) {
|
|
@@ -26,7 +22,6 @@ const setDefaults = state => {
|
|
|
26
22
|
state.hasNonCommentBeforeTag = {};
|
|
27
23
|
}
|
|
28
24
|
};
|
|
29
|
-
|
|
30
25
|
var _default = (0, _iterateJsdoc.default)(({
|
|
31
26
|
jsdocNode,
|
|
32
27
|
state,
|
|
@@ -37,7 +32,6 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
37
32
|
tags = defaultTags
|
|
38
33
|
} = context.options[0] || {};
|
|
39
34
|
setDefaults(state);
|
|
40
|
-
|
|
41
35
|
for (const tagName of Object.keys(tags)) {
|
|
42
36
|
const targetTagName = utils.getPreferredTagName({
|
|
43
37
|
tagName
|
|
@@ -45,7 +39,6 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
45
39
|
const hasTag = targetTagName && utils.hasTag(targetTagName);
|
|
46
40
|
state.hasTag[tagName] = hasTag || state.hasTag[tagName];
|
|
47
41
|
const hasDuplicate = state.hasDuplicates[tagName];
|
|
48
|
-
|
|
49
42
|
if (hasDuplicate === false) {
|
|
50
43
|
// Was marked before, so if a tag now, is a dupe
|
|
51
44
|
state.hasDuplicates[tagName] = hasTag;
|
|
@@ -66,7 +59,6 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
66
59
|
const {
|
|
67
60
|
tags = defaultTags
|
|
68
61
|
} = context.options[0] || {};
|
|
69
|
-
|
|
70
62
|
for (const [tagName, {
|
|
71
63
|
mustExist = false,
|
|
72
64
|
preventDuplicates = false,
|
|
@@ -75,27 +67,22 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
75
67
|
const obj = utils.getPreferredTagNameObject({
|
|
76
68
|
tagName
|
|
77
69
|
});
|
|
78
|
-
|
|
79
70
|
if (obj && obj.blocked) {
|
|
80
71
|
utils.reportSettings(`\`settings.jsdoc.tagNamePreference\` cannot block @${obj.tagName} ` + 'for the `require-file-overview` rule');
|
|
81
72
|
} else {
|
|
82
73
|
const targetTagName = obj && obj.replacement || obj;
|
|
83
|
-
|
|
84
74
|
if (mustExist && !state.hasTag[tagName]) {
|
|
85
75
|
utils.reportSettings(`Missing @${targetTagName}`);
|
|
86
76
|
}
|
|
87
|
-
|
|
88
77
|
if (preventDuplicates && state.hasDuplicates[tagName]) {
|
|
89
78
|
utils.reportSettings(`Duplicate @${targetTagName}`);
|
|
90
79
|
}
|
|
91
|
-
|
|
92
80
|
if (initialCommentsOnly && state.hasNonCommentBeforeTag[tagName]) {
|
|
93
81
|
utils.reportSettings(`@${targetTagName} should be at the beginning of the file`);
|
|
94
82
|
}
|
|
95
83
|
}
|
|
96
84
|
}
|
|
97
85
|
},
|
|
98
|
-
|
|
99
86
|
iterateAllJsdocs: true,
|
|
100
87
|
meta: {
|
|
101
88
|
docs: {
|
|
@@ -130,7 +117,6 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
130
117
|
}],
|
|
131
118
|
type: 'suggestion'
|
|
132
119
|
},
|
|
133
|
-
|
|
134
120
|
nonComment({
|
|
135
121
|
state,
|
|
136
122
|
node
|
|
@@ -139,9 +125,7 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
139
125
|
state.hasNonComment = node.range[0];
|
|
140
126
|
}
|
|
141
127
|
}
|
|
142
|
-
|
|
143
128
|
});
|
|
144
|
-
|
|
145
129
|
exports.default = _default;
|
|
146
130
|
module.exports = exports.default;
|
|
147
131
|
//# sourceMappingURL=requireFileOverview.js.map
|