{"version":3,"sources":["../../src/rules/matchDescription.js"],"names":["matchDescriptionDefault","stringOrDefault","value","userDefault","jsdoc","report","context","utils","mainDescription","matchDescription","message","tags","options","validateDescription","description","tag","mainDescriptionMatch","errorMessage","match","tagValue","tagName","regex","getRegexFromString","test","line","source","number","getDescription","replace","Object","keys","length","hasOptionTag","Boolean","forEachPreferredTag","matchingJsdocTag","targetTagName","name","getTagDescription","trim","whitelistedTags","filterTags","tagsWithNames","tagsWithoutNames","getTagsByType","some","contextDefaults","meta","docs","url","schema","additionalProperties","properties","contexts","items","anyOf","type","comment","oneOf","format","patternProperties","enum"],"mappings":";;;;;;;AAAA;;;;AAEA;AACA;AACA,MAAMA,uBAAuB,GAAG,6BAAhC;;AAEA,MAAMC,eAAe,GAAG,CAACC,KAAD,EAAQC,WAAR,KAAwB;AAC9C,SAAO,OAAOD,KAAP,KAAiB,QAAjB,GACLA,KADK,GAELC,WAAW,IAAIH,uBAFjB;AAGD,CAJD;;eAMe,2BAAa,CAAC;AAC3BI,EAAAA,KAD2B;AAE3BC,EAAAA,MAF2B;AAG3BC,EAAAA,OAH2B;AAI3BC,EAAAA;AAJ2B,CAAD,KAKtB;AACJ,QAAM;AACJC,IAAAA,eADI;AAEJC,IAAAA,gBAFI;AAGJC,IAAAA,OAHI;AAIJC,IAAAA;AAJI,MAKFL,OAAO,CAACM,OAAR,CAAgB,CAAhB,KAAsB,EAL1B;;AAOA,QAAMC,mBAAmB,GAAG,CAACC,WAAD,EAAcC,GAAd,KAAsB;AAChD,QAAIC,oBAAoB,GAAGR,eAA3B;AACA,QAAIS,YAAY,GAAGP,OAAnB;;AACA,QAAI,OAAOF,eAAP,KAA2B,QAA/B,EAAyC;AACvCQ,MAAAA,oBAAoB,GAAGR,eAAe,CAACU,KAAvC;AACAD,MAAAA,YAAY,GAAGT,eAAe,CAACE,OAA/B;AACD;;AACD,QAAI,CAACK,GAAD,IAAQC,oBAAoB,KAAK,KAArC,EAA4C;AAC1C;AACD;;AAED,QAAI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AE;AADC,SA1DC;AA6DV7C,QAAAA,IAAI,EAAE;AACJiD,UAAAA,iBAAiB,EAAE;AACjB,kBAAM;AACJF,cAAAA,KAAK,EAAE,CACL;AACEC,gBAAAA,MAAM,EAAE,OADV;AAEEH,gBAAAA,IAAI,EAAE;AAFR,eADK,EAKL;AACEK,gBAAAA,IAAI,EAAE,CAAC,IAAD,CADR;AAEEL,gBAAAA,IAAI,EAAE;AAFR,eALK,EASL;AACEL,gBAAAA,oBAAoB,EAAE,KADxB;AAEEC,gBAAAA,UAAU,EAAE;AACVlC,kBAAAA,KAAK,EAAE;AACLwC,oBAAAA,KAAK,EAAE,CACL;AACEC,sBAAAA,MAAM,EAAE,OADV;AAEEH,sBAAAA,IAAI,EAAE;AAFR,qBADK,EAKL;AACEK,sBAAAA,IAAI,EAAE,CAAC,IAAD,CADR;AAEEL,sBAAAA,IAAI,EAAE;AAFR,qBALK;AADF,mBADG;AAaV9C,kBAAAA,OAAO,EAAE;AACP8C,oBAAAA,IAAI,EAAE;AADC;AAbC,iBAFd;AAmBEA,gBAAAA,IAAI,EAAE;AAnBR,eATK;AADH;AADW,WADf;AAoCJA,UAAAA,IAAI,EAAE;AApCF;AA7DI,OAFd;AAsGEA,MAAAA,IAAI,EAAE;AAtGR,KADM,CALJ;AA+GJA,IAAAA,IAAI,EAAE;AA/GF;AAFL,CAzFY,C","sourcesContent":["import iterateJsdoc from '../iterateJsdoc';\n\n// If supporting Node >= 10, we could loosen the default to this for the\n// initial letter: \\\\p{Upper}\nconst matchDescriptionDefault = '^[A-Z`\\\\d_][\\\\s\\\\S]*[.?!`]$';\n\nconst stringOrDefault = (value, userDefault) => {\n return typeof value === 'string' ?\n value :\n userDefault || matchDescriptionDefault;\n};\n\nexport default iterateJsdoc(({\n jsdoc,\n report,\n context,\n utils,\n}) => {\n const {\n mainDescription,\n matchDescription,\n message,\n tags,\n } = context.options[0] || {};\n\n const validateDescription = (description, tag) => {\n let mainDescriptionMatch = mainDescription;\n let errorMessage = message;\n if (typeof mainDescription === 'object') {\n mainDescriptionMatch = mainDescription.match;\n errorMessage = mainDescription.message;\n }\n if (!tag && mainDescriptionMatch === false) {\n return;\n }\n\n let tagValue = mainDescriptionMatch;\n if (tag) {\n const tagName = tag.tag;\n if (typeof tags[tagName] === 'object') {\n tagValue = tags[tagName].match;\n errorMessage = tags[tagName].message;\n } else {\n tagValue = tags[tagName];\n }\n }\n\n const regex = utils.getRegexFromString(\n stringOrDefault(tagValue, matchDescription),\n );\n\n if (!regex.test(description)) {\n report(\n errorMessage || 'JSDoc description does not satisfy the regex pattern.',\n null,\n tag || {\n // Add one as description would typically be into block\n line: jsdoc.source[0].number + 1,\n },\n );\n }\n };\n\n if (jsdoc.description) {\n const {description} = utils.getDescription();\n validateDescription(\n description.replace(/\\s+$/, ''),\n );\n }\n\n if (!tags || !Object.keys(tags).length) {\n return;\n }\n\n const hasOptionTag = (tagName) => {\n return Boolean(tags[tagName]);\n };\n\n utils.forEachPreferredTag('description', (matchingJsdocTag, targetTagName) => {\n const description = (matchingJsdocTag.name + ' ' + utils.getTagDescription(matchingJsdocTag)).trim();\n if (hasOptionTag(targetTagName)) {\n validateDescription(description, matchingJsdocTag);\n }\n }, true);\n\n const whitelistedTags = utils.filterTags(({tag: tagName}) => {\n return hasOptionTag(tagName);\n });\n const {tagsWithNames, tagsWithoutNames} = utils.getTagsByType(whitelistedTags);\n\n tagsWithNames.some((tag) => {\n const description = utils.getTagDescription(tag).replace(/^[- ]*/u, '').trim();\n\n return validateDescription(description, tag);\n });\n\n tagsWithoutNames.some((tag) => {\n const description = (tag.name + ' ' + utils.getTagDescription(tag)).trim();\n\n return validateDescription(description, tag);\n });\n}, {\n contextDefaults: true,\n meta: {\n docs: {\n description: 'Enforces a regular expression pattern on descriptions.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-match-description',\n },\n schema: [\n {\n additionalProperties: false,\n properties: {\n contexts: {\n items: {\n anyOf: [\n {\n type: 'string',\n },\n {\n additionalProperties: false,\n properties: {\n comment: {\n type: 'string',\n },\n context: {\n type: 'string',\n },\n },\n type: 'object',\n },\n ],\n },\n type: 'array',\n },\n mainDescription: {\n oneOf: [\n {\n format: 'regex',\n type: 'string',\n },\n {\n type: 'boolean',\n },\n {\n additionalProperties: false,\n properties: {\n match: {\n oneOf: [\n {\n format: 'regex',\n type: 'string',\n },\n {\n type: 'boolean',\n },\n ],\n },\n message: {\n type: 'string',\n },\n },\n type: 'object',\n },\n ],\n },\n matchDescription: {\n format: 'regex',\n type: 'string',\n },\n message: {\n type: 'string',\n },\n tags: {\n patternProperties: {\n '.*': {\n oneOf: [\n {\n format: 'regex',\n type: 'string',\n },\n {\n enum: [true],\n type: 'boolean',\n },\n {\n additionalProperties: false,\n properties: {\n match: {\n oneOf: [\n {\n format: 'regex',\n type: 'string',\n },\n {\n enum: [true],\n type: 'boolean',\n },\n ],\n },\n message: {\n type: 'string',\n },\n },\n type: 'object',\n },\n ],\n },\n },\n type: 'object',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"file":"matchDescription.js"}