UNPKG

eslint-plugin-jsdoc

Version:
1 lines 8.98 kB
{"version":3,"file":"matchName.cjs","names":["iterateJsdoc"],"sources":["../../src/rules/matchName.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\nexport default iterateJsdoc(({\n context,\n info: {\n lastIndex,\n },\n jsdoc,\n report,\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(/^\\[/v, '').replace(/(=.*)?\\]$/v, '');\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 description: `\\`match\\` is a required option containing an array of objects which determine\nthe conditions whereby a name is reported as being problematic.\n\nThese objects can have any combination of the following groups of optional\nproperties, all of which act to confine one another.\n\nNote that \\`comment\\`, even if targeting a specific tag, is used to match the\nwhole block. So if a \\`comment\\` finds its specific tag, it may still apply\nfixes found by the likes of \\`disallowName\\` even when a different tag has the\ndisallowed name. An alternative is to ensure that \\`comment\\` finds the specific\ntag of the desired tag and/or name and no \\`disallowName\\` (or \\`allowName\\`) is\nsupplied. In such a case, only one error will be reported, but no fixer will\nbe applied, however.`,\n items: {\n additionalProperties: false,\n properties: {\n allowName: {\n description: `Indicates which names are allowed for the given tag (or \\`*\\`).\nAccepts a string regular expression (optionally wrapped between two\n\\`/\\` delimiters followed by optional flags) used to match the name.`,\n type: 'string',\n },\n comment: {\n description: 'As with `context` but AST for the JSDoc block comment and types.',\n type: 'string',\n },\n context: {\n description: `AST to confine the allowing or disallowing to JSDoc blocks\nassociated with a particular context. See the\n[\"AST and Selectors\"](../advanced.md#ast-and-selectors)\nsection of our Advanced docs for more on the expected format.`,\n type: 'string',\n },\n disallowName: {\n description: 'As with `allowName` but indicates names that are not allowed.',\n type: 'string',\n },\n message: {\n description: 'An optional custom message to use when there is a match.',\n type: 'string',\n },\n replacement: {\n description: `If \\`disallowName\\` is supplied and this value is present, it\nwill replace the matched \\`disallowName\\` text.`,\n type: 'string',\n },\n tags: {\n description: `This array should include tag names or \\`*\\` to indicate the\n match will apply for all tags (except as confined by any context\n properties). If \\`*\\` is not used, then these rules will only apply to\n the specified tags. If \\`tags\\` is omitted, then \\`*\\` is assumed.`,\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;AAA8C;AAAA,iCAE/B,IAAAA,qBAAY,EAAC,CAAC;EAC3B,OAAO;EACP,IAAI,EAAE;IACJ;EACF,CAAC;EACD,KAAK;EACL,MAAM;EACN;AACF,CAAC,KAAK;EACJ,MAAM;IACJ;EACF,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;EAC5B,IAAI,CAAC,KAAK,EAAE;IACV,MAAM,CAAC,0DAA0D,CAAC;IAElE;EACF;EAEA,MAAM;IACJ,SAAS;IACT,YAAY;IACZ,WAAW;IACX,IAAI,GAAG,CACL,GAAG;EAEP,CAAC,GAAG,KAAK,EAAC,mDAAqD,SAAS,EAAE;EAE1E,MAAM,cAAc,GAAG,SAAS,IAAI,KAAK,CAAC,kBAAkB,CAAC,SAAS,CAAC;EACvE,MAAM,iBAAiB,GAAG,YAAY,IAAI,KAAK,CAAC,kBAAkB,CAAC,YAAY,CAAC;EAEhF,IAAI,cAAc,GAAG,KAAK,CAAC,IAAI;EAC/B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;IACvB,cAAc,GAAG,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC;EAC7C;EAEA,IAAI,QAAQ,GAAG,KAAK;EACpB,KAAK,MAAM,GAAG,IAAI,cAAc,EAAE;IAChC,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;IACtE,MAAM,OAAO,GAAG,CAAC,cAAc,IAAI,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC;IAC/D,MAAM,UAAU,GAAG,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