eslint-plugin-jsdoc 54.2.1 → 54.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.
|
@@ -33,6 +33,7 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
35
|
const startsWithHyphen = /^\s*-/v.test(desc);
|
|
36
|
+
const hyphenNewline = /^\s*-\n/v.test(desc);
|
|
36
37
|
let lines = 0;
|
|
37
38
|
for (const {
|
|
38
39
|
tokens
|
|
@@ -42,23 +43,31 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
42
43
|
}
|
|
43
44
|
lines++;
|
|
44
45
|
}
|
|
45
|
-
if (always) {
|
|
46
|
+
if (always && !hyphenNewline) {
|
|
46
47
|
if (!startsWithHyphen) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
tokens.description = tokens.description.replace(/^(\s*)/v, '$1- ');
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
48
|
+
let fixIt = true;
|
|
49
|
+
for (const {
|
|
50
|
+
tokens
|
|
51
|
+
} of jsdocTag.source) {
|
|
52
|
+
if (tokens.description) {
|
|
53
|
+
tokens.description = tokens.description.replace(/^(\s*)/v, '$1- ');
|
|
54
|
+
break;
|
|
57
55
|
}
|
|
58
|
-
|
|
56
|
+
|
|
57
|
+
// Linebreak after name since has no description
|
|
58
|
+
if (tokens.name) {
|
|
59
|
+
fixIt = false;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (fixIt) {
|
|
64
|
+
utils.reportJSDoc(`There must be a hyphen before @${targetTagName} description.`, {
|
|
65
|
+
line: jsdocTag.source[0].number + lines
|
|
66
|
+
}, () => {});
|
|
67
|
+
}
|
|
59
68
|
}
|
|
60
69
|
} else if (startsWithHyphen) {
|
|
61
|
-
utils.reportJSDoc(`There must be no hyphen before @${targetTagName} description.`, {
|
|
70
|
+
utils.reportJSDoc(always ? `There must be no hyphen followed by newline after the @${targetTagName} name.` : `There must be no hyphen before @${targetTagName} description.`, {
|
|
62
71
|
line: jsdocTag.source[0].number + lines
|
|
63
72
|
}, () => {
|
|
64
73
|
for (const {
|
|
@@ -66,6 +75,9 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
66
75
|
} of jsdocTag.source) {
|
|
67
76
|
if (tokens.description) {
|
|
68
77
|
tokens.description = tokens.description.replace(/^\s*-\s*/v, '');
|
|
78
|
+
if (hyphenNewline) {
|
|
79
|
+
tokens.postName = '';
|
|
80
|
+
}
|
|
69
81
|
break;
|
|
70
82
|
}
|
|
71
83
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requireHyphenBeforeParamDescription.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","e","__esModule","default","_default","exports","iterateJsdoc","context","jsdoc","utils","mainCircumstance","tags","options","tgs","checkHyphens","jsdocTag","targetTagName","circumstance","always","desc","getTagDescription","trim","startsWithHyphen","test","lines","tokens","source","description","reportJSDoc","line","number","
|
|
1
|
+
{"version":3,"file":"requireHyphenBeforeParamDescription.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","e","__esModule","default","_default","exports","iterateJsdoc","context","jsdoc","utils","mainCircumstance","tags","options","tgs","checkHyphens","jsdocTag","targetTagName","circumstance","always","desc","getTagDescription","trim","startsWithHyphen","test","hyphenNewline","lines","tokens","source","description","fixIt","replace","name","reportJSDoc","line","number","postName","forEachPreferredTag","tagEntries","Object","entries","tagName","preferredParamTag","getPreferredTagName","tag","some","tagNme","iterateAllJsdocs","meta","docs","url","fixable","schema","enum","type","additionalProperties","properties","anyOf","patternProperties","module"],"sources":["../../src/rules/requireHyphenBeforeParamDescription.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\nexport default iterateJsdoc(({\n context,\n jsdoc,\n utils,\n}) => {\n const [\n mainCircumstance,\n {\n tags = null,\n } = {},\n ] = context.options;\n\n const tgs = /**\n * @type {null|\"any\"|{[key: string]: \"always\"|\"never\"}}\n */ (tags);\n\n /**\n * @param {import('@es-joy/jsdoccomment').JsdocTagWithInline} jsdocTag\n * @param {string} targetTagName\n * @param {\"always\"|\"never\"} [circumstance]\n * @returns {void}\n */\n const checkHyphens = (jsdocTag, targetTagName, circumstance = mainCircumstance) => {\n const always = !circumstance || circumstance === 'always';\n const desc = /** @type {string} */ (utils.getTagDescription(jsdocTag));\n if (!desc.trim()) {\n return;\n }\n\n const startsWithHyphen = (/^\\s*-/v).test(desc);\n const hyphenNewline = (/^\\s*-\\n/v).test(desc);\n\n let lines = 0;\n for (const {\n tokens,\n } of jsdocTag.source) {\n if (tokens.description) {\n break;\n }\n\n lines++;\n }\n\n if (always && !hyphenNewline) {\n if (!startsWithHyphen) {\n let fixIt = true;\n for (const {\n tokens,\n } of jsdocTag.source) {\n if (tokens.description) {\n tokens.description = tokens.description.replace(\n /^(\\s*)/v, '$1- ',\n );\n break;\n }\n\n // Linebreak after name since has no description\n if (tokens.name) {\n fixIt = false;\n break;\n }\n }\n\n if (fixIt) {\n utils.reportJSDoc(\n `There must be a hyphen before @${targetTagName} description.`,\n {\n line: jsdocTag.source[0].number + lines,\n },\n () => {},\n );\n }\n }\n } else if (startsWithHyphen) {\n utils.reportJSDoc(\n always ?\n `There must be no hyphen followed by newline after the @${targetTagName} name.` :\n `There must be no hyphen before @${targetTagName} description.`,\n {\n line: jsdocTag.source[0].number + lines,\n },\n () => {\n for (const {\n tokens,\n } of jsdocTag.source) {\n if (tokens.description) {\n tokens.description = tokens.description.replace(\n /^\\s*-\\s*/v, '',\n );\n if (hyphenNewline) {\n tokens.postName = '';\n }\n\n break;\n }\n }\n },\n true,\n );\n }\n };\n\n utils.forEachPreferredTag('param', checkHyphens);\n if (tgs) {\n const tagEntries = Object.entries(tgs);\n for (const [\n tagName,\n circumstance,\n ] of tagEntries) {\n if (tagName === '*') {\n const preferredParamTag = utils.getPreferredTagName({\n tagName: 'param',\n });\n for (const {\n tag,\n } of jsdoc.tags) {\n if (tag === preferredParamTag || tagEntries.some(([\n tagNme,\n ]) => {\n return tagNme !== '*' && tagNme === tag;\n })) {\n continue;\n }\n\n utils.forEachPreferredTag(tag, (jsdocTag, targetTagName) => {\n checkHyphens(\n jsdocTag,\n targetTagName,\n /** @type {\"always\"|\"never\"} */ (circumstance),\n );\n });\n }\n\n continue;\n }\n\n utils.forEachPreferredTag(tagName, (jsdocTag, targetTagName) => {\n checkHyphens(\n jsdocTag,\n targetTagName,\n /** @type {\"always\"|\"never\"} */ (circumstance),\n );\n });\n }\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Requires a hyphen before the `@param` description.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-hyphen-before-param-description.md#repos-sticky-header',\n },\n fixable: 'code',\n schema: [\n {\n enum: [\n 'always', 'never',\n ],\n type: 'string',\n },\n {\n additionalProperties: false,\n properties: {\n tags: {\n anyOf: [\n {\n patternProperties: {\n '.*': {\n enum: [\n 'always', 'never',\n ],\n type: 'string',\n },\n },\n type: 'object',\n },\n {\n enum: [\n 'any',\n ],\n type: 'string',\n },\n ],\n },\n },\n type: 'object',\n },\n ],\n type: 'layout',\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,CACJC,gBAAgB,EAChB;IACEC,IAAI,GAAG;EACT,CAAC,GAAG,CAAC,CAAC,CACP,GAAGJ,OAAO,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;UAEAlC,KAAK,CAAC2B,mBAAmB,CAACO,GAAG,EAAE,CAAC5B,QAAQ,EAAEC,aAAa,KAAK;YAC1DF,YAAY,CACVC,QAAQ,EACRC,aAAa,EACb,+BAAiCC,YACnC,CAAC;UACH,CAAC,CAAC;QACJ;QAEA;MACF;MAEAR,KAAK,CAAC2B,mBAAmB,CAACI,OAAO,EAAE,CAACzB,QAAQ,EAAEC,aAAa,KAAK;QAC9DF,YAAY,CACVC,QAAQ,EACRC,aAAa,EACb,+BAAiCC,YACnC,CAAC;MACH,CAAC,CAAC;IACJ;EACF;AACF,CAAC,EAAE;EACD6B,gBAAgB,EAAE,IAAI;EACtBC,IAAI,EAAE;IACJC,IAAI,EAAE;MACJpB,WAAW,EAAE,oDAAoD;MACjEqB,GAAG,EAAE;IACP,CAAC;IACDC,OAAO,EAAE,MAAM;IACfC,MAAM,EAAE,CACN;MACEC,IAAI,EAAE,CACJ,QAAQ,EAAE,OAAO,CAClB;MACDC,IAAI,EAAE;IACR,CAAC,EACD;MACEC,oBAAoB,EAAE,KAAK;MAC3BC,UAAU,EAAE;QACV5C,IAAI,EAAE;UACJ6C,KAAK,EAAE,CACL;YACEC,iBAAiB,EAAE;cACjB,IAAI,EAAE;gBACJL,IAAI,EAAE,CACJ,QAAQ,EAAE,OAAO,CAClB;gBACDC,IAAI,EAAE;cACR;YACF,CAAC;YACDA,IAAI,EAAE;UACR,CAAC,EACD;YACED,IAAI,EAAE,CACJ,KAAK,CACN;YACDC,IAAI,EAAE;UACR,CAAC;QAEL;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAAK,MAAA,CAAArD,OAAA,GAAAA,OAAA,CAAAF,OAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -30,6 +30,8 @@ export default iterateJsdoc(({
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
const startsWithHyphen = (/^\s*-/v).test(desc);
|
|
33
|
+
const hyphenNewline = (/^\s*-\n/v).test(desc);
|
|
34
|
+
|
|
33
35
|
let lines = 0;
|
|
34
36
|
for (const {
|
|
35
37
|
tokens,
|
|
@@ -41,30 +43,41 @@ export default iterateJsdoc(({
|
|
|
41
43
|
lines++;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
if (always) {
|
|
46
|
+
if (always && !hyphenNewline) {
|
|
45
47
|
if (!startsWithHyphen) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
48
|
+
let fixIt = true;
|
|
49
|
+
for (const {
|
|
50
|
+
tokens,
|
|
51
|
+
} of jsdocTag.source) {
|
|
52
|
+
if (tokens.description) {
|
|
53
|
+
tokens.description = tokens.description.replace(
|
|
54
|
+
/^(\s*)/v, '$1- ',
|
|
55
|
+
);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Linebreak after name since has no description
|
|
60
|
+
if (tokens.name) {
|
|
61
|
+
fixIt = false;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (fixIt) {
|
|
67
|
+
utils.reportJSDoc(
|
|
68
|
+
`There must be a hyphen before @${targetTagName} description.`,
|
|
69
|
+
{
|
|
70
|
+
line: jsdocTag.source[0].number + lines,
|
|
71
|
+
},
|
|
72
|
+
() => {},
|
|
73
|
+
);
|
|
74
|
+
}
|
|
64
75
|
}
|
|
65
76
|
} else if (startsWithHyphen) {
|
|
66
77
|
utils.reportJSDoc(
|
|
67
|
-
|
|
78
|
+
always ?
|
|
79
|
+
`There must be no hyphen followed by newline after the @${targetTagName} name.` :
|
|
80
|
+
`There must be no hyphen before @${targetTagName} description.`,
|
|
68
81
|
{
|
|
69
82
|
line: jsdocTag.source[0].number + lines,
|
|
70
83
|
},
|
|
@@ -76,6 +89,10 @@ export default iterateJsdoc(({
|
|
|
76
89
|
tokens.description = tokens.description.replace(
|
|
77
90
|
/^\s*-\s*/v, '',
|
|
78
91
|
);
|
|
92
|
+
if (hyphenNewline) {
|
|
93
|
+
tokens.postName = '';
|
|
94
|
+
}
|
|
95
|
+
|
|
79
96
|
break;
|
|
80
97
|
}
|
|
81
98
|
}
|