|
1 |
- {"version":3,"sources":["../../src/rules/checkLineAlignment.js"],"names":["flow","commentFlow","transforms","checkNotAlignedPerTag","utils","tag","customSpacings","spacerProps","contentProps","mightHaveNamepath","tagMightHaveNamepath","tokens","source","followedBySpace","idx","callbck","nextIndex","slice","some","spacerProp","innerIdx","contentProp","spacePropVal","ret","ok","contentPropVal","spacerPropVal","spacing","length","fix","forEach","padStart","hasSpace","contentPrp","setTag","reportJSDoc","checkAlignment","indent","jsdoc","jsdocNode","preserveMainDescriptionPostDelimiter","report","tags","transform","transformedJsdoc","comment","value","formatted","stringify","trimStart","fixer","replaceText","context","applicableTags","options","includes","foundTags","getPresentTags","iterateAllJsdocs","meta","docs","description","url","fixable","schema","enum","type","additionalProperties","properties","postDelimiter","postName","postTag","postType","default","items"],"mappings":";;;;;;;AAAA;;AAGA;;AACA;;;;AAEA,MAAM;AACJA,EAAAA,IAAI,EAAEC;AADF,IAEFC,yBAFJ;;AAIA,MAAMC,qBAAqB,GAAG,CAACC,KAAD,EAAQC,GAAR,EAAaC,cAAb,KAAgC;AAC5D;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACE,MAAIC,WAAJ;AACA,MAAIC,YAAJ;AACA,QAAMC,iBAAiB,GAAGL,KAAK,CAACM,oBAAN,CAA2BL,GAAG,CAACA,GAA/B,CAA1B;;AACA,MAAII,iBAAJ,EAAuB;AACrBF,IAAAA,WAAW,GAAG,CAAC,eAAD,EAAkB,SAAlB,EAA6B,UAA7B,EAAyC,UAAzC,CAAd;AACAC,IAAAA,YAAY,GAAG,CAAC,KAAD,EAAQ,MAAR,EAAgB,MAAhB,EAAwB,aAAxB,CAAf;AACD,GAHD,MAGO;AACLD,IAAAA,WAAW,GAAG,CAAC,eAAD,EAAkB,SAAlB,EAA6B,UAA7B,CAAd;AACAC,IAAAA,YAAY,GAAG,CAAC,KAAD,EAAQ,MAAR,EAAgB,aAAhB,CAAf;AACD;;AAED,QAAM;AAACG,I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AA,IAAI,EAAE;AA/BR,KALM,CANJ;AA6CJA,IAAAA,IAAI,EAAE;AA7CF;AAFL,CAtCY,C","sourcesContent":["import {\n transforms,\n} from 'comment-parser';\nimport alignTransform from '../alignTransform';\nimport iterateJsdoc from '../iterateJsdoc';\n\nconst {\n flow: commentFlow,\n} = transforms;\n\nconst checkNotAlignedPerTag = (utils, tag, customSpacings) => {\n /*\n start +\n delimiter +\n postDelimiter +\n tag +\n postTag +\n type +\n postType +\n name +\n postName +\n description +\n end +\n lineEnd\n */\n let spacerProps;\n let contentProps;\n const mightHaveNamepath = utils.tagMightHaveNamepath(tag.tag);\n if (mightHaveNamepath) {\n spacerProps = ['postDelimiter', 'postTag', 'postType', 'postName'];\n contentProps = ['tag', 'type', 'name', 'description'];\n } else {\n spacerProps = ['postDelimiter', 'postTag', 'postType'];\n contentProps = ['tag', 'type', 'description'];\n }\n\n const {tokens} = tag.source[0];\n\n const followedBySpace = (idx, callbck) => {\n const nextIndex = idx + 1;\n\n return spacerProps.slice(nextIndex).some((spacerProp, innerIdx) => {\n const contentProp = contentProps[nextIndex + innerIdx];\n\n const spacePropVal = tokens[spacerProp];\n\n const ret = spacePropVal;\n\n if (callbck) {\n callbck(!ret, contentProp);\n }\n\n return ret && (callbck || !contentProp);\n });\n };\n\n // If checking alignment on multiple lines, need to check other `source`\n // items\n // Go through `post*` spacing properties and exit to indicate problem if\n // extra spacing detected\n const ok = !spacerProps.some((spacerProp, idx) => {\n const contentProp = contentProps[idx];\n const contentPropVal = tokens[contentProp];\n const spacerPropVal = tokens[spacerProp];\n const spacing = customSpacings?.[spacerProp] || 1;\n\n // There will be extra alignment if...\n\n // 1. The spaces don't match the space it should have (1 or custom spacing) OR\n return spacerPropVal.length !== spacing && spacerPropVal.length !== 0 ||\n\n // 2. There is a (single) space, no immediate content, and yet another\n // space is found subsequently (not separated by intervening content)\n spacerPropVal && !contentPropVal && followedBySpace(idx);\n });\n if (ok) {\n return;\n }\n const fix = () => {\n spacerProps.forEach((spacerProp, idx) => {\n const contentProp = contentProps[idx];\n const contentPropVal = tokens[contentProp];\n\n if (contentPropVal) {\n const spacing = customSpacings?.[spacerProp] || 1;\n tokens[spacerProp] = ''.padStart(spacing, ' ');\n followedBySpace(idx, (hasSpace, contentPrp) => {\n if (hasSpace) {\n tokens[contentPrp] = '';\n }\n });\n } else {\n tokens[spacerProp] = '';\n }\n });\n\n utils.setTag(tag, tokens);\n };\n utils.reportJSDoc('Expected JSDoc block lines to not be aligned.', tag, fix, true);\n};\n\nconst checkAlignment = ({\n customSpacings,\n indent,\n jsdoc,\n jsdocNode,\n preserveMainDescriptionPostDelimiter,\n report,\n tags,\n utils,\n}) => {\n const transform = commentFlow(\n alignTransform({\n customSpacings,\n indent,\n preserveMainDescriptionPostDelimiter,\n tags,\n }),\n );\n const transformedJsdoc = transform(jsdoc);\n\n const comment = '/*' + jsdocNode.value + '*/';\n const formatted = utils.stringify(transformedJsdoc)\n .trimStart();\n\n if (comment !== formatted) {\n report(\n 'Expected JSDoc block lines to be aligned.',\n (fixer) => {\n return fixer.replaceText(jsdocNode, formatted);\n },\n );\n }\n};\n\nexport default iterateJsdoc(({\n indent,\n jsdoc,\n jsdocNode,\n report,\n context,\n utils,\n}) => {\n const {\n tags: applicableTags = ['param', 'arg', 'argument', 'property', 'prop', 'returns', 'return'],\n preserveMainDescriptionPostDelimiter,\n customSpacings,\n } = context.options[1] || {};\n\n if (context.options[0] === 'always') {\n // Skip if it contains only a single line.\n if (!jsdocNode.value.includes('\\n')) {\n return;\n }\n\n checkAlignment({\n customSpacings,\n indent,\n jsdoc,\n jsdocNode,\n preserveMainDescriptionPostDelimiter,\n report,\n tags: applicableTags,\n utils,\n });\n\n return;\n }\n\n const foundTags = utils.getPresentTags(applicableTags);\n foundTags.forEach((tag) => {\n checkNotAlignedPerTag(utils, tag, customSpacings);\n });\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Reports invalid alignment of JSDoc block lines.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-line-alignment',\n },\n fixable: 'whitespace',\n schema: [\n {\n enum: ['always', 'never'],\n type: 'string',\n },\n {\n additionalProperties: false,\n properties: {\n customSpacings: {\n additionalProperties: false,\n properties: {\n postDelimiter: {\n type: 'integer',\n },\n postName: {\n type: 'integer',\n },\n postTag: {\n type: 'integer',\n },\n postType: {\n type: 'integer',\n },\n },\n },\n preserveMainDescriptionPostDelimiter: {\n default: false,\n type: 'boolean',\n },\n tags: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n ],\n type: 'layout',\n },\n});\n"],"file":"checkLineAlignment.js"}
|