1 |
- {"version":3,"sources":["../../src/rules/requireHyphenBeforeParamDescription.js"],"names":["sourceCode","utils","report","context","jsdoc","jsdocNode","mainCircumstance","tags","options","checkHyphens","jsdocTag","targetTagName","circumstance","always","desc","getTagDescription","trim","startsWithHyphen","test","fixer","lineIndex","line","sourceLines","getText","split","description","descriptionIndex","lastIndexOf","replacementLine","slice","splice","replacement","join","replaceText","unwantedPart","exec","replace","length","forEachPreferredTag","tagEntries","Object","entries","forEach","tagName","preferredParamTag","getPreferredTagName","tag","some","tagNme","iterateAllJsdocs","meta","docs","url","fixable","schema","enum","type","additionalProperties","properties","anyOf","patternProperties"],"mappings":";;;;;;;AAAA;;;;eAEe,2BAAa,CAAC;AAC3BA,EAAAA,UAD2B;AAE3BC,EAAAA,KAF2B;AAG3BC,EAAAA,MAH2B;AAI3BC,EAAAA,OAJ2B;AAK3BC,EAAAA,KAL2B;AAM3BC,EAAAA;AAN2B,CAAD,KAOtB;AACJ,QAAM,CAACC,gBAAD,EAAmB;AAACC,IAAAA;AAAD,MAAS,EAA5B,IAAkCJ,OAAO,CAACK,OAAhD;;AAEA,QAAMC,YAAY,GAAG,CAACC,QAAD,EAAWC,aAAX,EAA0BC,YAAY,GAAGN,gBAAzC,KAA8D;AACjF,UAAMO,MAAM,GAAG,CAACD,YAAD,IAAiBA,YAAY,KAAK,QAAjD;AACA,UAAME,IAAI,GAAGb,KAAK,CAACc,iBAAN,CAAwBL,QAAxB,CAAb;;AACA,QAAI,CAACI,IAAI,CAACE,IAAL,EAAL,EAAkB;AAChB;AACD;;AAED,UAAMC,gBAAgB,GAAI,QAAD,CAAWC,IAAX,CAAgBJ,IAAhB,CAAzB;;AACA,QAAID,MAAJ,EAAY;AACV,UAAI,CAACI,gBAAL,EAAuB;AACrBf,QAAAA,MAAM,CAAE,kCAAiCS,aAAc,eAAjD,EAAkEQ,KAAD,IAAW;AAChF,gBAAMC,SAAS,GAAGV,QAAQ,CAACW,IAA3B;AACA,gBAAMC,WAAW,GAAGtB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AAI,EAAE;AAFR,KADM,EAKN;AACEC,MAAAA,oBAAoB,EAAE,KADxB;AAEEC,MAAAA,UAAU,EAAE;AACVnD,QAAAA,IAAI,EAAE;AACJoD,UAAAA,KAAK,EAAE,CACL;AACEC,YAAAA,iBAAiB,EAAE;AACjB,oBAAM;AACJL,gBAAAA,IAAI,EAAE,CAAC,QAAD,EAAW,OAAX,CADF;AAEJC,gBAAAA,IAAI,EAAE;AAFF;AADW,aADrB;AAOEA,YAAAA,IAAI,EAAE;AAPR,WADK,EAUL;AACED,YAAAA,IAAI,EAAE,CAAC,KAAD,CADR;AAEEC,YAAAA,IAAI,EAAE;AAFR,WAVK;AADH;AADI,OAFd;AAqBEA,MAAAA,IAAI,EAAE;AArBR,KALM,CANJ;AAmCJA,IAAAA,IAAI,EAAE;AAnCF;AAFL,CAzEY,C","sourcesContent":["import iterateJsdoc from '../iterateJsdoc';\n\nexport default iterateJsdoc(({\n sourceCode,\n utils,\n report,\n context,\n jsdoc,\n jsdocNode,\n}) => {\n const [mainCircumstance, {tags} = {}] = context.options;\n\n const checkHyphens = (jsdocTag, targetTagName, circumstance = mainCircumstance) => {\n const always = !circumstance || circumstance === 'always';\n const desc = utils.getTagDescription(jsdocTag);\n if (!desc.trim()) {\n return;\n }\n\n const startsWithHyphen = (/^\\s*-/u).test(desc);\n if (always) {\n if (!startsWithHyphen) {\n report(`There must be a hyphen before @${targetTagName} description.`, (fixer) => {\n const lineIndex = jsdocTag.line;\n const sourceLines = sourceCode.getText(jsdocNode).split('\\n');\n\n // Get start index of description, accounting for multi-line descriptions\n const description = desc.split('\\n')[0];\n const descriptionIndex = sourceLines[lineIndex].lastIndexOf(description);\n\n const replacementLine = sourceLines[lineIndex]\n .slice(0, descriptionIndex) + '- ' + description;\n sourceLines.splice(lineIndex, 1, replacementLine);\n const replacement = sourceLines.join('\\n');\n\n return fixer.replaceText(jsdocNode, replacement);\n }, jsdocTag);\n }\n } else if (startsWithHyphen) {\n report(`There must be no hyphen before @${targetTagName} description.`, (fixer) => {\n const [unwantedPart] = /^\\s*-\\s*/u.exec(desc);\n\n const replacement = sourceCode\n .getText(jsdocNode)\n .replace(desc, desc.slice(unwantedPart.length));\n\n return fixer.replaceText(jsdocNode, replacement);\n }, jsdocTag);\n }\n };\n\n utils.forEachPreferredTag('param', checkHyphens);\n if (tags) {\n const tagEntries = Object.entries(tags);\n tagEntries.forEach(([tagName, circumstance]) => {\n if (tagName === '*') {\n const preferredParamTag = utils.getPreferredTagName({tagName: 'param'});\n jsdoc.tags.forEach(({tag}) => {\n if (tag === preferredParamTag || tagEntries.some(([tagNme]) => {\n return tagNme !== '*' && tagNme === tag;\n })) {\n return;\n }\n utils.forEachPreferredTag(tag, (jsdocTag, targetTagName) => {\n checkHyphens(jsdocTag, targetTagName, circumstance);\n });\n });\n\n return;\n }\n utils.forEachPreferredTag(tagName, (jsdocTag, targetTagName) => {\n checkHyphens(jsdocTag, targetTagName, circumstance);\n });\n });\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Requires a hyphen before the `@param` description.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-hyphen-before-param-description',\n },\n fixable: 'code',\n schema: [\n {\n enum: ['always', 'never'],\n type: 'string',\n },\n {\n additionalProperties: false,\n properties: {\n tags: {\n anyOf: [\n {\n patternProperties: {\n '.*': {\n enum: ['always', 'never'],\n type: 'string',\n },\n },\n type: 'object',\n },\n {\n enum: ['any'],\n type: 'string',\n },\n ],\n },\n },\n type: 'object',\n },\n ],\n type: 'layout',\n },\n});\n"],"file":"requireHyphenBeforeParamDescription.js"}
|