UNPKG

eslint-plugin-jsdoc

Version:
1 lines 8.39 kB
{"version":3,"file":"requireAsteriskPrefix.cjs","names":["iterateJsdoc"],"sources":["../../src/rules/requireAsteriskPrefix.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\nexport default iterateJsdoc(({\n context,\n indent,\n jsdoc,\n utils,\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 /** @type {string} */\n let currentTag;\n source.some(({\n number,\n tokens,\n }) => {\n const {\n delimiter,\n description,\n end,\n tag,\n } = tokens;\n\n /**\n * @returns {void}\n */\n const neverFix = () => {\n tokens.delimiter = '';\n tokens.postDelimiter = '';\n };\n\n /**\n * @param {string} checkValue\n * @returns {boolean}\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 /**\n * @returns {void}\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 /**\n * @param {string} checkValue\n * @returns {boolean}\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 docs: {\n description:\n 'Requires that each JSDoc line starts with an `*`.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-asterisk-prefix.md#repos-sticky-header',\n },\n fixable: 'code',\n schema: [\n {\n description: `If it is \\`\"always\"\\` then a problem is raised when there is no asterisk\nprefix on a given JSDoc line. If it is \\`\"never\"\\` then a problem is raised\nwhen there is an asterisk present.\n\nThe default value is \\`\"always\"\\`. You may also set the default to \\`\"any\"\\`\nand use the \\`tags\\` option to apply to specific tags only.`,\n enum: [\n 'always', 'never', 'any',\n ],\n type: 'string',\n },\n {\n additionalProperties: false,\n properties: {\n tags: {\n additionalProperties: false,\n description: `If you want different values to apply to specific tags, you may use\nthe \\`tags\\` option object. The keys are \\`always\\`, \\`never\\`, or \\`any\\` and\nthe values are arrays of tag names or the special value \\`*description\\`\nwhich applies to the main JSDoc block description.\n\n\\`\\`\\`js\n{\n 'jsdoc/require-asterisk-prefix': ['error', 'always', {\n tags: {\n always: ['*description'],\n any: ['example', 'license'],\n never: ['copyright']\n }\n }]\n}\n\\`\\`\\``,\n properties: {\n always: {\n description: `If it is \\`\"always\"\\` then a problem is raised when there is no asterisk\nprefix on a given JSDoc line.`,\n items: {\n type: 'string',\n },\n type: 'array',\n },\n any: {\n description: 'No problem is raised regardless of asterisk presence or non-presence.',\n items: {\n type: 'string',\n },\n type: 'array',\n },\n never: {\n description: `If it is \\`\"never\"\\` then a problem is raised\nwhen there is an asterisk present.`,\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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