eslint-plugin-jsdoc 51.2.3 → 51.3.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.
|
@@ -6,6 +6,121 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _iterateJsdoc = _interopRequireDefault(require("../iterateJsdoc.cjs"));
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
/**
|
|
10
|
+
* @param {import('@es-joy/jsdoccomment').JsdocBlockWithInline} jsdoc
|
|
11
|
+
* @param {import('../iterateJsdoc.js').Utils} utils
|
|
12
|
+
* @param {number} requireSingleLineUnderCount
|
|
13
|
+
*/
|
|
14
|
+
const checkForShortTags = (jsdoc, utils, requireSingleLineUnderCount) => {
|
|
15
|
+
if (!requireSingleLineUnderCount || !jsdoc.tags.length) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
let lastLineWithTag = 0;
|
|
19
|
+
let exceedsLength = false;
|
|
20
|
+
let hasDesc = false;
|
|
21
|
+
const tagLines = jsdoc.source.reduce((acc, {
|
|
22
|
+
tokens: {
|
|
23
|
+
delimiter,
|
|
24
|
+
description: desc,
|
|
25
|
+
name,
|
|
26
|
+
postDelimiter,
|
|
27
|
+
postName,
|
|
28
|
+
postTag,
|
|
29
|
+
postType,
|
|
30
|
+
start,
|
|
31
|
+
tag,
|
|
32
|
+
type
|
|
33
|
+
}
|
|
34
|
+
}, idx) => {
|
|
35
|
+
if (tag.length) {
|
|
36
|
+
lastLineWithTag = idx;
|
|
37
|
+
if (start.length + delimiter.length + postDelimiter.length + type.length + postType.length + name.length + postName.length + tag.length + postTag.length + desc.length < requireSingleLineUnderCount) {
|
|
38
|
+
exceedsLength = true;
|
|
39
|
+
}
|
|
40
|
+
return acc + 1;
|
|
41
|
+
} else if (desc.length) {
|
|
42
|
+
hasDesc = true;
|
|
43
|
+
return acc;
|
|
44
|
+
}
|
|
45
|
+
return acc;
|
|
46
|
+
}, 0);
|
|
47
|
+
// Could be tagLines > 1
|
|
48
|
+
if (!hasDesc && exceedsLength && tagLines === 1) {
|
|
49
|
+
const fixer = () => {
|
|
50
|
+
const tokens = jsdoc.source[lastLineWithTag].tokens;
|
|
51
|
+
jsdoc.source = [{
|
|
52
|
+
number: 0,
|
|
53
|
+
source: '',
|
|
54
|
+
tokens: utils.seedTokens({
|
|
55
|
+
delimiter: '/**',
|
|
56
|
+
description: tokens.description.trimEnd() + ' ',
|
|
57
|
+
end: '*/',
|
|
58
|
+
name: tokens.name,
|
|
59
|
+
postDelimiter: ' ',
|
|
60
|
+
postName: tokens.postName,
|
|
61
|
+
postTag: tokens.postTag,
|
|
62
|
+
postType: tokens.postType,
|
|
63
|
+
start: jsdoc.source[0].tokens.start,
|
|
64
|
+
tag: tokens.tag,
|
|
65
|
+
type: tokens.type
|
|
66
|
+
})
|
|
67
|
+
}];
|
|
68
|
+
};
|
|
69
|
+
utils.reportJSDoc('Description is too short to be multi-line.', null, fixer);
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {import('@es-joy/jsdoccomment').JsdocBlockWithInline} jsdoc
|
|
77
|
+
* @param {import('../iterateJsdoc.js').Utils} utils
|
|
78
|
+
* @param {number} requireSingleLineUnderCount
|
|
79
|
+
*/
|
|
80
|
+
const checkForShortDescriptions = (jsdoc, utils, requireSingleLineUnderCount) => {
|
|
81
|
+
if (!requireSingleLineUnderCount || jsdoc.tags.length) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
let lastLineWithDesc = 0;
|
|
85
|
+
let exceedsLength = false;
|
|
86
|
+
const descLines = jsdoc.source.reduce((acc, {
|
|
87
|
+
tokens: {
|
|
88
|
+
delimiter,
|
|
89
|
+
description: desc,
|
|
90
|
+
postDelimiter,
|
|
91
|
+
start
|
|
92
|
+
}
|
|
93
|
+
}, idx) => {
|
|
94
|
+
if (desc.length) {
|
|
95
|
+
lastLineWithDesc = idx;
|
|
96
|
+
if (start.length + delimiter.length + postDelimiter.length + desc.length < requireSingleLineUnderCount) {
|
|
97
|
+
exceedsLength = true;
|
|
98
|
+
}
|
|
99
|
+
return acc + 1;
|
|
100
|
+
}
|
|
101
|
+
return acc;
|
|
102
|
+
}, 0);
|
|
103
|
+
// Could be descLines > 1
|
|
104
|
+
if (exceedsLength && descLines === 1) {
|
|
105
|
+
const fixer = () => {
|
|
106
|
+
const desc = jsdoc.source[lastLineWithDesc].tokens.description;
|
|
107
|
+
jsdoc.source = [{
|
|
108
|
+
number: 0,
|
|
109
|
+
source: '',
|
|
110
|
+
tokens: utils.seedTokens({
|
|
111
|
+
delimiter: '/**',
|
|
112
|
+
description: desc.trimEnd() + ' ',
|
|
113
|
+
end: '*/',
|
|
114
|
+
postDelimiter: ' ',
|
|
115
|
+
start: jsdoc.source[0].tokens.start
|
|
116
|
+
})
|
|
117
|
+
}];
|
|
118
|
+
};
|
|
119
|
+
utils.reportJSDoc('Description is too short to be multi-line.', null, fixer);
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
};
|
|
9
124
|
var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
10
125
|
context,
|
|
11
126
|
jsdoc,
|
|
@@ -19,6 +134,7 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
19
134
|
noMultilineBlocks = false,
|
|
20
135
|
noSingleLineBlocks = false,
|
|
21
136
|
noZeroLineText = true,
|
|
137
|
+
requireSingleLineUnderCount = null,
|
|
22
138
|
singleLineTags = ['lends', 'type']
|
|
23
139
|
} = context.options[0] || {};
|
|
24
140
|
const {
|
|
@@ -49,6 +165,12 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
49
165
|
utils.reportJSDoc('Single line blocks are not permitted by your configuration.', null, fixer, true);
|
|
50
166
|
return;
|
|
51
167
|
}
|
|
168
|
+
if (checkForShortDescriptions(jsdoc, utils, requireSingleLineUnderCount)) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (checkForShortTags(jsdoc, utils, requireSingleLineUnderCount)) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
52
174
|
const lineChecks = () => {
|
|
53
175
|
if (noZeroLineText && (tag || description)) {
|
|
54
176
|
const fixer = () => {
|
|
@@ -221,6 +343,9 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
221
343
|
noZeroLineText: {
|
|
222
344
|
type: 'boolean'
|
|
223
345
|
},
|
|
346
|
+
requireSingleLineUnderCount: {
|
|
347
|
+
type: 'number'
|
|
348
|
+
},
|
|
224
349
|
singleLineTags: {
|
|
225
350
|
items: {
|
|
226
351
|
type: 'string'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multilineBlocks.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","e","__esModule","default","_default","exports","iterateJsdoc","context","jsdoc","utils","allowMultipleTags","minimumLengthForMultiline","Number","POSITIVE_INFINITY","multilineTags","noFinalLineText","noMultilineBlocks","noSingleLineBlocks","noZeroLineText","singleLineTags","options","source","tokens","description","tag","sourceLength","length","isInvalidSingleLine","tagName","includes","slice","fixer","makeMultiline","reportJSDoc","lineChecks","line","emptyTokens","delimiter","start","addLine","finalLine","finalLineTokens","trim","trimEnd","prop","end","tags","hasATag","filterTags","tg","number","reduce","obj","desc","lineEnd","name","nme","postName","postTag","postType","type","typ","nameOrDescription","seedTokens","postDelimiter","iterateAllJsdocs","meta","docs","url","fixable","schema","additionalProperties","properties","anyOf","enum","items","module"],"sources":["../../src/rules/multilineBlocks.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\nexport default iterateJsdoc(({\n context,\n jsdoc,\n utils,\n}) => {\n const {\n allowMultipleTags = true,\n minimumLengthForMultiline = Number.POSITIVE_INFINITY,\n multilineTags = [\n '*',\n ],\n noFinalLineText = true,\n noMultilineBlocks = false,\n noSingleLineBlocks = false,\n noZeroLineText = true,\n singleLineTags = [\n 'lends', 'type',\n ],\n } = context.options[0] || {};\n\n const {\n source: [\n {\n tokens,\n },\n ],\n } = jsdoc;\n const {\n description,\n tag,\n } = tokens;\n const sourceLength = jsdoc.source.length;\n\n /**\n * @param {string} tagName\n * @returns {boolean}\n */\n const isInvalidSingleLine = (tagName) => {\n return noSingleLineBlocks &&\n (!tagName ||\n !singleLineTags.includes(tagName) && !singleLineTags.includes('*'));\n };\n\n if (sourceLength === 1) {\n if (!isInvalidSingleLine(tag.slice(1))) {\n return;\n }\n\n const fixer = () => {\n utils.makeMultiline();\n };\n\n utils.reportJSDoc(\n 'Single line blocks are not permitted by your configuration.',\n null,\n fixer,\n true,\n );\n\n return;\n }\n\n const lineChecks = () => {\n if (\n noZeroLineText &&\n (tag || description)\n ) {\n const fixer = () => {\n const line = {\n ...tokens,\n };\n utils.emptyTokens(tokens);\n const {\n tokens: {\n delimiter,\n start,\n },\n } = jsdoc.source[1];\n utils.addLine(1, {\n ...line,\n delimiter,\n start,\n });\n };\n\n utils.reportJSDoc(\n 'Should have no text on the \"0th\" line (after the `/**`).',\n null,\n fixer,\n );\n\n return;\n }\n\n const finalLine = jsdoc.source[jsdoc.source.length - 1];\n const finalLineTokens = finalLine.tokens;\n if (\n noFinalLineText &&\n finalLineTokens.description.trim()\n ) {\n const fixer = () => {\n const line = {\n ...finalLineTokens,\n };\n line.description = line.description.trimEnd();\n\n const {\n delimiter,\n } = line;\n\n for (const prop of [\n 'delimiter',\n 'postDelimiter',\n 'tag',\n 'type',\n 'lineEnd',\n 'postType',\n 'postTag',\n 'name',\n 'postName',\n 'description',\n ]) {\n finalLineTokens[\n /**\n * @type {\"delimiter\"|\"postDelimiter\"|\"tag\"|\"type\"|\n * \"lineEnd\"|\"postType\"|\"postTag\"|\"name\"|\n * \"postName\"|\"description\"}\n */ (\n prop\n )\n ] = '';\n }\n\n utils.addLine(jsdoc.source.length - 1, {\n ...line,\n delimiter,\n end: '',\n });\n };\n\n utils.reportJSDoc(\n 'Should have no text on the final line (before the `*/`).',\n null,\n fixer,\n );\n }\n };\n\n if (noMultilineBlocks) {\n if (\n jsdoc.tags.length &&\n (multilineTags.includes('*') || utils.hasATag(multilineTags))\n ) {\n lineChecks();\n\n return;\n }\n\n if (jsdoc.description.length >= minimumLengthForMultiline) {\n lineChecks();\n\n return;\n }\n\n if (\n noSingleLineBlocks &&\n (!jsdoc.tags.length ||\n !utils.filterTags(({\n tag: tg,\n }) => {\n return !isInvalidSingleLine(tg);\n }).length)\n ) {\n utils.reportJSDoc(\n 'Multiline jsdoc blocks are prohibited by ' +\n 'your configuration but fixing would result in a single ' +\n 'line block which you have prohibited with `noSingleLineBlocks`.',\n );\n\n return;\n }\n\n if (jsdoc.tags.length > 1) {\n if (!allowMultipleTags) {\n utils.reportJSDoc(\n 'Multiline jsdoc blocks are prohibited by ' +\n 'your configuration but the block has multiple tags.',\n );\n\n return;\n }\n } else if (jsdoc.tags.length === 1 && jsdoc.description.trim()) {\n if (!allowMultipleTags) {\n utils.reportJSDoc(\n 'Multiline jsdoc blocks are prohibited by ' +\n 'your configuration but the block has a description with a tag.',\n );\n\n return;\n }\n } else {\n const fixer = () => {\n jsdoc.source = [\n {\n number: 1,\n source: '',\n tokens: jsdoc.source.reduce((obj, {\n tokens: {\n description: desc,\n lineEnd,\n name: nme,\n postName,\n postTag,\n postType,\n tag: tg,\n type: typ,\n },\n }) => {\n if (typ) {\n obj.type = typ;\n }\n\n if (tg && typ && nme) {\n obj.postType = postType;\n }\n\n if (nme) {\n obj.name += nme;\n }\n\n if (nme && desc) {\n obj.postName = postName;\n }\n\n obj.description += desc;\n\n const nameOrDescription = obj.description || obj.name;\n if (\n nameOrDescription && nameOrDescription.slice(-1) !== ' '\n ) {\n obj.description += ' ';\n }\n\n obj.lineEnd = lineEnd;\n\n // Already filtered for multiple tags\n obj.tag += tg;\n if (tg) {\n obj.postTag = postTag || ' ';\n }\n\n return obj;\n }, utils.seedTokens({\n delimiter: '/**',\n end: '*/',\n postDelimiter: ' ',\n })),\n },\n ];\n };\n\n utils.reportJSDoc(\n 'Multiline jsdoc blocks are prohibited by ' +\n 'your configuration.',\n null,\n fixer,\n );\n\n return;\n }\n }\n\n lineChecks();\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Controls how and whether jsdoc blocks can be expressed as single or multiple line blocks.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/multiline-blocks.md#repos-sticky-header',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n allowMultipleTags: {\n type: 'boolean',\n },\n minimumLengthForMultiline: {\n type: 'integer',\n },\n multilineTags: {\n anyOf: [\n {\n enum: [\n '*',\n ],\n type: 'string',\n }, {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n ],\n },\n noFinalLineText: {\n type: 'boolean',\n },\n noMultilineBlocks: {\n type: 'boolean',\n },\n noSingleLineBlocks: {\n type: 'boolean',\n },\n noZeroLineText: {\n type: 'boolean',\n },\n singleLineTags: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA8C,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAE/B,IAAAG,qBAAY,EAAC,CAAC;EAC3BC,OAAO;EACPC,KAAK;EACLC;AACF,CAAC,KAAK;EACJ,MAAM;IACJC,iBAAiB,GAAG,IAAI;IACxBC,yBAAyB,GAAGC,MAAM,CAACC,iBAAiB;IACpDC,aAAa,GAAG,CACd,GAAG,CACJ;IACDC,eAAe,GAAG,IAAI;IACtBC,iBAAiB,GAAG,KAAK;I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ACxG6C,GAAG,EAAE;IACP,CAAC;IACDC,OAAO,EAAE,MAAM;IACfC,MAAM,EAAE,CACN;MACEC,oBAAoB,EAAE,KAAK;MAC3BC,UAAU,EAAE;QACV9D,iBAAiB,EAAE;UACjBkD,IAAI,EAAE;QACR,CAAC;QACDjD,yBAAyB,EAAE;UACzBiD,IAAI,EAAE;QACR,CAAC;QACD9C,aAAa,EAAE;UACb2D,KAAK,EAAE,CACL;YACEC,IAAI,EAAE,CACJ,GAAG,CACJ;YACDd,IAAI,EAAE;UACR,CAAC,EAAE;YACDe,KAAK,EAAE;cACLf,IAAI,EAAE;YACR,CAAC;YACDA,IAAI,EAAE;UACR,CAAC;QAEL,CAAC;QACD7C,eAAe,EAAE;UACf6C,IAAI,EAAE;QACR,CAAC;QACD5C,iBAAiB,EAAE;UACjB4C,IAAI,EAAE;QACR,CAAC;QACD3C,kBAAkB,EAAE;UAClB2C,IAAI,EAAE;QACR,CAAC;QACD1C,cAAc,EAAE;UACd0C,IAAI,EAAE;QACR,CAAC;QACDzC,cAAc,EAAE;UACdwD,KAAK,EAAE;YACLf,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAAgB,MAAA,CAAAvE,OAAA,GAAAA,OAAA,CAAAF,OAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"multilineBlocks.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","e","__esModule","default","checkForShortTags","jsdoc","utils","requireSingleLineUnderCount","tags","length","lastLineWithTag","exceedsLength","hasDesc","tagLines","source","reduce","acc","tokens","delimiter","description","desc","name","postDelimiter","postName","postTag","postType","start","tag","type","idx","fixer","number","seedTokens","trimEnd","end","reportJSDoc","checkForShortDescriptions","lastLineWithDesc","descLines","_default","exports","iterateJsdoc","context","allowMultipleTags","minimumLengthForMultiline","Number","POSITIVE_INFINITY","multilineTags","noFinalLineText","noMultilineBlocks","noSingleLineBlocks","noZeroLineText","singleLineTags","options","sourceLength","isInvalidSingleLine","tagName","includes","slice","makeMultiline","lineChecks","line","emptyTokens","addLine","finalLine","finalLineTokens","trim","prop","hasATag","filterTags","tg","obj","lineEnd","nme","typ","nameOrDescription","iterateAllJsdocs","meta","docs","url","fixable","schema","additionalProperties","properties","anyOf","enum","items","module"],"sources":["../../src/rules/multilineBlocks.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\n/**\n * @param {import('@es-joy/jsdoccomment').JsdocBlockWithInline} jsdoc\n * @param {import('../iterateJsdoc.js').Utils} utils\n * @param {number} requireSingleLineUnderCount\n */\nconst checkForShortTags = (jsdoc, utils, requireSingleLineUnderCount) => {\n if (!requireSingleLineUnderCount || !jsdoc.tags.length) {\n return false;\n }\n\n let lastLineWithTag = 0;\n let exceedsLength = false;\n let hasDesc = false;\n const tagLines = jsdoc.source.reduce((acc, {\n tokens: {\n delimiter,\n description: desc,\n name,\n postDelimiter,\n postName,\n postTag,\n postType,\n start,\n tag,\n type,\n },\n }, idx) => {\n if (tag.length) {\n lastLineWithTag = idx;\n if (\n start.length + delimiter.length + postDelimiter.length +\n type.length + postType.length + name.length + postName.length +\n tag.length + postTag.length + desc.length <\n requireSingleLineUnderCount\n ) {\n exceedsLength = true;\n }\n\n return acc + 1;\n } else if (desc.length) {\n hasDesc = true;\n return acc;\n }\n\n return acc;\n }, 0);\n // Could be tagLines > 1\n if (!hasDesc && exceedsLength && tagLines === 1) {\n const fixer = () => {\n const tokens = jsdoc.source[lastLineWithTag].tokens;\n jsdoc.source = [\n {\n number: 0,\n source: '',\n tokens: utils.seedTokens({\n delimiter: '/**',\n description: tokens.description.trimEnd() + ' ',\n end: '*/',\n name: tokens.name,\n postDelimiter: ' ',\n postName: tokens.postName,\n postTag: tokens.postTag,\n postType: tokens.postType,\n start: jsdoc.source[0].tokens.start,\n tag: tokens.tag,\n type: tokens.type,\n }),\n },\n ];\n };\n\n utils.reportJSDoc(\n 'Description is too short to be multi-line.',\n null,\n fixer,\n );\n return true;\n }\n\n return false;\n};\n\n/**\n * @param {import('@es-joy/jsdoccomment').JsdocBlockWithInline} jsdoc\n * @param {import('../iterateJsdoc.js').Utils} utils\n * @param {number} requireSingleLineUnderCount\n */\nconst checkForShortDescriptions = (jsdoc, utils, requireSingleLineUnderCount) => {\n if (!requireSingleLineUnderCount || jsdoc.tags.length) {\n return false;\n }\n\n let lastLineWithDesc = 0;\n let exceedsLength = false;\n const descLines = jsdoc.source.reduce((acc, {\n tokens: {\n delimiter,\n description: desc,\n postDelimiter,\n start,\n },\n }, idx) => {\n if (desc.length) {\n lastLineWithDesc = idx;\n if (\n start.length + delimiter.length + postDelimiter.length + desc.length <\n requireSingleLineUnderCount\n ) {\n exceedsLength = true;\n }\n\n return acc + 1;\n }\n\n return acc;\n }, 0);\n // Could be descLines > 1\n if (exceedsLength && descLines === 1) {\n const fixer = () => {\n const desc = jsdoc.source[lastLineWithDesc].tokens.description;\n jsdoc.source = [\n {\n number: 0,\n source: '',\n tokens: utils.seedTokens({\n delimiter: '/**',\n description: desc.trimEnd() + ' ',\n end: '*/',\n postDelimiter: ' ',\n start: jsdoc.source[0].tokens.start,\n }),\n },\n ];\n };\n\n utils.reportJSDoc(\n 'Description is too short to be multi-line.',\n null,\n fixer,\n );\n return true;\n }\n\n return false;\n};\n\nexport default iterateJsdoc(({\n context,\n jsdoc,\n utils,\n}) => {\n const {\n allowMultipleTags = true,\n minimumLengthForMultiline = Number.POSITIVE_INFINITY,\n multilineTags = [\n '*',\n ],\n noFinalLineText = true,\n noMultilineBlocks = false,\n noSingleLineBlocks = false,\n noZeroLineText = true,\n requireSingleLineUnderCount = null,\n singleLineTags = [\n 'lends', 'type',\n ],\n } = context.options[0] || {};\n\n const {\n source: [\n {\n tokens,\n },\n ],\n } = jsdoc;\n const {\n description,\n tag,\n } = tokens;\n const sourceLength = jsdoc.source.length;\n\n /**\n * @param {string} tagName\n * @returns {boolean}\n */\n const isInvalidSingleLine = (tagName) => {\n return noSingleLineBlocks &&\n (!tagName ||\n !singleLineTags.includes(tagName) && !singleLineTags.includes('*'));\n };\n\n if (sourceLength === 1) {\n if (!isInvalidSingleLine(tag.slice(1))) {\n return;\n }\n\n const fixer = () => {\n utils.makeMultiline();\n };\n\n utils.reportJSDoc(\n 'Single line blocks are not permitted by your configuration.',\n null,\n fixer,\n true,\n );\n\n return;\n }\n\n if (checkForShortDescriptions(jsdoc, utils, requireSingleLineUnderCount)\n ) {\n return;\n }\n\n if (checkForShortTags(jsdoc, utils, requireSingleLineUnderCount)\n ) {\n return;\n }\n\n const lineChecks = () => {\n if (\n noZeroLineText &&\n (tag || description)\n ) {\n const fixer = () => {\n const line = {\n ...tokens,\n };\n utils.emptyTokens(tokens);\n const {\n tokens: {\n delimiter,\n start,\n },\n } = jsdoc.source[1];\n utils.addLine(1, {\n ...line,\n delimiter,\n start,\n });\n };\n\n utils.reportJSDoc(\n 'Should have no text on the \"0th\" line (after the `/**`).',\n null,\n fixer,\n );\n\n return;\n }\n\n const finalLine = jsdoc.source[jsdoc.source.length - 1];\n const finalLineTokens = finalLine.tokens;\n if (\n noFinalLineText &&\n finalLineTokens.description.trim()\n ) {\n const fixer = () => {\n const line = {\n ...finalLineTokens,\n };\n line.description = line.description.trimEnd();\n\n const {\n delimiter,\n } = line;\n\n for (const prop of [\n 'delimiter',\n 'postDelimiter',\n 'tag',\n 'type',\n 'lineEnd',\n 'postType',\n 'postTag',\n 'name',\n 'postName',\n 'description',\n ]) {\n finalLineTokens[\n /**\n * @type {\"delimiter\"|\"postDelimiter\"|\"tag\"|\"type\"|\n * \"lineEnd\"|\"postType\"|\"postTag\"|\"name\"|\n * \"postName\"|\"description\"}\n */ (\n prop\n )\n ] = '';\n }\n\n utils.addLine(jsdoc.source.length - 1, {\n ...line,\n delimiter,\n end: '',\n });\n };\n\n utils.reportJSDoc(\n 'Should have no text on the final line (before the `*/`).',\n null,\n fixer,\n );\n }\n };\n\n if (noMultilineBlocks) {\n if (\n jsdoc.tags.length &&\n (multilineTags.includes('*') || utils.hasATag(multilineTags))\n ) {\n lineChecks();\n\n return;\n }\n\n if (jsdoc.description.length >= minimumLengthForMultiline) {\n lineChecks();\n\n return;\n }\n\n if (\n noSingleLineBlocks &&\n (!jsdoc.tags.length ||\n !utils.filterTags(({\n tag: tg,\n }) => {\n return !isInvalidSingleLine(tg);\n }).length)\n ) {\n utils.reportJSDoc(\n 'Multiline jsdoc blocks are prohibited by ' +\n 'your configuration but fixing would result in a single ' +\n 'line block which you have prohibited with `noSingleLineBlocks`.',\n );\n\n return;\n }\n\n if (jsdoc.tags.length > 1) {\n if (!allowMultipleTags) {\n utils.reportJSDoc(\n 'Multiline jsdoc blocks are prohibited by ' +\n 'your configuration but the block has multiple tags.',\n );\n\n return;\n }\n } else if (jsdoc.tags.length === 1 && jsdoc.description.trim()) {\n if (!allowMultipleTags) {\n utils.reportJSDoc(\n 'Multiline jsdoc blocks are prohibited by ' +\n 'your configuration but the block has a description with a tag.',\n );\n\n return;\n }\n } else {\n const fixer = () => {\n jsdoc.source = [\n {\n number: 1,\n source: '',\n tokens: jsdoc.source.reduce((obj, {\n tokens: {\n description: desc,\n lineEnd,\n name: nme,\n postName,\n postTag,\n postType,\n tag: tg,\n type: typ,\n },\n }) => {\n if (typ) {\n obj.type = typ;\n }\n\n if (tg && typ && nme) {\n obj.postType = postType;\n }\n\n if (nme) {\n obj.name += nme;\n }\n\n if (nme && desc) {\n obj.postName = postName;\n }\n\n obj.description += desc;\n\n const nameOrDescription = obj.description || obj.name;\n if (\n nameOrDescription && nameOrDescription.slice(-1) !== ' '\n ) {\n obj.description += ' ';\n }\n\n obj.lineEnd = lineEnd;\n\n // Already filtered for multiple tags\n obj.tag += tg;\n if (tg) {\n obj.postTag = postTag || ' ';\n }\n\n return obj;\n }, utils.seedTokens({\n delimiter: '/**',\n end: '*/',\n postDelimiter: ' ',\n })),\n },\n ];\n };\n\n utils.reportJSDoc(\n 'Multiline jsdoc blocks are prohibited by ' +\n 'your configuration.',\n null,\n fixer,\n );\n\n return;\n }\n }\n\n lineChecks();\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Controls how and whether jsdoc blocks can be expressed as single or multiple line blocks.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/multiline-blocks.md#repos-sticky-header',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n allowMultipleTags: {\n type: 'boolean',\n },\n minimumLengthForMultiline: {\n type: 'integer',\n },\n multilineTags: {\n anyOf: [\n {\n enum: [\n '*',\n ],\n type: 'string',\n }, {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n ],\n },\n noFinalLineText: {\n type: 'boolean',\n },\n noMultilineBlocks: {\n type: 'boolean',\n },\n noSingleLineBlocks: {\n type: 'boolean',\n },\n noZeroLineText: {\n type: 'boolean',\n },\n requireSingleLineUnderCount: {\n type: 'number',\n },\n singleLineTags: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA8C,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE9C;AACA;AACA;AACA;AACA;AACA,MAAMG,iBAAiB,GAAGA,CAACC,KAAK,EAAEC,KAAK,EAAEC,2BAA2B,KAAK;EACvE,IAAI,CAACA,2BAA2B,IAAI,CAACF,KAAK,CAACG,IAAI,CAACC,MAAM,EAAE;IACtD,OAAO,KAAK;EACd;EAEA,IAAIC,eAAe,GAAG,CAAC;EACvB,IAAIC,aAAa,GAAG,KAAK;EACzB,IAAIC,OAAO,GAAG,KAAK;EACnB,MAAMC,QAAQ,GAAGR,KAAK,CAACS,MAAM,CAACC,MAAM,CAAC,CAACC,GAAG,EA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WAAW,EAAE,2FAA2F;MACxG4D,GAAG,EAAE;IACP,CAAC;IACDC,OAAO,EAAE,MAAM;IACfC,MAAM,EAAE,CACN;MACEC,oBAAoB,EAAE,KAAK;MAC3BC,UAAU,EAAE;QACVxC,iBAAiB,EAAE;UACjBf,IAAI,EAAE;QACR,CAAC;QACDgB,yBAAyB,EAAE;UACzBhB,IAAI,EAAE;QACR,CAAC;QACDmB,aAAa,EAAE;UACbqC,KAAK,EAAE,CACL;YACEC,IAAI,EAAE,CACJ,GAAG,CACJ;YACDzD,IAAI,EAAE;UACR,CAAC,EAAE;YACD0D,KAAK,EAAE;cACL1D,IAAI,EAAE;YACR,CAAC;YACDA,IAAI,EAAE;UACR,CAAC;QAEL,CAAC;QACDoB,eAAe,EAAE;UACfpB,IAAI,EAAE;QACR,CAAC;QACDqB,iBAAiB,EAAE;UACjBrB,IAAI,EAAE;QACR,CAAC;QACDsB,kBAAkB,EAAE;UAClBtB,IAAI,EAAE;QACR,CAAC;QACDuB,cAAc,EAAE;UACdvB,IAAI,EAAE;QACR,CAAC;QACDrB,2BAA2B,EAAE;UAC3BqB,IAAI,EAAE;QACR,CAAC;QACDwB,cAAc,EAAE;UACdkC,KAAK,EAAE;YACL1D,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAA2D,MAAA,CAAA/C,OAAA,GAAAA,OAAA,CAAArC,OAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,5 +1,151 @@
|
|
|
1
1
|
import iterateJsdoc from '../iterateJsdoc.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @param {import('@es-joy/jsdoccomment').JsdocBlockWithInline} jsdoc
|
|
5
|
+
* @param {import('../iterateJsdoc.js').Utils} utils
|
|
6
|
+
* @param {number} requireSingleLineUnderCount
|
|
7
|
+
*/
|
|
8
|
+
const checkForShortTags = (jsdoc, utils, requireSingleLineUnderCount) => {
|
|
9
|
+
if (!requireSingleLineUnderCount || !jsdoc.tags.length) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let lastLineWithTag = 0;
|
|
14
|
+
let exceedsLength = false;
|
|
15
|
+
let hasDesc = false;
|
|
16
|
+
const tagLines = jsdoc.source.reduce((acc, {
|
|
17
|
+
tokens: {
|
|
18
|
+
delimiter,
|
|
19
|
+
description: desc,
|
|
20
|
+
name,
|
|
21
|
+
postDelimiter,
|
|
22
|
+
postName,
|
|
23
|
+
postTag,
|
|
24
|
+
postType,
|
|
25
|
+
start,
|
|
26
|
+
tag,
|
|
27
|
+
type,
|
|
28
|
+
},
|
|
29
|
+
}, idx) => {
|
|
30
|
+
if (tag.length) {
|
|
31
|
+
lastLineWithTag = idx;
|
|
32
|
+
if (
|
|
33
|
+
start.length + delimiter.length + postDelimiter.length +
|
|
34
|
+
type.length + postType.length + name.length + postName.length +
|
|
35
|
+
tag.length + postTag.length + desc.length <
|
|
36
|
+
requireSingleLineUnderCount
|
|
37
|
+
) {
|
|
38
|
+
exceedsLength = true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return acc + 1;
|
|
42
|
+
} else if (desc.length) {
|
|
43
|
+
hasDesc = true;
|
|
44
|
+
return acc;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return acc;
|
|
48
|
+
}, 0);
|
|
49
|
+
// Could be tagLines > 1
|
|
50
|
+
if (!hasDesc && exceedsLength && tagLines === 1) {
|
|
51
|
+
const fixer = () => {
|
|
52
|
+
const tokens = jsdoc.source[lastLineWithTag].tokens;
|
|
53
|
+
jsdoc.source = [
|
|
54
|
+
{
|
|
55
|
+
number: 0,
|
|
56
|
+
source: '',
|
|
57
|
+
tokens: utils.seedTokens({
|
|
58
|
+
delimiter: '/**',
|
|
59
|
+
description: tokens.description.trimEnd() + ' ',
|
|
60
|
+
end: '*/',
|
|
61
|
+
name: tokens.name,
|
|
62
|
+
postDelimiter: ' ',
|
|
63
|
+
postName: tokens.postName,
|
|
64
|
+
postTag: tokens.postTag,
|
|
65
|
+
postType: tokens.postType,
|
|
66
|
+
start: jsdoc.source[0].tokens.start,
|
|
67
|
+
tag: tokens.tag,
|
|
68
|
+
type: tokens.type,
|
|
69
|
+
}),
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
utils.reportJSDoc(
|
|
75
|
+
'Description is too short to be multi-line.',
|
|
76
|
+
null,
|
|
77
|
+
fixer,
|
|
78
|
+
);
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return false;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @param {import('@es-joy/jsdoccomment').JsdocBlockWithInline} jsdoc
|
|
87
|
+
* @param {import('../iterateJsdoc.js').Utils} utils
|
|
88
|
+
* @param {number} requireSingleLineUnderCount
|
|
89
|
+
*/
|
|
90
|
+
const checkForShortDescriptions = (jsdoc, utils, requireSingleLineUnderCount) => {
|
|
91
|
+
if (!requireSingleLineUnderCount || jsdoc.tags.length) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let lastLineWithDesc = 0;
|
|
96
|
+
let exceedsLength = false;
|
|
97
|
+
const descLines = jsdoc.source.reduce((acc, {
|
|
98
|
+
tokens: {
|
|
99
|
+
delimiter,
|
|
100
|
+
description: desc,
|
|
101
|
+
postDelimiter,
|
|
102
|
+
start,
|
|
103
|
+
},
|
|
104
|
+
}, idx) => {
|
|
105
|
+
if (desc.length) {
|
|
106
|
+
lastLineWithDesc = idx;
|
|
107
|
+
if (
|
|
108
|
+
start.length + delimiter.length + postDelimiter.length + desc.length <
|
|
109
|
+
requireSingleLineUnderCount
|
|
110
|
+
) {
|
|
111
|
+
exceedsLength = true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return acc + 1;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return acc;
|
|
118
|
+
}, 0);
|
|
119
|
+
// Could be descLines > 1
|
|
120
|
+
if (exceedsLength && descLines === 1) {
|
|
121
|
+
const fixer = () => {
|
|
122
|
+
const desc = jsdoc.source[lastLineWithDesc].tokens.description;
|
|
123
|
+
jsdoc.source = [
|
|
124
|
+
{
|
|
125
|
+
number: 0,
|
|
126
|
+
source: '',
|
|
127
|
+
tokens: utils.seedTokens({
|
|
128
|
+
delimiter: '/**',
|
|
129
|
+
description: desc.trimEnd() + ' ',
|
|
130
|
+
end: '*/',
|
|
131
|
+
postDelimiter: ' ',
|
|
132
|
+
start: jsdoc.source[0].tokens.start,
|
|
133
|
+
}),
|
|
134
|
+
},
|
|
135
|
+
];
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
utils.reportJSDoc(
|
|
139
|
+
'Description is too short to be multi-line.',
|
|
140
|
+
null,
|
|
141
|
+
fixer,
|
|
142
|
+
);
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return false;
|
|
147
|
+
};
|
|
148
|
+
|
|
3
149
|
export default iterateJsdoc(({
|
|
4
150
|
context,
|
|
5
151
|
jsdoc,
|
|
@@ -15,6 +161,7 @@ export default iterateJsdoc(({
|
|
|
15
161
|
noMultilineBlocks = false,
|
|
16
162
|
noSingleLineBlocks = false,
|
|
17
163
|
noZeroLineText = true,
|
|
164
|
+
requireSingleLineUnderCount = null,
|
|
18
165
|
singleLineTags = [
|
|
19
166
|
'lends', 'type',
|
|
20
167
|
],
|
|
@@ -62,6 +209,16 @@ export default iterateJsdoc(({
|
|
|
62
209
|
return;
|
|
63
210
|
}
|
|
64
211
|
|
|
212
|
+
if (checkForShortDescriptions(jsdoc, utils, requireSingleLineUnderCount)
|
|
213
|
+
) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (checkForShortTags(jsdoc, utils, requireSingleLineUnderCount)
|
|
218
|
+
) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
65
222
|
const lineChecks = () => {
|
|
66
223
|
if (
|
|
67
224
|
noZeroLineText &&
|
|
@@ -318,6 +475,9 @@ export default iterateJsdoc(({
|
|
|
318
475
|
noZeroLineText: {
|
|
319
476
|
type: 'boolean',
|
|
320
477
|
},
|
|
478
|
+
requireSingleLineUnderCount: {
|
|
479
|
+
type: 'number',
|
|
480
|
+
},
|
|
321
481
|
singleLineTags: {
|
|
322
482
|
items: {
|
|
323
483
|
type: 'string',
|