1 |
- {"version":3,"sources":["../../src/rules/newlineAfterDescription.js"],"names":["jsdoc","report","context","jsdocNode","sourceCode","indent","utils","always","description","trim","tags","length","_","has","options","lastDescriptionLine","getDescription","descriptionEndsWithANewline","test","sourceLines","getText","split","fixer","injectedLine","endsWith","splice","replaceText","join","line","iterateAllJsdocs","meta","docs","url","fixable","schema","enum","type"],"mappings":";;;;;;;AAAA;;AACA;;;;eAEe,2BAAa,CAAC;AAC3BA,EAAAA,KAD2B;AAE3BC,EAAAA,MAF2B;AAG3BC,EAAAA,OAH2B;AAI3BC,EAAAA,SAJ2B;AAK3BC,EAAAA,UAL2B;AAM3BC,EAAAA,MAN2B;AAO3BC,EAAAA;AAP2B,CAAD,KAQtB;AACJ,MAAIC,MAAJ;;AAEA,MAAI,CAACP,KAAK,CAACQ,WAAN,CAAkBC,IAAlB,EAAD,IAA6B,CAACT,KAAK,CAACU,IAAN,CAAWC,MAA7C,EAAqD;AACnD;AACD;;AAED,MAAIC,gBAAEC,GAAF,CAAMX,OAAO,CAACY,OAAd,EAAuB,CAAvB,CAAJ,EAA+B;AAC7BP,IAAAA,MAAM,GAAGL,OAAO,CAACY,OAAR,CAAgB,CAAhB,MAAuB,QAAhC;AACD,GAFD,MAEO;AACLP,IAAAA,MAAM,GAAG,IAAT;AACD;;AAED,QAAM;AAACC,IAAAA,WAAD;AAAcO,IAAAA;AAAd,MAAqCT,KAAK,CAACU,cAAN,EAA3C;AACA,QAAMC,2BAA2B,GAAI,QAAD,CAAWC,IAAX,CAAgBV,WAAhB,CAApC;;AAEA,MAAID,MAAJ,EAAY;AACV,QAAI,CAACU,2BAAL,EAAkC;AAChC,YAAME,WAAW,GAAGf,UAAU,CAACgB,OAAX,CAAmBjB,SAAnB,EAA8BkB,KAA9B,CAAoC,IAApC,CAApB;AAEApB,MAAAA,MAAM,CAAC,mEAAD,EAAuEqB,KAAD,IAAW;AACrF;AACA,cAAMC,YAAY,GAAI,GAAElB,MAAO,IAAV,IAClBc,WAAW,CA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c(({\n jsdoc,\n report,\n context,\n jsdocNode,\n sourceCode,\n indent,\n utils,\n}) => {\n let always;\n\n if (!jsdoc.description.trim() || !jsdoc.tags.length) {\n return;\n }\n\n if (_.has(context.options, 0)) {\n always = context.options[0] === 'always';\n } else {\n always = true;\n }\n\n const {description, lastDescriptionLine} = utils.getDescription();\n const descriptionEndsWithANewline = (/\\n\\r?$/).test(description);\n\n if (always) {\n if (!descriptionEndsWithANewline) {\n const sourceLines = sourceCode.getText(jsdocNode).split('\\n');\n\n report('There must be a newline after the description of the JSDoc block.', (fixer) => {\n // Add the new line\n const injectedLine = `${indent} *` +\n (sourceLines[lastDescriptionLine].endsWith('\\r') ? '\\r' : '');\n sourceLines.splice(lastDescriptionLine + 1, 0, injectedLine);\n\n return fixer.replaceText(jsdocNode, sourceLines.join('\\n'));\n }, {\n line: lastDescriptionLine,\n });\n }\n } else if (descriptionEndsWithANewline) {\n const sourceLines = sourceCode.getText(jsdocNode).split('\\n');\n report('There must be no newline after the description of the JSDoc block.', (fixer) => {\n // Remove the extra line\n sourceLines.splice(lastDescriptionLine, 1);\n\n return fixer.replaceText(jsdocNode, sourceLines.join('\\n'));\n }, {\n line: lastDescriptionLine,\n });\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Enforces a consistent padding of the block description.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-newline-after-description',\n },\n fixable: 'whitespace',\n schema: [\n {\n enum: ['always', 'never'],\n type: 'string',\n },\n ],\n type: 'layout',\n },\n});\n"],"file":"newlineAfterDescription.js"}
|