mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
1 line
14 KiB
Plaintext
1 line
14 KiB
Plaintext
{"version":3,"sources":["../../src/rules/requireDescriptionCompleteSentence.js"],"names":["otherDescriptiveTags","extractParagraphs","text","reverse","join","split","map","par","extractSentences","abbreviationsRegex","txt","replace","sentenceEndGrouping","puncts","punct","sentence","idx","test","isNewLinePrecededByAPeriod","lastLineEndsSentence","lines","some","line","isCapitalized","str","toUpperCase","isTable","charAt","capitalize","slice","validateDescription","description","reportOrig","jsdocNode","sourceCode","tag","paragraphs","paragraph","parIdx","sentences","fix","fixer","getText","_","last","RegExp","escapeRegExp","filter","sentence_","beginning","reg","$0","$1","replaceText","report","msg","tagObj","column","paragraphNoAbbreviations","context","jsdoc","utils","options","abbreviations","length","abbreviation","tags","forEachPreferredTag","matchingJsdocTag","name","trim","getTagsByType","tagsWithNames","tagsWithoutNames","filterTags","tagName","includes","hasOptionTag","trimStart","iterateAllJsdocs","meta","fixable","schema","additionalProperties","properties","items","type"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AAEA,MAAMA,oBAAoB,GAAG,CAC3B;AACA;AACA;AACA,SAJ2B,EAIhB,MAJgB,EAIR,cAJQ,EAIQ,UAJR,EAIoB,WAJpB,EAIiC,MAJjC,EAK3B,YAL2B,EAKb,QALa,EAKH,WALG,EAKU,QALV,EAKoB,OALpB,CAA7B;;AAQA,MAAMC,iBAAiB,GAAIC,IAAD,IAAU;AAClC;AACA;AACA,SAAO,CAAC,GAAGA,IAAJ,EAAUC,OAAV,GAAoBC,IAApB,CAAyB,EAAzB,EAA6BC,KAA7B,CAAmC,eAAnC,EAAoDC,GAApD,CAAyDC,GAAD,IAAS;AACtE,WAAO,CAAC,GAAGA,GAAJ,EAASJ,OAAT,GAAmBC,IAAnB,CAAwB,EAAxB,CAAP;AACD,GAFM,EAEJD,OAFI,EAAP;AAGD,CAND;;AAQA,MAAMK,gBAAgB,GAAG,CAACN,IA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AACC,WAAD,EAAcuB,MAAd,EAAsBrB,SAAtB,EAAiCxB,kBAAjC,EAAqDyB,UAArD,EAAiEC,GAAjE,CAA1B;AACD,GAJD;AAMAsC,EAAAA,gBAAgB,CAACpD,IAAjB,CAAuBc,GAAD,IAAS;AAC7B,UAAMJ,WAAW,GAAI,GAAEI,GAAG,CAACkC,IAAK,IAAGlC,GAAG,CAACJ,WAAY,EAA/B,CAAiCuC,IAAjC,EAApB;AAEA,WAAOxC,mBAAmB,CAACC,WAAD,EAAcuB,MAAd,EAAsBrB,SAAtB,EAAiCxB,kBAAjC,EAAqDyB,UAArD,EAAiEC,GAAjE,CAA1B;AACD,GAJD;AAKD,CArDc,EAqDZ;AACD4C,EAAAA,gBAAgB,EAAE,IADjB;AAEDC,EAAAA,IAAI,EAAE;AACJC,IAAAA,OAAO,EAAE,MADL;AAEJC,IAAAA,MAAM,EAAE,CACN;AACEC,MAAAA,oBAAoB,EAAE,KADxB;AAEEC,MAAAA,UAAU,EAAE;AACVrB,QAAAA,aAAa,EAAE;AACbsB,UAAAA,KAAK,EAAE;AACLC,YAAAA,IAAI,EAAE;AADD,WADM;AAIbA,UAAAA,IAAI,EAAE;AAJO,SADL;AAOVpB,QAAAA,IAAI,EAAE;AACJmB,UAAAA,KAAK,EAAE;AACLC,YAAAA,IAAI,EAAE;AADD,WADH;AAIJA,UAAAA,IAAI,EAAE;AAJF;AAPI,OAFd;AAgBEA,MAAAA,IAAI,EAAE;AAhBR,KADM,CAFJ;AAsBJA,IAAAA,IAAI,EAAE;AAtBF;AAFL,CArDY,C","sourcesContent":["import _ from 'lodash';\nimport {RegExtras} from 'regextras/dist/main-umd';\nimport iterateJsdoc from '../iterateJsdoc';\n\nconst otherDescriptiveTags = [\n // 'copyright' and 'see' might be good addition, but as the former may be\n // sensitive text, and the latter may have just a link, they are not\n // included by default\n 'summary', 'file', 'fileoverview', 'overview', 'classdesc', 'todo',\n 'deprecated', 'throws', 'exception', 'yields', 'yield',\n];\n\nconst extractParagraphs = (text) => {\n // Todo [engine:node@>8.11.0]: Uncomment following line with neg. lookbehind instead\n // return text.split(/(?<![;:])\\n\\n/u);\n return [...text].reverse().join('').split(/\\n\\n(?![;:])/u).map((par) => {\n return [...par].reverse().join('');\n }).reverse();\n};\n\nconst extractSentences = (text, abbreviationsRegex) => {\n const txt = text\n\n // Remove all {} tags.\n .replace(/\\{[\\s\\S]*?\\}\\s*/gu, '')\n\n // Remove custom abbreviations\n .replace(abbreviationsRegex, '');\n\n const sentenceEndGrouping = /([.?!])(?:\\s+|$)/u;\n const puncts = RegExtras(sentenceEndGrouping).map(txt, (punct) => {\n return punct;\n });\n\n return txt\n\n .split(/[.?!](?:\\s+|$)/u)\n\n // Re-add the dot.\n .map((sentence, idx) => {\n return /^\\s*$/u.test(sentence) ? sentence : `${sentence}${puncts[idx] || ''}`;\n });\n};\n\nconst isNewLinePrecededByAPeriod = (text) => {\n let lastLineEndsSentence;\n\n const lines = text.split('\\n');\n\n return !lines.some((line) => {\n if (lastLineEndsSentence === false && /^[A-Z][a-z]/u.test(line)) {\n return true;\n }\n\n lastLineEndsSentence = /[.:?!|]$/u.test(line);\n\n return false;\n });\n};\n\nconst isCapitalized = (str) => {\n return str[0] === str[0].toUpperCase();\n};\n\nconst isTable = (str) => {\n return str.charAt() === '|';\n};\n\nconst capitalize = (str) => {\n return str.charAt(0).toUpperCase() + str.slice(1);\n};\n\nconst validateDescription = (description, reportOrig, jsdocNode, abbreviationsRegex, sourceCode, tag) => {\n if (!description) {\n return false;\n }\n\n const paragraphs = extractParagraphs(description);\n\n return paragraphs.some((paragraph, parIdx) => {\n const sentences = extractSentences(paragraph, abbreviationsRegex);\n\n const fix = (fixer) => {\n let text = sourceCode.getText(jsdocNode);\n\n if (!/[.:?!]$/u.test(paragraph)) {\n const line = _.last(paragraph.split('\\n'));\n\n text = text.replace(new RegExp(`${_.escapeRegExp(line)}$`, 'mu'), `${line}.`);\n }\n\n for (const sentence of sentences.filter((sentence_) => {\n return !(/^\\s*$/u).test(sentence_) && !isCapitalized(sentence_) &&\n !isTable(sentence_);\n })) {\n const beginning = sentence.split('\\n')[0];\n\n if (tag.tag) {\n const reg = new RegExp(`(@${_.escapeRegExp(tag.tag)}.*)${_.escapeRegExp(beginning)}`, 'u');\n\n text = text.replace(reg, ($0, $1) => {\n return $1 + capitalize(beginning);\n });\n } else {\n text = text.replace(beginning, capitalize(beginning));\n }\n }\n\n return fixer.replaceText(jsdocNode, text);\n };\n\n const report = (msg, fixer, tagObj) => {\n tagObj.line += parIdx * 2;\n\n // Avoid errors if old column doesn't exist here\n tagObj.column = 0;\n reportOrig(msg, fixer, tagObj);\n };\n\n if (sentences.some((sentence) => {\n return !(/^\\s*$/u).test(sentence) && !isCapitalized(sentence) && !isTable(sentence);\n })) {\n report('Sentence should start with an uppercase character.', fix, tag);\n }\n\n const paragraphNoAbbreviations = paragraph.replace(abbreviationsRegex, '');\n\n if (!/[.!?|]$/u.test(paragraphNoAbbreviations)) {\n report('Sentence must end with a period.', fix, tag);\n\n return true;\n }\n\n if (!isNewLinePrecededByAPeriod(paragraphNoAbbreviations)) {\n report('A line of text is started with an uppercase character, but preceding line does not end the sentence.', null, tag);\n\n return true;\n }\n\n return false;\n });\n};\n\nexport default iterateJsdoc(({\n sourceCode,\n context,\n jsdoc,\n report,\n jsdocNode,\n utils,\n}) => {\n const options = context.options[0] || {};\n const {\n abbreviations = [],\n } = options;\n\n const abbreviationsRegex = abbreviations.length ?\n new RegExp('\\\\b' + abbreviations.map((abbreviation) => {\n return _.escapeRegExp(abbreviation.replace(/\\.$/g, '') + '.');\n }).join('|') + '(?:$|\\\\s)', 'gu') :\n '';\n\n if (!jsdoc.tags ||\n validateDescription(jsdoc.description, report, jsdocNode, abbreviationsRegex, sourceCode, {\n line: jsdoc.line + 1,\n })\n ) {\n return;\n }\n\n utils.forEachPreferredTag('description', (matchingJsdocTag) => {\n const description = `${matchingJsdocTag.name} ${matchingJsdocTag.description}`.trim();\n validateDescription(description, report, jsdocNode, abbreviationsRegex, sourceCode, matchingJsdocTag);\n }, true);\n\n const {tagsWithNames} = utils.getTagsByType(jsdoc.tags);\n const tagsWithoutNames = utils.filterTags(({tag: tagName}) => {\n return otherDescriptiveTags.includes(tagName) ||\n utils.hasOptionTag(tagName) && !tagsWithNames.some(({tag}) => {\n // If user accidentally adds tags with names (or like `returns`\n // get parsed as having names), do not add to this list\n return tag === tagName;\n });\n });\n\n tagsWithNames.some((tag) => {\n const description = _.trimStart(tag.description, '- ');\n\n return validateDescription(description, report, jsdocNode, abbreviationsRegex, sourceCode, tag);\n });\n\n tagsWithoutNames.some((tag) => {\n const description = `${tag.name} ${tag.description}`.trim();\n\n return validateDescription(description, report, jsdocNode, abbreviationsRegex, sourceCode, tag);\n });\n}, {\n iterateAllJsdocs: true,\n meta: {\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n abbreviations: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n tags: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"file":"requireDescriptionCompleteSentence.js"} |