eslint-plugin-jsdoc 50.4.0 → 50.4.2
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/dist/rules/matchName.cjs
CHANGED
|
@@ -37,8 +37,9 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
37
37
|
}
|
|
38
38
|
let reported = false;
|
|
39
39
|
for (const tag of applicableTags) {
|
|
40
|
-
const
|
|
41
|
-
const
|
|
40
|
+
const tagName = tag.name.replace(/^\[/u, '').replace(/(=.*)?\]$/u, '');
|
|
41
|
+
const allowed = !allowNameRegex || allowNameRegex.test(tagName);
|
|
42
|
+
const disallowed = disallowNameRegex && disallowNameRegex.test(tagName);
|
|
42
43
|
const hasRegex = allowNameRegex || disallowNameRegex;
|
|
43
44
|
if (hasRegex && allowed && !disallowed) {
|
|
44
45
|
continue;
|
|
@@ -59,9 +60,9 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
59
60
|
} = match[( /** @type {import('../iterateJsdoc.js').Integer} */lastIndex)];
|
|
60
61
|
if (!message) {
|
|
61
62
|
if (hasRegex) {
|
|
62
|
-
message = disallowed ? `Only allowing names not matching \`${disallowNameRegex}\` but found "${
|
|
63
|
+
message = disallowed ? `Only allowing names not matching \`${disallowNameRegex}\` but found "${tagName}".` : `Only allowing names matching \`${allowNameRegex}\` but found "${tagName}".`;
|
|
63
64
|
} else {
|
|
64
|
-
message = `Prohibited context for "${
|
|
65
|
+
message = `Prohibited context for "${tagName}".`;
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
utils.reportJSDoc(message, hasRegex ? tag : null,
|
|
@@ -70,7 +71,7 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
70
71
|
// Could also supply `context`, `comment`, `tags`
|
|
71
72
|
allowName,
|
|
72
73
|
disallowName,
|
|
73
|
-
name:
|
|
74
|
+
name: tagName
|
|
74
75
|
});
|
|
75
76
|
if (!hasRegex) {
|
|
76
77
|
reported = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matchName.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","e","__esModule","default","_default","exports","iterateJsdoc","context","jsdoc","report","info","lastIndex","utils","match","options","allowName","disallowName","replacement","tags","allowNameRegex","getRegexFromString","disallowNameRegex","applicableTags","includes","getPresentTags","reported","tag","
|
|
1
|
+
{"version":3,"file":"matchName.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","e","__esModule","default","_default","exports","iterateJsdoc","context","jsdoc","report","info","lastIndex","utils","match","options","allowName","disallowName","replacement","tags","allowNameRegex","getRegexFromString","disallowNameRegex","applicableTags","includes","getPresentTags","reported","tag","tagName","name","replace","allowed","test","disallowed","hasRegex","fixer","src","source","tokens","message","reportJSDoc","undefined","matchContext","meta","docs","description","url","fixable","schema","additionalProperties","properties","items","type","comment","required","module"],"sources":["../../src/rules/matchName.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\n// eslint-disable-next-line complexity\nexport default iterateJsdoc(({\n context,\n jsdoc,\n report,\n info: {\n lastIndex,\n },\n utils,\n}) => {\n const {\n match,\n } = context.options[0] || {};\n if (!match) {\n report('Rule `no-restricted-syntax` is missing a `match` option.');\n\n return;\n }\n\n const {\n allowName,\n disallowName,\n replacement,\n tags = [\n '*',\n ],\n } = match[/** @type {import('../iterateJsdoc.js').Integer} */ (lastIndex)];\n\n const allowNameRegex = allowName && utils.getRegexFromString(allowName);\n const disallowNameRegex = disallowName && utils.getRegexFromString(disallowName);\n\n let applicableTags = jsdoc.tags;\n if (!tags.includes('*')) {\n applicableTags = utils.getPresentTags(tags);\n }\n\n let reported = false;\n for (const tag of applicableTags) {\n const tagName = tag.name.replace(/^\\[/u, '').replace(/(=.*)?\\]$/u, '');\n const allowed = !allowNameRegex || allowNameRegex.test(tagName);\n const disallowed = disallowNameRegex && disallowNameRegex.test(tagName);\n const hasRegex = allowNameRegex || disallowNameRegex;\n if (hasRegex && allowed && !disallowed) {\n continue;\n }\n\n if (!hasRegex && reported) {\n continue;\n }\n\n const fixer = () => {\n for (const src of tag.source) {\n if (src.tokens.name) {\n src.tokens.name = src.tokens.name.replace(\n disallowNameRegex, replacement,\n );\n break;\n }\n }\n };\n\n let {\n message,\n } = match[/** @type {import('../iterateJsdoc.js').Integer} */ (lastIndex)];\n if (!message) {\n if (hasRegex) {\n message = disallowed ?\n `Only allowing names not matching \\`${disallowNameRegex}\\` but found \"${tagName}\".` :\n `Only allowing names matching \\`${allowNameRegex}\\` but found \"${tagName}\".`;\n } else {\n message = `Prohibited context for \"${tagName}\".`;\n }\n }\n\n utils.reportJSDoc(\n message,\n hasRegex ? tag : null,\n\n // We could match up\n disallowNameRegex && replacement !== undefined ?\n fixer :\n null,\n false,\n {\n // Could also supply `context`, `comment`, `tags`\n allowName,\n disallowName,\n name: tagName,\n },\n );\n if (!hasRegex) {\n reported = true;\n }\n }\n}, {\n matchContext: true,\n meta: {\n docs: {\n description: 'Reports the name portion of a JSDoc tag if matching or not matching a given regular expression.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/match-name.md#repos-sticky-header',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n match: {\n additionalProperties: false,\n items: {\n properties: {\n allowName: {\n type: 'string',\n },\n comment: {\n type: 'string',\n },\n context: {\n type: 'string',\n },\n disallowName: {\n type: 'string',\n },\n message: {\n type: 'string',\n },\n tags: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n type: 'array',\n },\n },\n required: [\n 'match',\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;AAAA,IAAAG,QAAA,GAAAC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E;QACVpC,KAAK,EAAE;UACLmC,oBAAoB,EAAE,KAAK;UAC3BE,KAAK,EAAE;YACLD,UAAU,EAAE;cACVlC,SAAS,EAAE;gBACToC,IAAI,EAAE;cACR,CAAC;cACDC,OAAO,EAAE;gBACPD,IAAI,EAAE;cACR,CAAC;cACD5C,OAAO,EAAE;gBACP4C,IAAI,EAAE;cACR,CAAC;cACDnC,YAAY,EAAE;gBACZmC,IAAI,EAAE;cACR,CAAC;cACDb,OAAO,EAAE;gBACPa,IAAI,EAAE;cACR,CAAC;cACDjC,IAAI,EAAE;gBACJgC,KAAK,EAAE;kBACLC,IAAI,EAAE;gBACR,CAAC;gBACDA,IAAI,EAAE;cACR;YACF,CAAC;YACDA,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR;MACF,CAAC;MACDE,QAAQ,EAAE,CACR,OAAO,CACR;MACDF,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAAG,MAAA,CAAAjD,OAAA,GAAAA,OAAA,CAAAF,OAAA","ignoreList":[]}
|
|
@@ -73,7 +73,7 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
73
73
|
iterateAllJsdocs: true,
|
|
74
74
|
meta: {
|
|
75
75
|
docs: {
|
|
76
|
-
description: '',
|
|
76
|
+
description: 'Prevents use of multiple asterisks at the beginning of lines.',
|
|
77
77
|
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/no-multi-asterisks.md#repos-sticky-header'
|
|
78
78
|
},
|
|
79
79
|
fixable: 'code',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noMultiAsterisks.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","e","__esModule","default","middleAsterisksBlockWS","middleAsterisksNoBlockWS","endAsterisksSingleLineBlockWS","endAsterisksMultipleLineBlockWS","endAsterisksSingleLineNoBlockWS","endAsterisksMultipleLineNoBlockWS","_default","exports","iterateJsdoc","context","jsdoc","utils","allowWhitespace","preventAtEnd","preventAtMiddleLines","options","middleAsterisks","source","some","tokens","number","delimiter","tag","name","type","description","end","postDelimiter","test","fix","replace","reportJSDoc","line","isSingleLineBlock","delim","endAsterisks","endingAsterisksAndSpaces","match","trim","endFix","iterateAllJsdocs","meta","docs","url","fixable","schema","additionalProperties","properties","module"],"sources":["../../src/rules/noMultiAsterisks.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\nconst middleAsterisksBlockWS = /^([\\t ]|\\*(?!\\*))+/u;\nconst middleAsterisksNoBlockWS = /^\\*+/u;\n\nconst endAsterisksSingleLineBlockWS = /\\*((?:\\*|(?: |\\t))*)\\*$/u;\nconst endAsterisksMultipleLineBlockWS = /((?:\\*|(?: |\\t))*)\\*$/u;\n\nconst endAsterisksSingleLineNoBlockWS = /\\*(\\**)\\*$/u;\nconst endAsterisksMultipleLineNoBlockWS = /(\\**)\\*$/u;\n\nexport default iterateJsdoc(({\n context,\n jsdoc,\n utils,\n}) => {\n const {\n allowWhitespace = false,\n preventAtEnd = true,\n preventAtMiddleLines = true,\n } = context.options[0] || {};\n\n const middleAsterisks = allowWhitespace ? middleAsterisksNoBlockWS : middleAsterisksBlockWS;\n\n // eslint-disable-next-line complexity -- Todo\n jsdoc.source.some(({\n tokens,\n number,\n }) => {\n const {\n delimiter,\n tag,\n name,\n type,\n description,\n end,\n postDelimiter,\n } = tokens;\n\n if (\n preventAtMiddleLines &&\n !end && !tag && !type && !name &&\n (\n !allowWhitespace && middleAsterisks.test(description) ||\n allowWhitespace && middleAsterisks.test(postDelimiter + description)\n )\n ) {\n // console.log('description', JSON.stringify(description));\n const fix = () => {\n tokens.description = description.replace(middleAsterisks, '');\n };\n\n utils.reportJSDoc(\n 'Should be no multiple asterisks on middle lines.',\n {\n line: number,\n },\n fix,\n true,\n );\n\n return true;\n }\n\n if (!preventAtEnd || !end) {\n return false;\n }\n\n const isSingleLineBlock = delimiter === '/**';\n const delim = isSingleLineBlock ? '*' : delimiter;\n const endAsterisks = allowWhitespace ?\n (isSingleLineBlock ? endAsterisksSingleLineNoBlockWS : endAsterisksMultipleLineNoBlockWS) :\n (isSingleLineBlock ? endAsterisksSingleLineBlockWS : endAsterisksMultipleLineBlockWS);\n\n const endingAsterisksAndSpaces = (\n allowWhitespace ? postDelimiter + description + delim : description + delim\n ).match(\n endAsterisks,\n );\n\n if (\n !endingAsterisksAndSpaces ||\n !isSingleLineBlock && endingAsterisksAndSpaces[1] && !endingAsterisksAndSpaces[1].trim()\n ) {\n return false;\n }\n\n const endFix = () => {\n if (!isSingleLineBlock) {\n tokens.delimiter = '';\n }\n\n tokens.description = (description + delim).replace(endAsterisks, '');\n };\n\n utils.reportJSDoc(\n 'Should be no multiple asterisks on end lines.',\n {\n line: number,\n },\n endFix,\n true,\n );\n\n return true;\n });\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: '',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/no-multi-asterisks.md#repos-sticky-header',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n allowWhitespace: {\n type: 'boolean',\n },\n preventAtEnd: {\n type: 'boolean',\n },\n preventAtMiddleLines: {\n type: 'boolean',\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,MAAMG,sBAAsB,GAAG,qBAAqB;AACpD,MAAMC,wBAAwB,GAAG,OAAO;AAExC,MAAMC,6BAA6B,GAAG,0BAA0B;AAChE,MAAMC,+BAA+B,GAAG,wBAAwB;AAEhE,MAAMC,+BAA+B,GAAG,aAAa;AACrD,MAAMC,iCAAiC,GAAG,WAAW;AAAC,IAAAC,QAAA,GAAAC,OAA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vB,eAAe,GACjCqB,iBAAiB,GAAG7B,+BAA+B,GAAGC,iCAAiC,GACvF4B,iBAAiB,GAAG/B,6BAA6B,GAAGC,+BAAgC;IAEvF,MAAMiC,wBAAwB,GAAG,CAC/BxB,eAAe,GAAGe,aAAa,GAAGF,WAAW,GAAGS,KAAK,GAAGT,WAAW,GAAGS,KAAK,EAC3EG,KAAK,CACLF,YACF,CAAC;IAED,IACE,CAACC,wBAAwB,IACzB,CAACH,iBAAiB,IAAIG,wBAAwB,CAAC,CAAC,CAAC,IAAI,CAACA,wBAAwB,CAAC,CAAC,CAAC,CAACE,IAAI,CAAC,CAAC,EACxF;MACA,OAAO,KAAK;IACd;IAEA,MAAMC,MAAM,GAAGA,CAAA,KAAM;MACnB,IAAI,CAACN,iBAAiB,EAAE;QACtBd,MAAM,CAACE,SAAS,GAAG,EAAE;MACvB;MAEAF,MAAM,CAACM,WAAW,GAAG,CAACA,WAAW,GAAGS,KAAK,EAAEJ,OAAO,CAACK,YAAY,EAAE,EAAE,CAAC;IACtE,CAAC;IAEDxB,KAAK,CAACoB,WAAW,CACf,+CAA+C,EAC/C;MACEC,IAAI,EAAEZ;IACR,CAAC,EACDmB,MAAM,EACN,IACF,CAAC;IAED,OAAO,IAAI;EACb,CAAC,CAAC;AACJ,CAAC,EAAE;EACDC,gBAAgB,EAAE,IAAI;EACtBC,IAAI,EAAE;IACJC,IAAI,EAAE;MACJjB,WAAW,EAAE
|
|
1
|
+
{"version":3,"file":"noMultiAsterisks.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","e","__esModule","default","middleAsterisksBlockWS","middleAsterisksNoBlockWS","endAsterisksSingleLineBlockWS","endAsterisksMultipleLineBlockWS","endAsterisksSingleLineNoBlockWS","endAsterisksMultipleLineNoBlockWS","_default","exports","iterateJsdoc","context","jsdoc","utils","allowWhitespace","preventAtEnd","preventAtMiddleLines","options","middleAsterisks","source","some","tokens","number","delimiter","tag","name","type","description","end","postDelimiter","test","fix","replace","reportJSDoc","line","isSingleLineBlock","delim","endAsterisks","endingAsterisksAndSpaces","match","trim","endFix","iterateAllJsdocs","meta","docs","url","fixable","schema","additionalProperties","properties","module"],"sources":["../../src/rules/noMultiAsterisks.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\nconst middleAsterisksBlockWS = /^([\\t ]|\\*(?!\\*))+/u;\nconst middleAsterisksNoBlockWS = /^\\*+/u;\n\nconst endAsterisksSingleLineBlockWS = /\\*((?:\\*|(?: |\\t))*)\\*$/u;\nconst endAsterisksMultipleLineBlockWS = /((?:\\*|(?: |\\t))*)\\*$/u;\n\nconst endAsterisksSingleLineNoBlockWS = /\\*(\\**)\\*$/u;\nconst endAsterisksMultipleLineNoBlockWS = /(\\**)\\*$/u;\n\nexport default iterateJsdoc(({\n context,\n jsdoc,\n utils,\n}) => {\n const {\n allowWhitespace = false,\n preventAtEnd = true,\n preventAtMiddleLines = true,\n } = context.options[0] || {};\n\n const middleAsterisks = allowWhitespace ? middleAsterisksNoBlockWS : middleAsterisksBlockWS;\n\n // eslint-disable-next-line complexity -- Todo\n jsdoc.source.some(({\n tokens,\n number,\n }) => {\n const {\n delimiter,\n tag,\n name,\n type,\n description,\n end,\n postDelimiter,\n } = tokens;\n\n if (\n preventAtMiddleLines &&\n !end && !tag && !type && !name &&\n (\n !allowWhitespace && middleAsterisks.test(description) ||\n allowWhitespace && middleAsterisks.test(postDelimiter + description)\n )\n ) {\n // console.log('description', JSON.stringify(description));\n const fix = () => {\n tokens.description = description.replace(middleAsterisks, '');\n };\n\n utils.reportJSDoc(\n 'Should be no multiple asterisks on middle lines.',\n {\n line: number,\n },\n fix,\n true,\n );\n\n return true;\n }\n\n if (!preventAtEnd || !end) {\n return false;\n }\n\n const isSingleLineBlock = delimiter === '/**';\n const delim = isSingleLineBlock ? '*' : delimiter;\n const endAsterisks = allowWhitespace ?\n (isSingleLineBlock ? endAsterisksSingleLineNoBlockWS : endAsterisksMultipleLineNoBlockWS) :\n (isSingleLineBlock ? endAsterisksSingleLineBlockWS : endAsterisksMultipleLineBlockWS);\n\n const endingAsterisksAndSpaces = (\n allowWhitespace ? postDelimiter + description + delim : description + delim\n ).match(\n endAsterisks,\n );\n\n if (\n !endingAsterisksAndSpaces ||\n !isSingleLineBlock && endingAsterisksAndSpaces[1] && !endingAsterisksAndSpaces[1].trim()\n ) {\n return false;\n }\n\n const endFix = () => {\n if (!isSingleLineBlock) {\n tokens.delimiter = '';\n }\n\n tokens.description = (description + delim).replace(endAsterisks, '');\n };\n\n utils.reportJSDoc(\n 'Should be no multiple asterisks on end lines.',\n {\n line: number,\n },\n endFix,\n true,\n );\n\n return true;\n });\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Prevents use of multiple asterisks at the beginning of lines.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/no-multi-asterisks.md#repos-sticky-header',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n allowWhitespace: {\n type: 'boolean',\n },\n preventAtEnd: {\n type: 'boolean',\n },\n preventAtMiddleLines: {\n type: 'boolean',\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,MAAMG,sBAAsB,GAAG,qBAAqB;AACpD,MAAMC,wBAAwB,GAAG,OAAO;AAExC,MAAMC,6BAA6B,GAAG,0BAA0B;AAChE,MAAMC,+BAA+B,GAAG,wBAAwB;AAEhE,MAAMC,+BAA+B,GAAG,aAAa;AACrD,MAAMC,iCAAiC,GAAG,WAAW;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAR,OAAA,GAEvC,IAAAS,qBAAY,EAAC,CAAC;EAC3BC,OAAO;EACPC,KAAK;EACLC;AACF,CAAC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json
CHANGED
package/src/rules/matchName.js
CHANGED
|
@@ -38,8 +38,9 @@ export default iterateJsdoc(({
|
|
|
38
38
|
|
|
39
39
|
let reported = false;
|
|
40
40
|
for (const tag of applicableTags) {
|
|
41
|
-
const
|
|
42
|
-
const
|
|
41
|
+
const tagName = tag.name.replace(/^\[/u, '').replace(/(=.*)?\]$/u, '');
|
|
42
|
+
const allowed = !allowNameRegex || allowNameRegex.test(tagName);
|
|
43
|
+
const disallowed = disallowNameRegex && disallowNameRegex.test(tagName);
|
|
43
44
|
const hasRegex = allowNameRegex || disallowNameRegex;
|
|
44
45
|
if (hasRegex && allowed && !disallowed) {
|
|
45
46
|
continue;
|
|
@@ -66,10 +67,10 @@ export default iterateJsdoc(({
|
|
|
66
67
|
if (!message) {
|
|
67
68
|
if (hasRegex) {
|
|
68
69
|
message = disallowed ?
|
|
69
|
-
`Only allowing names not matching \`${disallowNameRegex}\` but found "${
|
|
70
|
-
`Only allowing names matching \`${allowNameRegex}\` but found "${
|
|
70
|
+
`Only allowing names not matching \`${disallowNameRegex}\` but found "${tagName}".` :
|
|
71
|
+
`Only allowing names matching \`${allowNameRegex}\` but found "${tagName}".`;
|
|
71
72
|
} else {
|
|
72
|
-
message = `Prohibited context for "${
|
|
73
|
+
message = `Prohibited context for "${tagName}".`;
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
|
|
@@ -86,7 +87,7 @@ export default iterateJsdoc(({
|
|
|
86
87
|
// Could also supply `context`, `comment`, `tags`
|
|
87
88
|
allowName,
|
|
88
89
|
disallowName,
|
|
89
|
-
name:
|
|
90
|
+
name: tagName,
|
|
90
91
|
},
|
|
91
92
|
);
|
|
92
93
|
if (!hasRegex) {
|
|
@@ -108,7 +108,7 @@ export default iterateJsdoc(({
|
|
|
108
108
|
iterateAllJsdocs: true,
|
|
109
109
|
meta: {
|
|
110
110
|
docs: {
|
|
111
|
-
description: '',
|
|
111
|
+
description: 'Prevents use of multiple asterisks at the beginning of lines.',
|
|
112
112
|
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/no-multi-asterisks.md#repos-sticky-header',
|
|
113
113
|
},
|
|
114
114
|
fixable: 'code',
|