UNPKG

eslint-plugin-jsdoc

Version:
1 lines 6.42 kB
{"version":3,"file":"noMultiAsterisks.cjs","names":["iterateJsdoc"],"sources":["../../src/rules/noMultiAsterisks.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\nconst middleAsterisksBlockWS = /^([\\t ]|\\*(?!\\*))+/v;\nconst middleAsterisksNoBlockWS = /^\\*+/v;\n\nconst endAsterisksSingleLineBlockWS = /\\*((?:\\*|(?: |\\t))*)\\*$/v;\nconst endAsterisksMultipleLineBlockWS = /((?:\\*|(?: |\\t))*)\\*$/v;\n\nconst endAsterisksSingleLineNoBlockWS = /\\*(\\**)\\*$/v;\nconst endAsterisksMultipleLineNoBlockWS = /(\\**)\\*$/v;\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 jsdoc.source.some(({\n number,\n tokens,\n }) => {\n const {\n delimiter,\n description,\n end,\n name,\n postDelimiter,\n tag,\n type,\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 description: `Set to \\`true\\` if you wish to allow asterisks after a space (as with Markdown):\n\n\\`\\`\\`js\n/**\n * *bold* text\n */\n\\`\\`\\`\n\nDefaults to \\`false\\`.`,\n type: 'boolean',\n },\n preventAtEnd: {\n description: `Prevent the likes of this:\n\n\\`\\`\\`js\n/**\n *\n *\n **/\n\\`\\`\\`\n\nDefaults to \\`true\\`.`,\n type: 'boolean',\n },\n preventAtMiddleLines: {\n description: `Prevent the likes of this:\n\n\\`\\`\\`js\n/**\n *\n **\n */\n\\`\\`\\`\n\nDefaults to \\`true\\`.`,\n type: 'boolean',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA;AAA8C;AAE9C,MAAM,sBAAsB,GAAG,qBAAqB;AACpD,MAAM,wBAAwB,GAAG,OAAO;AAExC,MAAM,6BAA6B,GAAG,0BAA0B;AAChE,MAAM,+BAA+B,GAAG,wBAAwB;AAEhE,MAAM,+BAA+B,GAAG,aAAa;AACrD,MAAM,iCAAiC,GAAG,WAAW;AAAC,iCAEvC,IA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