|
1 |
- {"version":3,"sources":["../../src/rules/multilineBlocks.js"],"names":["context","jsdoc","utils","allowMultipleTags","noFinalLineText","noZeroLineText","noSingleLineBlocks","singleLineTags","noMultilineBlocks","minimumLengthForMultiline","Number","POSITIVE_INFINITY","multilineTags","options","source","tokens","description","tag","sourceLength","length","isInvalidSingleLine","tagName","includes","slice","fixer","makeMultiline","reportJSDoc","lineChecks","line","emptyTokens","delimiter","start","addLine","finalLine","finalLineTokens","trim","trimEnd","forEach","prop","end","tags","hasATag","filterTags","tg","number","reduce","obj","desc","type","typ","name","nme","lineEnd","postType","postName","postTag","nameOrDescription","seedTokens","postDelimiter","iterateAllJsdocs","meta","docs","url","fixable","schema","additionalProperies","properties","anyOf","enum","items"],"mappings":";;;;;;;AAAA;;;;eAEe,2BAAa,CAAC;AAC3BA,EAAAA,OAD2B;AAE3BC,EAAAA,KAF2B;AAG3BC,EAAAA;AAH2B,CAAD,KAItB;AACJ,QAAM;AACJC,IAAAA,iBAAiB,GAAG,IADhB;AAEJC,IAAAA,eAAe,GAAG,IAFd;AAGJC,IAAAA,cAAc,GAAG,IAHb;AAIJC,IAAAA,kBAAkB,GAAG,KAJjB;AAKJC,IAAAA,cAAc,GAAG,CAAC,OAAD,EAAU,MAAV,CALb;AAMJC,IAAAA,iBAAiB,GAAG,KANhB;AAOJC,IAAAA,yBAAyB,GAAGC,MAAM,CAACC,iBAP/B;AAQJC,IAAAA,aAAa,GAAG,CAAC,GAAD;AARZ,MASFZ,OAAO,CAACa,OAAR,CAAgB,CAAhB,KAAsB,EAT1B;AAWA,QAAM;AAACC,IAAAA,MAAM,EAAE,CAAC;AAACC,MAAAA;AAAD,KAAD;AAAT,MAAuBd,KAA7B;AACA,QAAM;AAACe,IAAAA,WAAD;AAAcC,IAAAA;AAAd,MAAqBF,MAA3B;AACA,QAAMG,YAAY,GAAGjB,KAAK,CAACa,MAAN,CAAaK,MAAlC;;AAEA,QAAMC,mBAAmB,GAAIC,OAAD,IAAa;AACvC,WAA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EAAE,KADvB;AAEEC,MAAAA,UAAU,EAAE;AACV/D,QAAAA,iBAAiB,EAAE;AACjB6C,UAAAA,IAAI,EAAE;AADW,SADT;AAIVvC,QAAAA,yBAAyB,EAAE;AACzBuC,UAAAA,IAAI,EAAE;AADmB,SAJjB;AAOVpC,QAAAA,aAAa,EAAE;AACbuD,UAAAA,KAAK,EAAE,CACL;AACEC,YAAAA,IAAI,EAAE,CAAC,GAAD,CADR;AAEEpB,YAAAA,IAAI,EAAE;AAFR,WADK,EAIF;AACDqB,YAAAA,KAAK,EAAE;AACLrB,cAAAA,IAAI,EAAE;AADD,aADN;AAIDA,YAAAA,IAAI,EAAE;AAJL,WAJE;AADM,SAPL;AAoBV5C,QAAAA,eAAe,EAAE;AACf4C,UAAAA,IAAI,EAAE;AADS,SApBP;AAuBVxC,QAAAA,iBAAiB,EAAE;AACjBwC,UAAAA,IAAI,EAAE;AADW,SAvBT;AA0BV1C,QAAAA,kBAAkB,EAAE;AAClB0C,UAAAA,IAAI,EAAE;AADY,SA1BV;AA6BV3C,QAAAA,cAAc,EAAE;AACd2C,UAAAA,IAAI,EAAE;AADQ,SA7BN;AAgCVzC,QAAAA,cAAc,EAAE;AACd8D,UAAAA,KAAK,EAAE;AACLrB,YAAAA,IAAI,EAAE;AADD,WADO;AAIdA,UAAAA,IAAI,EAAE;AAJQ;AAhCN,OAFd;AAyCEA,MAAAA,IAAI,EAAE;AAzCR,KADM,CANJ;AAmDJA,IAAAA,IAAI,EAAE;AAnDF;AAFL,CA9MY,C","sourcesContent":["import iterateJsdoc from '../iterateJsdoc';\n\nexport default iterateJsdoc(({\n context,\n jsdoc,\n utils,\n}) => {\n const {\n allowMultipleTags = true,\n noFinalLineText = true,\n noZeroLineText = true,\n noSingleLineBlocks = false,\n singleLineTags = ['lends', 'type'],\n noMultilineBlocks = false,\n minimumLengthForMultiline = Number.POSITIVE_INFINITY,\n multilineTags = ['*'],\n } = context.options[0] || {};\n\n const {source: [{tokens}]} = jsdoc;\n const {description, tag} = tokens;\n const sourceLength = jsdoc.source.length;\n\n const isInvalidSingleLine = (tagName) => {\n return noSingleLineBlocks &&\n (!tagName ||\n !singleLineTags.includes(tagName) && !singleLineTags.includes('*'));\n };\n\n if (sourceLength === 1) {\n if (!isInvalidSingleLine(tag.slice(1))) {\n return;\n }\n\n const fixer = () => {\n utils.makeMultiline();\n };\n\n utils.reportJSDoc(\n 'Single line blocks are not permitted by your configuration.',\n null, fixer, true,\n );\n\n return;\n }\n\n const lineChecks = () => {\n if (\n noZeroLineText &&\n (tag || description)\n ) {\n const fixer = () => {\n const line = {...tokens};\n utils.emptyTokens(tokens);\n const {tokens: {delimiter, start}} = jsdoc.source[1];\n utils.addLine(1, {...line, delimiter, start});\n };\n utils.reportJSDoc(\n 'Should have no text on the \"0th\" line (after the `/**`).',\n null, fixer,\n );\n\n return;\n }\n\n const finalLine = jsdoc.source[jsdoc.source.length - 1];\n const finalLineTokens = finalLine.tokens;\n if (\n noFinalLineText &&\n finalLineTokens.description.trim()\n ) {\n const fixer = () => {\n const line = {...finalLineTokens};\n line.description = line.description.trimEnd();\n\n const {delimiter} = line;\n\n [\n 'delimiter',\n 'postDelimiter',\n 'tag',\n 'type',\n 'lineEnd',\n 'postType',\n 'postTag',\n 'name',\n 'postName',\n 'description',\n ].forEach((prop) => {\n finalLineTokens[prop] = '';\n });\n\n utils.addLine(jsdoc.source.length - 1, {...line, delimiter, end: ''});\n };\n utils.reportJSDoc(\n 'Should have no text on the final line (before the `*/`).',\n null, fixer,\n );\n }\n };\n\n if (noMultilineBlocks) {\n if (\n jsdoc.tags.length &&\n (multilineTags.includes('*') || utils.hasATag(multilineTags))\n ) {\n lineChecks();\n\n return;\n }\n\n if (jsdoc.description.length >= minimumLengthForMultiline) {\n lineChecks();\n\n return;\n }\n\n if (\n noSingleLineBlocks &&\n (!jsdoc.tags.length ||\n !utils.filterTags(({tag: tg}) => {\n return !isInvalidSingleLine(tg);\n }).length)\n ) {\n utils.reportJSDoc(\n 'Multiline jsdoc blocks are prohibited by ' +\n 'your configuration but fixing would result in a single ' +\n 'line block which you have prohibited with `noSingleLineBlocks`.',\n );\n\n return;\n }\n\n if (jsdoc.tags.length > 1) {\n if (!allowMultipleTags) {\n utils.reportJSDoc(\n 'Multiline jsdoc blocks are prohibited by ' +\n 'your configuration but the block has multiple tags.',\n );\n\n return;\n }\n } else if (jsdoc.tags.length === 1 && jsdoc.description.trim()) {\n if (!allowMultipleTags) {\n utils.reportJSDoc(\n 'Multiline jsdoc blocks are prohibited by ' +\n 'your configuration but the block has a description with a tag.',\n );\n\n return;\n }\n } else {\n const fixer = () => {\n jsdoc.source = [{\n number: 1,\n source: '',\n tokens: jsdoc.source.reduce((obj, {\n tokens: {\n description: desc, tag: tg, type: typ, name: nme,\n lineEnd, postType, postName, postTag,\n },\n }) => {\n if (typ) {\n obj.type = typ;\n }\n if (tg && typ && nme) {\n obj.postType = postType;\n }\n if (nme) {\n obj.name += nme;\n }\n if (nme && desc) {\n obj.postName = postName;\n }\n obj.description += desc;\n\n const nameOrDescription = obj.description || obj.name;\n if (\n nameOrDescription && nameOrDescription.slice(-1) !== ' '\n ) {\n obj.description += ' ';\n }\n obj.lineEnd = lineEnd;\n\n // Already filtered for multiple tags\n obj.tag += tg;\n if (tg) {\n obj.postTag = postTag || ' ';\n }\n\n return obj;\n }, utils.seedTokens({\n delimiter: '/**',\n end: '*/',\n postDelimiter: ' ',\n })),\n }];\n };\n utils.reportJSDoc(\n 'Multiline jsdoc blocks are prohibited by ' +\n 'your configuration.',\n null, fixer,\n );\n\n return;\n }\n }\n\n lineChecks();\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Controls how and whether jsdoc blocks can be expressed as single or multiple line blocks.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-multiline-blocks',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperies: false,\n properties: {\n allowMultipleTags: {\n type: 'boolean',\n },\n minimumLengthForMultiline: {\n type: 'integer',\n },\n multilineTags: {\n anyOf: [\n {\n enum: ['*'],\n type: 'string',\n }, {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n ],\n },\n noFinalLineText: {\n type: 'boolean',\n },\n noMultilineBlocks: {\n type: 'boolean',\n },\n noSingleLineBlocks: {\n type: 'boolean',\n },\n noZeroLineText: {\n type: 'boolean',\n },\n singleLineTags: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"file":"multilineBlocks.js"}
|