eslint-plugin-jsdoc 44.2.3 → 44.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alignTransform.js +86 -4
- package/dist/alignTransform.js.map +1 -1
- package/dist/exportParser.js +134 -4
- package/dist/exportParser.js.map +1 -1
- package/dist/iterateJsdoc.js +936 -345
- package/dist/iterateJsdoc.js.map +1 -1
- package/dist/jsdocUtils.js +173 -105
- package/dist/jsdocUtils.js.map +1 -1
- package/dist/rules/checkAlignment.js +6 -0
- package/dist/rules/checkAlignment.js.map +1 -1
- package/dist/rules/checkExamples.js +70 -6
- package/dist/rules/checkExamples.js.map +1 -1
- package/dist/rules/checkIndentation.js +11 -1
- package/dist/rules/checkIndentation.js.map +1 -1
- package/dist/rules/checkLineAlignment.js +68 -4
- package/dist/rules/checkLineAlignment.js.map +1 -1
- package/dist/rules/checkParamNames.js +12 -7
- package/dist/rules/checkParamNames.js.map +1 -1
- package/dist/rules/checkPropertyNames.js +13 -7
- package/dist/rules/checkPropertyNames.js.map +1 -1
- package/dist/rules/checkTagNames.js +45 -5
- package/dist/rules/checkTagNames.js.map +1 -1
- package/dist/rules/checkTypes.js +97 -36
- package/dist/rules/checkTypes.js.map +1 -1
- package/dist/rules/checkValues.js +6 -6
- package/dist/rules/checkValues.js.map +1 -1
- package/dist/rules/emptyTags.js +8 -1
- package/dist/rules/emptyTags.js.map +1 -1
- package/dist/rules/informativeDocs.js +26 -7
- package/dist/rules/informativeDocs.js.map +1 -1
- package/dist/rules/matchDescription.js +18 -1
- package/dist/rules/matchDescription.js.map +1 -1
- package/dist/rules/matchName.js +2 -2
- package/dist/rules/matchName.js.map +1 -1
- package/dist/rules/multilineBlocks.js +12 -1
- package/dist/rules/multilineBlocks.js.map +1 -1
- package/dist/rules/noBadBlocks.js +3 -5
- package/dist/rules/noBadBlocks.js.map +1 -1
- package/dist/rules/noBlankBlockDescriptions.js +2 -0
- package/dist/rules/noBlankBlockDescriptions.js.map +1 -1
- package/dist/rules/noMissingSyntax.js +58 -15
- package/dist/rules/noMissingSyntax.js.map +1 -1
- package/dist/rules/noMultiAsterisks.js +1 -6
- package/dist/rules/noMultiAsterisks.js.map +1 -1
- package/dist/rules/noRestrictedSyntax.js +17 -4
- package/dist/rules/noRestrictedSyntax.js.map +1 -1
- package/dist/rules/noTypes.js +3 -0
- package/dist/rules/noTypes.js.map +1 -1
- package/dist/rules/noUndefinedTypes.js +61 -20
- package/dist/rules/noUndefinedTypes.js.map +1 -1
- package/dist/rules/requireAsteriskPrefix.js +20 -0
- package/dist/rules/requireAsteriskPrefix.js.map +1 -1
- package/dist/rules/requireDescription.js +6 -2
- package/dist/rules/requireDescription.js.map +1 -1
- package/dist/rules/requireDescriptionCompleteSentence.js +72 -9
- package/dist/rules/requireDescriptionCompleteSentence.js.map +1 -1
- package/dist/rules/requireFileOverview.js +9 -4
- package/dist/rules/requireFileOverview.js.map +1 -1
- package/dist/rules/requireHyphenBeforeParamDescription.js +23 -6
- package/dist/rules/requireHyphenBeforeParamDescription.js.map +1 -1
- package/dist/rules/requireJsdoc.js +144 -28
- package/dist/rules/requireJsdoc.js.map +1 -1
- package/dist/rules/requireParam.js +46 -2
- package/dist/rules/requireParam.js.map +1 -1
- package/dist/rules/requireProperty.js +1 -1
- package/dist/rules/requireProperty.js.map +1 -1
- package/dist/rules/requireReturns.js +2 -2
- package/dist/rules/requireReturns.js.map +1 -1
- package/dist/rules/requireReturnsCheck.js +9 -2
- package/dist/rules/requireReturnsCheck.js.map +1 -1
- package/dist/rules/requireThrows.js +2 -2
- package/dist/rules/requireThrows.js.map +1 -1
- package/dist/rules/requireYields.js +9 -2
- package/dist/rules/requireYields.js.map +1 -1
- package/dist/rules/requireYieldsCheck.js +19 -5
- package/dist/rules/requireYieldsCheck.js.map +1 -1
- package/dist/rules/sortTags.js +67 -9
- package/dist/rules/sortTags.js.map +1 -1
- package/dist/rules/tagLines.js +22 -3
- package/dist/rules/tagLines.js.map +1 -1
- package/dist/rules/textEscaping.js +16 -2
- package/dist/rules/textEscaping.js.map +1 -1
- package/dist/rules/validTypes.js +25 -8
- package/dist/rules/validTypes.js.map +1 -1
- package/dist/utils/hasReturnValue.js +77 -43
- package/dist/utils/hasReturnValue.js.map +1 -1
- package/docs/rules/check-tag-names.md +15 -0
- package/docs/rules/no-missing-syntax.md +6 -0
- package/docs/rules/require-description-complete-sentence.md +525 -289
- package/docs/rules/require-description.md +289 -525
- package/docs/rules/require-file-overview.md +7 -0
- package/docs/rules/require-jsdoc.md +1 -1
- package/docs/rules/require-param-description.md +116 -1694
- package/docs/rules/require-param-name.md +58 -133
- package/docs/rules/require-param-type.md +119 -55
- package/docs/rules/require-param.md +1700 -111
- package/docs/rules/require-property-description.md +39 -79
- package/docs/rules/require-property-name.md +21 -30
- package/docs/rules/require-property-type.md +21 -21
- package/docs/rules/require-property.md +82 -33
- package/docs/rules/require-returns-check.md +636 -747
- package/docs/rules/require-returns-description.md +61 -933
- package/docs/rules/require-returns-type.md +42 -79
- package/docs/rules/require-returns.md +1081 -61
- package/docs/rules/require-yields-check.md +238 -517
- package/docs/rules/require-yields.md +517 -238
- package/docs/rules/valid-types.md +1 -1
- package/docs/settings.md +1 -1
- package/package.json +5 -4
- package/tsconfig.json +2 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requireDescriptionCompleteSentence.js","names":["_escapeStringRegexp","_interopRequireDefault","require","_iterateJsdoc","obj","__esModule","default","otherDescriptiveTags","Set","extractParagraphs","text","split","extractSentences","abbreviationsRegex","txt","replace","sentenceEndGrouping","puncts","matchAll","map","sentEnd","sentence","idx","test","isNewLinePrecededByAPeriod","lastLineEndsSentence","lines","some","line","isCapitalized","str","toUpperCase","isTable","charAt","capitalize","slice","validateDescription","description","reportOrig","jsdocNode","sourceCode","tag","newlineBeforeCapsAssumesBadSentenceEnd","paragraphs","filter","Boolean","paragraph","parIdx","sentences","fix","fixer","getText","pop","RegExp","escapeStringRegexp","sentence_","beginning","reg","_$0","$1","replaceText","report","msg","tagObj","source","number","column","paragraphNoAbbreviations","_default","iterateJsdoc","context","jsdoc","utils","options","abbreviations","length","abbreviation","join","getDescription","indices","match","index","reverse","forEachPreferredTag","matchingJsdocTag","desc","name","getTagDescription","trim","tagsWithNames","getTagsByType","tags","tagsWithoutNames","filterTags","tagName","has","hasOptionTag","trimEnd","iterateAllJsdocs","meta","docs","url","fixable","schema","additionalProperties","properties","items","type","exports","module"],"sources":["../../src/rules/requireDescriptionCompleteSentence.js"],"sourcesContent":["import escapeStringRegexp from 'escape-string-regexp';\nimport iterateJsdoc from '../iterateJsdoc';\n\nconst otherDescriptiveTags = new Set([\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 return text.split(/(?<![;:])\\n\\n/u);\n};\n\nconst extractSentences = (text, abbreviationsRegex) => {\n const txt = text\n // Remove all {} tags.\n .replace(/\\{[\\s\\S]*?\\}\\s*/gu, '')\n\n // Remove custom abbreviations\n .replace(abbreviationsRegex, '');\n\n const sentenceEndGrouping = /([.?!])(?:\\s+|$)/ug;\n\n const puncts = [\n ...txt.matchAll(sentenceEndGrouping),\n ].map((sentEnd) => {\n return sentEnd[0];\n });\n\n return txt\n .split(/[.?!](?:\\s+|$)/u)\n\n // Re-add the dot.\n .map((sentence, idx) => {\n return !puncts[idx] && /^\\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 = (\n description, reportOrig, jsdocNode, abbreviationsRegex,\n sourceCode, tag, newlineBeforeCapsAssumesBadSentenceEnd,\n) => {\n if (!description || (/^\\n+$/u).test(description)) {\n return false;\n }\n\n const paragraphs = extractParagraphs(description).filter(Boolean);\n\n return paragraphs.some((paragraph, parIdx) => {\n const sentences = extractSentences(paragraph, abbreviationsRegex);\n\n const fix = /** @type {import('eslint').Rule.ReportFixer} */ (fixer) => {\n let text = sourceCode.getText(jsdocNode);\n\n if (!/[.:?!]$/u.test(paragraph)) {\n const line = paragraph.split('\\n').filter(Boolean).pop();\n\n text = text.replace(new RegExp(`${escapeStringRegexp(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(`(@${escapeStringRegexp(tag.tag)}.*)${escapeStringRegexp(beginning)}`, 'u');\n\n text = text.replace(reg, (_$0, $1) => {\n return $1 + capitalize(beginning);\n });\n } else {\n text = text.replace(new RegExp('((?:[.?!]|\\\\*|\\\\})\\\\s*)' + escapeStringRegexp(beginning), 'u'), '$1' + capitalize(beginning));\n }\n }\n\n return fixer.replaceText(jsdocNode, text);\n };\n\n const report = (msg, fixer, tagObj) => {\n if ('line' in tagObj) {\n tagObj.line += parIdx * 2;\n } else {\n tagObj.source[0].number += parIdx * 2;\n }\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 (/^[.?!]$/u).test(sentence);\n })) {\n report('Sentences must be more than punctuation.', null, tag);\n }\n\n if (sentences.some((sentence) => {\n return !(/^\\s*$/u).test(sentence) && !isCapitalized(sentence) && !isTable(sentence);\n })) {\n report('Sentences should start with an uppercase character.', fix, tag);\n }\n\n const paragraphNoAbbreviations = paragraph.replace(abbreviationsRegex, '');\n\n if (!/(?:[.?!|]|```)\\s*$/u.test(paragraphNoAbbreviations)) {\n report('Sentences must end with a period.', fix, tag);\n\n return true;\n }\n\n if (newlineBeforeCapsAssumesBadSentenceEnd && !isNewLinePrecededByAPeriod(paragraphNoAbbreviations)) {\n report('A line of text is started with an uppercase character, but the 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 newlineBeforeCapsAssumesBadSentenceEnd = false,\n } = options;\n\n const abbreviationsRegex = abbreviations.length ?\n new RegExp('\\\\b' + abbreviations.map((abbreviation) => {\n return escapeStringRegexp(abbreviation.replace(/\\.$/ug, '') + '.');\n }).join('|') + '(?:$|\\\\s)', 'gu') :\n '';\n\n let {\n description,\n } = utils.getDescription();\n\n const indices = [\n ...description.matchAll(/```[\\s\\S]*```/gu),\n ].map((match) => {\n const {\n index,\n } = match;\n const [\n {\n length,\n },\n ] = match;\n return {\n index,\n length,\n };\n }).reverse();\n\n for (const {\n index,\n length,\n } of indices) {\n description = description.slice(0, index) + description.slice(index + length);\n }\n\n if (validateDescription(description, report, jsdocNode, abbreviationsRegex, sourceCode, {\n line: jsdoc.source[0].number + 1,\n }, newlineBeforeCapsAssumesBadSentenceEnd)) {\n return;\n }\n\n utils.forEachPreferredTag('description', (matchingJsdocTag) => {\n const desc = `${matchingJsdocTag.name} ${utils.getTagDescription(matchingJsdocTag)}`.trim();\n validateDescription(desc, report, jsdocNode, abbreviationsRegex, sourceCode, matchingJsdocTag, newlineBeforeCapsAssumesBadSentenceEnd);\n }, true);\n\n const {\n tagsWithNames,\n } = utils.getTagsByType(jsdoc.tags);\n const tagsWithoutNames = utils.filterTags(({\n tag: tagName,\n }) => {\n return otherDescriptiveTags.has(tagName) ||\n utils.hasOptionTag(tagName) && !tagsWithNames.some(({\n tag,\n }) => {\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 desc = utils.getTagDescription(tag).replace(/^- /u, '').trimEnd();\n\n return validateDescription(desc, report, jsdocNode, abbreviationsRegex, sourceCode, tag, newlineBeforeCapsAssumesBadSentenceEnd);\n });\n\n tagsWithoutNames.some((tag) => {\n const desc = `${tag.name} ${utils.getTagDescription(tag)}`.trim();\n\n return validateDescription(desc, report, jsdocNode, abbreviationsRegex, sourceCode, tag, newlineBeforeCapsAssumesBadSentenceEnd);\n });\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Requires that block description, explicit `@description`, and `@param`/`@returns` tag descriptions are written in complete sentences.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-description-complete-sentence',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n abbreviations: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n newlineBeforeCapsAssumesBadSentenceEnd: {\n type: 'boolean',\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"],"mappings":";;;;;;AAAA,IAAAA,mBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAF,sBAAA,CAAAC,OAAA;AAA2C,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE3C,MAAMG,oBAAoB,GAAG,IAAIC,GAAG,CAAC;AACnC;AACA;AACA;AACA,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAClE,YAAY,EAAE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AAE2B,UAAU,EAAEC,GAAG,EAAEC,sCAAsC,CAAC;EAClI,CAAC,CAAC;EAEFkD,gBAAgB,CAACjE,IAAI,CAAEc,GAAG,IAAK;IAC7B,MAAM4C,IAAI,GAAI,GAAE5C,GAAG,CAAC6C,IAAK,IAAGd,KAAK,CAACe,iBAAiB,CAAC9C,GAAG,CAAE,EAAC,CAAC+C,IAAI,CAAC,CAAC;IAEjE,OAAOpD,mBAAmB,CAACiD,IAAI,EAAExB,MAAM,EAAEtB,SAAS,EAAE1B,kBAAkB,EAAE2B,UAAU,EAAEC,GAAG,EAAEC,sCAAsC,CAAC;EAClI,CAAC,CAAC;AACJ,CAAC,EAAE;EACDwD,gBAAgB,EAAE,IAAI;EACtBC,IAAI,EAAE;IACJC,IAAI,EAAE;MACJ/D,WAAW,EAAE,uIAAuI;MACpJgE,GAAG,EAAE;IACP,CAAC;IACDC,OAAO,EAAE,MAAM;IACfC,MAAM,EAAE,CACN;MACEC,oBAAoB,EAAE,KAAK;MAC3BC,UAAU,EAAE;QACV/B,aAAa,EAAE;UACbgC,KAAK,EAAE;YACLC,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR,CAAC;QACDjE,sCAAsC,EAAE;UACtCiE,IAAI,EAAE;QACR,CAAC;QACDhB,IAAI,EAAE;UACJe,KAAK,EAAE;YACLC,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAAC,OAAA,CAAAtG,OAAA,GAAA8D,QAAA;AAAAyC,MAAA,CAAAD,OAAA,GAAAA,OAAA,CAAAtG,OAAA"}
|
|
1
|
+
{"version":3,"file":"requireDescriptionCompleteSentence.js","names":["_escapeStringRegexp","_interopRequireDefault","require","_iterateJsdoc","obj","__esModule","default","otherDescriptiveTags","Set","extractParagraphs","text","split","extractSentences","abbreviationsRegex","txt","replace","sentenceEndGrouping","puncts","matchAll","map","sentEnd","sentence","idx","test","isNewLinePrecededByAPeriod","lastLineEndsSentence","lines","some","line","isCapitalized","str","toUpperCase","isTable","charAt","capitalize","slice","validateDescription","description","reportOrig","jsdocNode","sourceCode","tag","newlineBeforeCapsAssumesBadSentenceEnd","paragraphs","filter","Boolean","paragraph","parIdx","sentences","fix","fixer","getText","pop","RegExp","escapeStringRegexp","sentence_","beginning","reg","_$0","$1","replaceText","report","msg","tagObj","source","number","column","paragraphNoAbbreviations","_default","iterateJsdoc","context","jsdoc","utils","abbreviations","options","length","abbreviation","join","getDescription","indices","match","index","reverse","forEachPreferredTag","matchingJsdocTag","desc","name","getTagDescription","trim","tagsWithNames","getTagsByType","tags","tagsWithoutNames","filterTags","tagName","has","hasOptionTag","trimEnd","iterateAllJsdocs","meta","docs","url","fixable","schema","additionalProperties","properties","items","type","exports","module"],"sources":["../../src/rules/requireDescriptionCompleteSentence.js"],"sourcesContent":["import escapeStringRegexp from 'escape-string-regexp';\nimport iterateJsdoc from '../iterateJsdoc';\n\nconst otherDescriptiveTags = new Set([\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\n/**\n * @param {string} text\n * @returns {string[]}\n */\nconst extractParagraphs = (text) => {\n return text.split(/(?<![;:])\\n\\n/u);\n};\n\n/**\n * @param {string} text\n * @param {string|RegExp} abbreviationsRegex\n * @returns {string[]}\n */\nconst extractSentences = (text, abbreviationsRegex) => {\n const txt = text\n // Remove all {} tags.\n .replace(/\\{[\\s\\S]*?\\}\\s*/gu, '')\n\n // Remove custom abbreviations\n .replace(abbreviationsRegex, '');\n\n const sentenceEndGrouping = /([.?!])(?:\\s+|$)/ug;\n\n const puncts = [\n ...txt.matchAll(sentenceEndGrouping),\n ].map((sentEnd) => {\n return sentEnd[0];\n });\n\n return txt\n .split(/[.?!](?:\\s+|$)/u)\n\n // Re-add the dot.\n .map((sentence, idx) => {\n return !puncts[idx] && /^\\s*$/u.test(sentence) ? sentence : `${sentence}${puncts[idx] || ''}`;\n });\n};\n\n/**\n * @param {string} text\n * @returns {boolean}\n */\nconst isNewLinePrecededByAPeriod = (text) => {\n /** @type {boolean} */\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\n/**\n * @param {string} str\n * @returns {boolean}\n */\nconst isCapitalized = (str) => {\n return str[0] === str[0].toUpperCase();\n};\n\n/**\n * @param {string} str\n * @returns {boolean}\n */\nconst isTable = (str) => {\n return str.charAt(0) === '|';\n};\n\n/**\n * @param {string} str\n * @returns {string}\n */\nconst capitalize = (str) => {\n return str.charAt(0).toUpperCase() + str.slice(1);\n};\n\n/**\n * @param {string} description\n * @param {import('../iterateJsdoc.js').Report} reportOrig\n * @param {import('eslint').Rule.Node} jsdocNode\n * @param {string|RegExp} abbreviationsRegex\n * @param {import('eslint').SourceCode} sourceCode\n * @param {import('comment-parser').Spec|{\n * line: import('../iterateJsdoc.js').Integer\n * }} tag\n * @param {boolean} newlineBeforeCapsAssumesBadSentenceEnd\n * @returns {boolean}\n */\nconst validateDescription = (\n description, reportOrig, jsdocNode, abbreviationsRegex,\n sourceCode, tag, newlineBeforeCapsAssumesBadSentenceEnd,\n) => {\n if (!description || (/^\\n+$/u).test(description)) {\n return false;\n }\n\n const paragraphs = extractParagraphs(description).filter(Boolean);\n\n return paragraphs.some((paragraph, parIdx) => {\n const sentences = extractSentences(paragraph, abbreviationsRegex);\n\n const fix = /** @type {import('eslint').Rule.ReportFixer} */ (fixer) => {\n let text = sourceCode.getText(jsdocNode);\n\n if (!/[.:?!]$/u.test(paragraph)) {\n const line = paragraph.split('\\n').filter(Boolean).pop();\n text = text.replace(new RegExp(`${escapeStringRegexp(\n /** @type {string} */\n (line),\n )}$`, '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' in tag && tag.tag) {\n const reg = new RegExp(`(@${escapeStringRegexp(tag.tag)}.*)${escapeStringRegexp(beginning)}`, 'u');\n\n text = text.replace(reg, (_$0, $1) => {\n return $1 + capitalize(beginning);\n });\n } else {\n text = text.replace(new RegExp('((?:[.?!]|\\\\*|\\\\})\\\\s*)' + escapeStringRegexp(beginning), 'u'), '$1' + capitalize(beginning));\n }\n }\n\n return fixer.replaceText(jsdocNode, text);\n };\n\n /**\n * @param {string} msg\n * @param {import('eslint').Rule.ReportFixer | null | undefined} fixer\n * @param {{\n * line?: number | undefined;\n * column?: number | undefined;\n * } | (import('comment-parser').Spec & {\n * line?: number | undefined;\n * column?: number | undefined;\n * })} tagObj\n * @returns {void}\n */\n const report = (msg, fixer, tagObj) => {\n if ('line' in tagObj) {\n /**\n * @type {{\n * line: number;\n * }}\n */ (tagObj).line += parIdx * 2;\n } else {\n /** @type {import('comment-parser').Spec} */ (\n tagObj\n ).source[0].number += parIdx * 2;\n }\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 (/^[.?!]$/u).test(sentence);\n })) {\n report('Sentences must be more than punctuation.', null, tag);\n }\n\n if (sentences.some((sentence) => {\n return !(/^\\s*$/u).test(sentence) && !isCapitalized(sentence) && !isTable(sentence);\n })) {\n report('Sentences should start with an uppercase character.', fix, tag);\n }\n\n const paragraphNoAbbreviations = paragraph.replace(abbreviationsRegex, '');\n\n if (!/(?:[.?!|]|```)\\s*$/u.test(paragraphNoAbbreviations)) {\n report('Sentences must end with a period.', fix, tag);\n return true;\n }\n\n if (newlineBeforeCapsAssumesBadSentenceEnd && !isNewLinePrecededByAPeriod(paragraphNoAbbreviations)) {\n report('A line of text is started with an uppercase character, but the 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 /** @type {{abbreviations: string[], newlineBeforeCapsAssumesBadSentenceEnd: boolean}} */ {\n abbreviations = [],\n newlineBeforeCapsAssumesBadSentenceEnd = false,\n } = context.options[0] || {};\n\n const abbreviationsRegex = abbreviations.length ?\n new RegExp('\\\\b' + abbreviations.map((abbreviation) => {\n return escapeStringRegexp(abbreviation.replace(/\\.$/ug, '') + '.');\n }).join('|') + '(?:$|\\\\s)', 'gu') :\n '';\n\n let {\n description,\n } = utils.getDescription();\n\n const indices = [\n ...description.matchAll(/```[\\s\\S]*```/gu),\n ].map((match) => {\n const {\n index,\n } = match;\n const [\n {\n length,\n },\n ] = match;\n return {\n index,\n length,\n };\n }).reverse();\n\n for (const {\n index,\n length,\n } of indices) {\n description = description.slice(0, index) +\n description.slice(/** @type {import('../iterateJsdoc.js').Integer} */ (\n index\n ) + length);\n }\n\n if (validateDescription(description, report, jsdocNode, abbreviationsRegex, sourceCode, {\n line: jsdoc.source[0].number + 1,\n }, newlineBeforeCapsAssumesBadSentenceEnd)) {\n return;\n }\n\n utils.forEachPreferredTag('description', (matchingJsdocTag) => {\n const desc = `${matchingJsdocTag.name} ${utils.getTagDescription(matchingJsdocTag)}`.trim();\n validateDescription(desc, report, jsdocNode, abbreviationsRegex, sourceCode, matchingJsdocTag, newlineBeforeCapsAssumesBadSentenceEnd);\n }, true);\n\n const {\n tagsWithNames,\n } = utils.getTagsByType(jsdoc.tags);\n const tagsWithoutNames = utils.filterTags(({\n tag: tagName,\n }) => {\n return otherDescriptiveTags.has(tagName) ||\n utils.hasOptionTag(tagName) && !tagsWithNames.some(({\n tag,\n }) => {\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 desc = /** @type {string} */ (\n utils.getTagDescription(tag)\n ).replace(/^- /u, '').trimEnd();\n\n return validateDescription(desc, report, jsdocNode, abbreviationsRegex, sourceCode, tag, newlineBeforeCapsAssumesBadSentenceEnd);\n });\n\n tagsWithoutNames.some((tag) => {\n const desc = `${tag.name} ${utils.getTagDescription(tag)}`.trim();\n\n return validateDescription(desc, report, jsdocNode, abbreviationsRegex, sourceCode, tag, newlineBeforeCapsAssumesBadSentenceEnd);\n });\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Requires that block description, explicit `@description`, and `@param`/`@returns` tag descriptions are written in complete sentences.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-description-complete-sentence',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n abbreviations: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n newlineBeforeCapsAssumesBadSentenceEnd: {\n type: 'boolean',\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"],"mappings":";;;;;;AAAA,IAAAA,mBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAF,sBAAA,CAAAC,OAAA;AAA2C,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE3C,MAAMG,oBAAoB,GAAG,IAAIC,GAAG,CAAC;AACnC;AACA;AACA;AACA,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAClE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,CACvD,CAAC;;AAEF;AACA;AACA;AACA;AACA,MAAMC,iBAAiB,GAAIC,IAAI,IAAK;EAClC,OAAOA,IAAI,CAAC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
|
@@ -13,6 +13,11 @@ const defaultTags = {
|
|
|
13
13
|
preventDuplicates: true
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {import('../iterateJsdoc.js').StateObject} state
|
|
19
|
+
* @returns {void}
|
|
20
|
+
*/
|
|
16
21
|
const setDefaults = state => {
|
|
17
22
|
// First iteration
|
|
18
23
|
if (!state.globalTags) {
|
|
@@ -33,10 +38,10 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
33
38
|
} = context.options[0] || {};
|
|
34
39
|
setDefaults(state);
|
|
35
40
|
for (const tagName of Object.keys(tags)) {
|
|
36
|
-
const targetTagName = utils.getPreferredTagName({
|
|
41
|
+
const targetTagName = /** @type {string} */utils.getPreferredTagName({
|
|
37
42
|
tagName
|
|
38
43
|
});
|
|
39
|
-
const hasTag = targetTagName && utils.hasTag(targetTagName);
|
|
44
|
+
const hasTag = Boolean(targetTagName && utils.hasTag(targetTagName));
|
|
40
45
|
state.hasTag[tagName] = hasTag || state.hasTag[tagName];
|
|
41
46
|
const hasDuplicate = state.hasDuplicates[tagName];
|
|
42
47
|
if (hasDuplicate === false) {
|
|
@@ -67,10 +72,10 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
67
72
|
const obj = utils.getPreferredTagNameObject({
|
|
68
73
|
tagName
|
|
69
74
|
});
|
|
70
|
-
if (obj && obj
|
|
75
|
+
if (obj && typeof obj === 'object' && 'blocked' in obj) {
|
|
71
76
|
utils.reportSettings(`\`settings.jsdoc.tagNamePreference\` cannot block @${obj.tagName} ` + 'for the `require-file-overview` rule');
|
|
72
77
|
} else {
|
|
73
|
-
const targetTagName = obj && obj.replacement || obj;
|
|
78
|
+
const targetTagName = obj && typeof obj === 'object' && obj.replacement || obj;
|
|
74
79
|
if (mustExist && !state.hasTag[tagName]) {
|
|
75
80
|
utils.reportSettings(`Missing @${targetTagName}`);
|
|
76
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requireFileOverview.js","names":["_iterateJsdoc","_interopRequireDefault","require","obj","__esModule","default","defaultTags","file","initialCommentsOnly","mustExist","preventDuplicates","setDefaults","state","globalTags","hasDuplicates","hasTag","hasNonCommentBeforeTag","_default","iterateJsdoc","jsdocNode","utils","context","tags","options","tagName","Object","keys","targetTagName","getPreferredTagName","hasDuplicate","hasNonComment","range","exit","entries","getPreferredTagNameObject","
|
|
1
|
+
{"version":3,"file":"requireFileOverview.js","names":["_iterateJsdoc","_interopRequireDefault","require","obj","__esModule","default","defaultTags","file","initialCommentsOnly","mustExist","preventDuplicates","setDefaults","state","globalTags","hasDuplicates","hasTag","hasNonCommentBeforeTag","_default","iterateJsdoc","jsdocNode","utils","context","tags","options","tagName","Object","keys","targetTagName","getPreferredTagName","Boolean","hasDuplicate","hasNonComment","range","exit","entries","getPreferredTagNameObject","reportSettings","replacement","iterateAllJsdocs","meta","docs","description","url","schema","additionalProperties","properties","patternProperties","type","nonComment","node","exports","module"],"sources":["../../src/rules/requireFileOverview.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc';\n\nconst defaultTags = {\n file: {\n initialCommentsOnly: true,\n mustExist: true,\n preventDuplicates: true,\n },\n};\n\n/**\n * @param {import('../iterateJsdoc.js').StateObject} state\n * @returns {void}\n */\nconst setDefaults = (state) => {\n // First iteration\n if (!state.globalTags) {\n state.globalTags = {};\n state.hasDuplicates = {};\n state.hasTag = {};\n state.hasNonCommentBeforeTag = {};\n }\n};\n\nexport default iterateJsdoc(({\n jsdocNode,\n state,\n utils,\n context,\n}) => {\n const {\n tags = defaultTags,\n } = context.options[0] || {};\n\n setDefaults(state);\n\n for (const tagName of Object.keys(tags)) {\n const targetTagName = /** @type {string} */ (utils.getPreferredTagName({\n tagName,\n }));\n\n const hasTag = Boolean(targetTagName && utils.hasTag(targetTagName));\n\n state.hasTag[tagName] = hasTag || state.hasTag[tagName];\n\n const hasDuplicate = state.hasDuplicates[tagName];\n\n if (hasDuplicate === false) {\n // Was marked before, so if a tag now, is a dupe\n state.hasDuplicates[tagName] = hasTag;\n } else if (!hasDuplicate && hasTag) {\n // No dupes set before, but has first tag, so change state\n // from `undefined` to `false` so can detect next time\n state.hasDuplicates[tagName] = false;\n state.hasNonCommentBeforeTag[tagName] = state.hasNonComment &&\n state.hasNonComment < jsdocNode.range[0];\n }\n }\n}, {\n exit ({\n context,\n state,\n utils,\n }) {\n setDefaults(state);\n const {\n tags = defaultTags,\n } = context.options[0] || {};\n\n for (const [\n tagName,\n {\n mustExist = false,\n preventDuplicates = false,\n initialCommentsOnly = false,\n },\n ] of Object.entries(tags)) {\n const obj = utils.getPreferredTagNameObject({\n tagName,\n });\n if (obj && typeof obj === 'object' && 'blocked' in obj) {\n utils.reportSettings(\n `\\`settings.jsdoc.tagNamePreference\\` cannot block @${obj.tagName} ` +\n 'for the `require-file-overview` rule',\n );\n } else {\n const targetTagName = (\n obj && typeof obj === 'object' && obj.replacement\n ) || obj;\n if (mustExist && !state.hasTag[tagName]) {\n utils.reportSettings(`Missing @${targetTagName}`);\n }\n\n if (preventDuplicates && state.hasDuplicates[tagName]) {\n utils.reportSettings(\n `Duplicate @${targetTagName}`,\n );\n }\n\n if (initialCommentsOnly &&\n state.hasNonCommentBeforeTag[tagName]\n ) {\n utils.reportSettings(\n `@${targetTagName} should be at the beginning of the file`,\n );\n }\n }\n }\n },\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Checks that all files have one `@file`, `@fileoverview`, or `@overview` tag at the beginning of the file.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-file-overview',\n },\n schema: [\n {\n additionalProperties: false,\n properties: {\n tags: {\n patternProperties: {\n '.*': {\n additionalProperties: false,\n properties: {\n initialCommentsOnly: {\n type: 'boolean',\n },\n mustExist: {\n type: 'boolean',\n },\n preventDuplicates: {\n type: 'boolean',\n },\n },\n type: 'object',\n },\n },\n type: 'object',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n nonComment ({\n state,\n node,\n }) {\n if (!state.hasNonComment) {\n state.hasNonComment = node.range[0];\n }\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA2C,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE3C,MAAMG,WAAW,GAAG;EAClBC,IAAI,EAAE;IACJC,mBAAmB,EAAE,IAAI;IACzBC,SAAS,EAAE,IAAI;IACfC,iBAAiB,EAAE;EACrB;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAIC,KAAK,IAAK;EAC7B;EACA,IAAI,CAACA,KAAK,CAACC,UAAU,EAAE;IACrBD,KAAK,CAACC,UAAU,GAAG,CAAC,CAAC;IACrBD,KAAK,CAACE,aAAa,GAAG,CAAC,CAAC;IACxBF,KAAK,CAACG,MAAM,GAAG,CAAC,CAAC;IACjBH,KAAK,CAACI,sBAAsB,GAAG,CAAC,CAAC;EACnC;AACF,CAAC;AAAC,IAAAC,QAAA,GAEa,IAAAC,qBAAY,EAAC,CAAC;EAC3BC,SAAS;EACTP,KAAK;EACLQ,KAAK;EACLC;AACF,CAAC,KAAK;EACJ,MAAM;IACJC,IAAI,GAAGhB;EACT,CAAC,GAAGe,OAAO,CAACE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;EAE5BZ,WAAW,CAACC,KAAK,CAAC;EAElB,KAAK,MAAMY,OAAO,IAAIC,MAAM,CAACC,IAAI,CAACJ,IAAI,CAAC,EAAE;IACvC,MAAMK,aAAa,GAAG,qBAAuBP,KAAK,CAACQ,mBAAmB,CAAC;MACrEJ;IACF,CAAC,CAAE;IAEH,MAAMT,MAAM,GAAGc,OAAO,CAACF,aAAa,IAAIP,KAAK,CAACL,MAAM,CAACY,aAAa,CAAC,CAAC;IAEpEf,KAAK,CAACG,MAAM,CAAC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,CAACjB,KAAK,CAAC,CAAC,CAAC;IACrC;EACF;AACF,CAAC,CAAC;AAAAkB,OAAA,CAAA7C,OAAA,GAAAY,QAAA;AAAAkC,MAAA,CAAAD,OAAA,GAAAA,OAAA,CAAA7C,OAAA"}
|
|
@@ -15,11 +15,28 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
15
15
|
jsdocNode
|
|
16
16
|
}) => {
|
|
17
17
|
const [mainCircumstance, {
|
|
18
|
-
tags
|
|
18
|
+
tags = null
|
|
19
19
|
} = {}] = context.options;
|
|
20
|
+
|
|
21
|
+
/* eslint-disable jsdoc/valid-types -- Old version */
|
|
22
|
+
const tgs =
|
|
23
|
+
/**
|
|
24
|
+
* @type {null|"any"|{[key: string]: "always"|"never"}}
|
|
25
|
+
*/
|
|
26
|
+
tags;
|
|
27
|
+
/* eslint-enable jsdoc/valid-types -- Old version */
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {import('comment-parser').Spec & {
|
|
31
|
+
* line: import('../iterateJsdoc.js').Integer
|
|
32
|
+
* }} jsdocTag
|
|
33
|
+
* @param {string} targetTagName
|
|
34
|
+
* @param {"always"|"never"} [circumstance]
|
|
35
|
+
* @returns {void}
|
|
36
|
+
*/
|
|
20
37
|
const checkHyphens = (jsdocTag, targetTagName, circumstance = mainCircumstance) => {
|
|
21
38
|
const always = !circumstance || circumstance === 'always';
|
|
22
|
-
const desc = utils.getTagDescription(jsdocTag);
|
|
39
|
+
const desc = /** @type {string} */utils.getTagDescription(jsdocTag);
|
|
23
40
|
if (!desc.trim()) {
|
|
24
41
|
return;
|
|
25
42
|
}
|
|
@@ -64,8 +81,8 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
64
81
|
}
|
|
65
82
|
};
|
|
66
83
|
utils.forEachPreferredTag('param', checkHyphens);
|
|
67
|
-
if (
|
|
68
|
-
const tagEntries = Object.entries(
|
|
84
|
+
if (tgs) {
|
|
85
|
+
const tagEntries = Object.entries(tgs);
|
|
69
86
|
for (const [tagName, circumstance] of tagEntries) {
|
|
70
87
|
if (tagName === '*') {
|
|
71
88
|
const preferredParamTag = utils.getPreferredTagName({
|
|
@@ -80,13 +97,13 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
80
97
|
continue;
|
|
81
98
|
}
|
|
82
99
|
utils.forEachPreferredTag(tag, (jsdocTag, targetTagName) => {
|
|
83
|
-
checkHyphens(jsdocTag, targetTagName, circumstance);
|
|
100
|
+
checkHyphens(jsdocTag, targetTagName, /** @type {"always"|"never"} */circumstance);
|
|
84
101
|
});
|
|
85
102
|
}
|
|
86
103
|
continue;
|
|
87
104
|
}
|
|
88
105
|
utils.forEachPreferredTag(tagName, (jsdocTag, targetTagName) => {
|
|
89
|
-
checkHyphens(jsdocTag, targetTagName, circumstance);
|
|
106
|
+
checkHyphens(jsdocTag, targetTagName, /** @type {"always"|"never"} */circumstance);
|
|
90
107
|
});
|
|
91
108
|
}
|
|
92
109
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requireHyphenBeforeParamDescription.js","names":["_iterateJsdoc","_interopRequireDefault","require","obj","__esModule","default","_default","iterateJsdoc","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","lines","tokens","source","reportJSDoc","number","replace","forEachPreferredTag","tagEntries","Object","entries","tagName","preferredParamTag","getPreferredTagName","tag","some","tagNme","iterateAllJsdocs","meta","docs","url","fixable","schema","enum","type","additionalProperties","properties","anyOf","patternProperties","exports","module"],"sources":["../../src/rules/requireHyphenBeforeParamDescription.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc';\n\nexport default iterateJsdoc(({\n sourceCode,\n utils,\n report,\n context,\n jsdoc,\n jsdocNode,\n}) => {\n const [\n mainCircumstance,\n {\n tags,\n } = {},\n ] = 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 let lines = 0;\n for (const {\n tokens,\n } of jsdocTag.source) {\n if (tokens.description) {\n break;\n }\n\n lines++;\n }\n\n utils.reportJSDoc(\n `There must be no hyphen before @${targetTagName} description.`,\n {\n line: jsdocTag.source[0].number + lines,\n },\n () => {\n for (const {\n tokens,\n } of jsdocTag.source) {\n if (tokens.description) {\n tokens.description = tokens.description.replace(\n /^\\s*-\\s*/u, '',\n );\n break;\n }\n }\n },\n true,\n );\n }\n };\n\n utils.forEachPreferredTag('param', checkHyphens);\n if (
|
|
1
|
+
{"version":3,"file":"requireHyphenBeforeParamDescription.js","names":["_iterateJsdoc","_interopRequireDefault","require","obj","__esModule","default","_default","iterateJsdoc","sourceCode","utils","report","context","jsdoc","jsdocNode","mainCircumstance","tags","options","tgs","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","lines","tokens","source","reportJSDoc","number","replace","forEachPreferredTag","tagEntries","Object","entries","tagName","preferredParamTag","getPreferredTagName","tag","some","tagNme","iterateAllJsdocs","meta","docs","url","fixable","schema","enum","type","additionalProperties","properties","anyOf","patternProperties","exports","module"],"sources":["../../src/rules/requireHyphenBeforeParamDescription.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc';\n\nexport default iterateJsdoc(({\n sourceCode,\n utils,\n report,\n context,\n jsdoc,\n jsdocNode,\n}) => {\n const [\n mainCircumstance,\n {\n tags = null,\n } = {},\n ] = context.options;\n\n /* eslint-disable jsdoc/valid-types -- Old version */\n const tgs = /**\n * @type {null|\"any\"|{[key: string]: \"always\"|\"never\"}}\n */ (tags);\n /* eslint-enable jsdoc/valid-types -- Old version */\n\n /**\n * @param {import('comment-parser').Spec & {\n * line: import('../iterateJsdoc.js').Integer\n * }} jsdocTag\n * @param {string} targetTagName\n * @param {\"always\"|\"never\"} [circumstance]\n * @returns {void}\n */\n const checkHyphens = (jsdocTag, targetTagName, circumstance = mainCircumstance) => {\n const always = !circumstance || circumstance === 'always';\n const desc = /** @type {string} */ (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 let lines = 0;\n for (const {\n tokens,\n } of jsdocTag.source) {\n if (tokens.description) {\n break;\n }\n\n lines++;\n }\n\n utils.reportJSDoc(\n `There must be no hyphen before @${targetTagName} description.`,\n {\n line: jsdocTag.source[0].number + lines,\n },\n () => {\n for (const {\n tokens,\n } of jsdocTag.source) {\n if (tokens.description) {\n tokens.description = tokens.description.replace(\n /^\\s*-\\s*/u, '',\n );\n break;\n }\n }\n },\n true,\n );\n }\n };\n\n utils.forEachPreferredTag('param', checkHyphens);\n if (tgs) {\n const tagEntries = Object.entries(tgs);\n for (const [\n tagName,\n circumstance,\n ] of tagEntries) {\n if (tagName === '*') {\n const preferredParamTag = utils.getPreferredTagName({\n tagName: 'param',\n });\n for (const {\n tag,\n } of jsdoc.tags) {\n if (tag === preferredParamTag || tagEntries.some(([\n tagNme,\n ]) => {\n return tagNme !== '*' && tagNme === tag;\n })) {\n continue;\n }\n\n utils.forEachPreferredTag(tag, (jsdocTag, targetTagName) => {\n checkHyphens(\n jsdocTag,\n targetTagName,\n /** @type {\"always\"|\"never\"} */ (circumstance),\n );\n });\n }\n\n continue;\n }\n\n utils.forEachPreferredTag(tagName, (jsdocTag, targetTagName) => {\n checkHyphens(\n jsdocTag,\n targetTagName,\n /** @type {\"always\"|\"never\"} */ (circumstance),\n );\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: [\n 'always', 'never',\n ],\n type: 'string',\n },\n {\n additionalProperties: false,\n properties: {\n tags: {\n anyOf: [\n {\n patternProperties: {\n '.*': {\n enum: [\n 'always', 'never',\n ],\n type: 'string',\n },\n },\n type: 'object',\n },\n {\n enum: [\n 'any',\n ],\n type: 'string',\n },\n ],\n },\n },\n type: 'object',\n },\n ],\n type: 'layout',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA2C,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CA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KAAK,CACN;YACDC,IAAI,EAAE;UACR,CAAC;QAEL;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAAK,OAAA,CAAAlE,OAAA,GAAAC,QAAA;AAAAkE,MAAA,CAAAD,OAAA,GAAAA,OAAA,CAAAlE,OAAA"}
|
|
@@ -9,6 +9,7 @@ var _exportParser = _interopRequireDefault(require("../exportParser"));
|
|
|
9
9
|
var _iterateJsdoc = require("../iterateJsdoc");
|
|
10
10
|
var _jsdocUtils = _interopRequireDefault(require("../jsdocUtils"));
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
/** @type {import('json-schema').JSONSchema4} */
|
|
12
13
|
const OPTIONS_SCHEMA = {
|
|
13
14
|
additionalProperties: false,
|
|
14
15
|
properties: {
|
|
@@ -133,15 +134,49 @@ const OPTIONS_SCHEMA = {
|
|
|
133
134
|
},
|
|
134
135
|
type: 'object'
|
|
135
136
|
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @param {import('eslint').Rule.RuleContext} context
|
|
140
|
+
* @param {import('json-schema').JSONSchema4Object} baseObject
|
|
141
|
+
* @param {string} option
|
|
142
|
+
* @param {string} key
|
|
143
|
+
* @returns {boolean|undefined}
|
|
144
|
+
*/
|
|
136
145
|
const getOption = (context, baseObject, option, key) => {
|
|
137
146
|
if (context.options[0] && option in context.options[0] && (
|
|
138
|
-
// Todo: boolean shouldn't be returning property, but
|
|
147
|
+
// Todo: boolean shouldn't be returning property, but
|
|
148
|
+
// tests currently require
|
|
139
149
|
typeof context.options[0][option] === 'boolean' || key in context.options[0][option])) {
|
|
140
150
|
return context.options[0][option][key];
|
|
141
151
|
}
|
|
142
|
-
|
|
152
|
+
|
|
153
|
+
/* eslint-disable jsdoc/valid-types -- Old version */
|
|
154
|
+
return (/** @type {{[key: string]: {default?: boolean|undefined}}} */baseObject.properties[key].default
|
|
155
|
+
);
|
|
156
|
+
/* eslint-enable jsdoc/valid-types -- Old version */
|
|
143
157
|
};
|
|
158
|
+
|
|
159
|
+
/* eslint-disable jsdoc/valid-types -- Old version */
|
|
160
|
+
/**
|
|
161
|
+
* @param {import('eslint').Rule.RuleContext} context
|
|
162
|
+
* @param {import('../iterateJsdoc.js').Settings} settings
|
|
163
|
+
* @returns {{
|
|
164
|
+
* contexts: (string|{
|
|
165
|
+
* context: string,
|
|
166
|
+
* inlineCommentBlock: boolean,
|
|
167
|
+
* minLineCount: import('../iterateJsdoc.js').Integer
|
|
168
|
+
* })[],
|
|
169
|
+
* enableFixer: boolean,
|
|
170
|
+
* exemptEmptyConstructors: boolean,
|
|
171
|
+
* exemptEmptyFunctions: boolean,
|
|
172
|
+
* fixerMessage: string,
|
|
173
|
+
* minLineCount: undefined|import('../iterateJsdoc.js').Integer,
|
|
174
|
+
* publicOnly: boolean|{[key: string]: boolean|undefined}
|
|
175
|
+
* require: {[key: string]: boolean|undefined}
|
|
176
|
+
* }}
|
|
177
|
+
*/
|
|
144
178
|
const getOptions = (context, settings) => {
|
|
179
|
+
/* eslint-enable jsdoc/valid-types -- Old version */
|
|
145
180
|
const {
|
|
146
181
|
publicOnly,
|
|
147
182
|
contexts = settings.contexts || [],
|
|
@@ -162,21 +197,35 @@ const getOptions = (context, settings) => {
|
|
|
162
197
|
if (!publicOnly) {
|
|
163
198
|
return false;
|
|
164
199
|
}
|
|
200
|
+
|
|
201
|
+
/* eslint-disable jsdoc/valid-types -- Old version */
|
|
202
|
+
/** @type {{[key: string]: boolean|undefined}} */
|
|
165
203
|
const properties = {};
|
|
166
|
-
|
|
167
|
-
|
|
204
|
+
/* eslint-enable jsdoc/valid-types -- Old version */
|
|
205
|
+
for (const prop of Object.keys( /** @type {import('json-schema').JSONSchema4Object} */
|
|
206
|
+
/** @type {import('json-schema').JSONSchema4Object} */baseObj.properties)) {
|
|
207
|
+
const opt = getOption(context, /** @type {import('json-schema').JSONSchema4Object} */baseObj, 'publicOnly', prop);
|
|
168
208
|
properties[prop] = opt;
|
|
169
209
|
}
|
|
170
210
|
return properties;
|
|
171
|
-
})(
|
|
211
|
+
})( /** @type {import('json-schema').JSONSchema4Object} */
|
|
212
|
+
/** @type {import('json-schema').JSONSchema4Object} */
|
|
213
|
+
/** @type {import('json-schema').JSONSchema4Object} */
|
|
214
|
+
OPTIONS_SCHEMA.properties.publicOnly.oneOf[1]),
|
|
172
215
|
require: (baseObj => {
|
|
216
|
+
/* eslint-disable jsdoc/valid-types -- Old version */
|
|
217
|
+
/** @type {{[key: string]: boolean|undefined}} */
|
|
173
218
|
const properties = {};
|
|
174
|
-
|
|
175
|
-
|
|
219
|
+
/* eslint-enable jsdoc/valid-types -- Old version */
|
|
220
|
+
for (const prop of Object.keys( /** @type {import('json-schema').JSONSchema4Object} */
|
|
221
|
+
/** @type {import('json-schema').JSONSchema4Object} */baseObj.properties)) {
|
|
222
|
+
const opt = getOption(context, /** @type {import('json-schema').JSONSchema4Object} */
|
|
223
|
+
baseObj, 'require', prop);
|
|
176
224
|
properties[prop] = opt;
|
|
177
225
|
}
|
|
178
226
|
return properties;
|
|
179
|
-
})(
|
|
227
|
+
})( /** @type {import('json-schema').JSONSchema4Object} */
|
|
228
|
+
OPTIONS_SCHEMA.properties.require)
|
|
180
229
|
};
|
|
181
230
|
};
|
|
182
231
|
|
|
@@ -188,24 +237,43 @@ var _default = {
|
|
|
188
237
|
if (!settings) {
|
|
189
238
|
return {};
|
|
190
239
|
}
|
|
240
|
+
const opts = getOptions(context, settings);
|
|
191
241
|
const {
|
|
192
242
|
require: requireOption,
|
|
193
243
|
contexts,
|
|
194
|
-
publicOnly,
|
|
195
244
|
exemptEmptyFunctions,
|
|
196
245
|
exemptEmptyConstructors,
|
|
197
246
|
enableFixer,
|
|
198
247
|
fixerMessage,
|
|
199
248
|
minLineCount
|
|
200
|
-
} =
|
|
201
|
-
const
|
|
249
|
+
} = opts;
|
|
250
|
+
const publicOnly = /* eslint-disable jsdoc/valid-types -- Old version */
|
|
251
|
+
/**
|
|
252
|
+
* @type {{
|
|
253
|
+
* [key: string]: boolean | undefined;
|
|
254
|
+
* }}
|
|
255
|
+
*/
|
|
256
|
+
opts.publicOnly;
|
|
257
|
+
/* eslint-enable jsdoc/valid-types -- Old version */
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* @type {import('../iterateJsdoc.js').CheckJsdoc}
|
|
261
|
+
*/
|
|
262
|
+
const checkJsDoc = (info, _handler, node) => {
|
|
202
263
|
if (
|
|
203
264
|
// Optimize
|
|
204
|
-
minLineCount !== undefined || contexts.some(
|
|
205
|
-
|
|
206
|
-
|
|
265
|
+
minLineCount !== undefined || contexts.some(ctxt => {
|
|
266
|
+
if (typeof ctxt === 'string') {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
const {
|
|
270
|
+
minLineCount: count
|
|
271
|
+
} = ctxt;
|
|
207
272
|
return count !== undefined;
|
|
208
273
|
})) {
|
|
274
|
+
/**
|
|
275
|
+
* @param {undefined|import('../iterateJsdoc.js').Integer} count
|
|
276
|
+
*/
|
|
209
277
|
const underMinLine = count => {
|
|
210
278
|
var _sourceCode$getText$m;
|
|
211
279
|
return count !== undefined && count > (((_sourceCode$getText$m = sourceCode.getText(node).match(/\n/gu)) === null || _sourceCode$getText$m === void 0 ? void 0 : _sourceCode$getText$m.length) ?? 0) + 1;
|
|
@@ -215,10 +283,22 @@ var _default = {
|
|
|
215
283
|
}
|
|
216
284
|
const {
|
|
217
285
|
minLineCount: contextMinLineCount
|
|
218
|
-
} =
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
286
|
+
} =
|
|
287
|
+
/**
|
|
288
|
+
* @type {{
|
|
289
|
+
* context: string;
|
|
290
|
+
* inlineCommentBlock: boolean;
|
|
291
|
+
* minLineCount: number;
|
|
292
|
+
* }}
|
|
293
|
+
*/
|
|
294
|
+
contexts.find(ctxt => {
|
|
295
|
+
if (typeof ctxt === 'string') {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
const {
|
|
299
|
+
context: ctx
|
|
300
|
+
} = ctxt;
|
|
301
|
+
return ctx === (info.selector || node.type);
|
|
222
302
|
}) || {};
|
|
223
303
|
if (underMinLine(contextMinLineCount)) {
|
|
224
304
|
return;
|
|
@@ -232,6 +312,9 @@ var _default = {
|
|
|
232
312
|
// For those who have options configured against ANY constructors (or
|
|
233
313
|
// setters or getters) being reported
|
|
234
314
|
if (_jsdocUtils.default.exemptSpeciaMethods({
|
|
315
|
+
description: '',
|
|
316
|
+
problems: [],
|
|
317
|
+
source: [],
|
|
235
318
|
tags: []
|
|
236
319
|
}, node, context, [OPTIONS_SCHEMA])) {
|
|
237
320
|
return;
|
|
@@ -251,34 +334,49 @@ var _default = {
|
|
|
251
334
|
const fix = /** @type {import('eslint').Rule.ReportFixer} */fixer => {
|
|
252
335
|
// Default to one line break if the `minLines`/`maxLines` settings allow
|
|
253
336
|
const lines = settings.minLines === 0 && settings.maxLines >= 1 ? 1 : settings.minLines;
|
|
337
|
+
/** @type {import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Decorator} */
|
|
254
338
|
let baseNode = (0, _jsdoccomment.getReducedASTNode)(node, sourceCode);
|
|
255
339
|
const decorator = (0, _jsdoccomment.getDecorator)(baseNode);
|
|
256
340
|
if (decorator) {
|
|
257
341
|
baseNode = decorator;
|
|
258
342
|
}
|
|
259
343
|
const indent = _jsdocUtils.default.getIndent({
|
|
260
|
-
text: sourceCode.getText(baseNode,
|
|
344
|
+
text: sourceCode.getText( /** @type {import('eslint').Rule.Node} */baseNode, /** @type {import('eslint').AST.SourceLocation} */
|
|
345
|
+
/** @type {import('eslint').Rule.Node} */baseNode.loc.start.column)
|
|
261
346
|
});
|
|
262
347
|
const {
|
|
263
348
|
inlineCommentBlock
|
|
264
|
-
} =
|
|
265
|
-
|
|
266
|
-
|
|
349
|
+
} =
|
|
350
|
+
/**
|
|
351
|
+
* @type {{
|
|
352
|
+
* context: string,
|
|
353
|
+
* inlineCommentBlock: boolean,
|
|
354
|
+
* minLineCount: import('../iterateJsdoc.js').Integer
|
|
355
|
+
* }}
|
|
356
|
+
*/
|
|
357
|
+
contexts.find(contxt => {
|
|
358
|
+
if (typeof contxt === 'string') {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
const {
|
|
362
|
+
context: ctxt
|
|
363
|
+
} = contxt;
|
|
267
364
|
return ctxt === node.type;
|
|
268
365
|
}) || {};
|
|
269
366
|
const insertion = (inlineCommentBlock ? `/** ${fixerMessage}` : `/**\n${indent}*${fixerMessage}\n${indent}`) + `*/${'\n'.repeat(lines)}${indent.slice(0, -1)}`;
|
|
270
|
-
return fixer.insertTextBefore(
|
|
367
|
+
return fixer.insertTextBefore( /** @type {import('eslint').Rule.Node} */
|
|
368
|
+
baseNode, insertion);
|
|
271
369
|
};
|
|
272
370
|
const report = () => {
|
|
273
371
|
const {
|
|
274
372
|
start
|
|
275
|
-
} = node.loc;
|
|
373
|
+
} = /** @type {import('eslint').AST.SourceLocation} */node.loc;
|
|
276
374
|
const loc = {
|
|
277
375
|
end: {
|
|
278
376
|
column: 0,
|
|
279
377
|
line: start.line + 1
|
|
280
378
|
},
|
|
281
|
-
start
|
|
379
|
+
start
|
|
282
380
|
};
|
|
283
381
|
context.report({
|
|
284
382
|
fix: enableFixer ? fix : null,
|
|
@@ -302,6 +400,12 @@ var _default = {
|
|
|
302
400
|
report();
|
|
303
401
|
}
|
|
304
402
|
};
|
|
403
|
+
/* eslint-enable complexity -- Temporary */
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* @param {string} prop
|
|
407
|
+
* @returns {boolean}
|
|
408
|
+
*/
|
|
305
409
|
const hasOption = prop => {
|
|
306
410
|
return requireOption[prop] || contexts.some(ctxt => {
|
|
307
411
|
return typeof ctxt === 'object' ? ctxt.context === prop : ctxt === prop;
|
|
@@ -313,7 +417,13 @@ var _default = {
|
|
|
313
417
|
if (!hasOption('ArrowFunctionExpression')) {
|
|
314
418
|
return;
|
|
315
419
|
}
|
|
316
|
-
if (['VariableDeclarator', 'AssignmentExpression', 'ExportDefaultDeclaration'].includes(node.parent.type) || ['Property', 'ObjectProperty', 'ClassProperty', 'PropertyDefinition'].includes(node.parent.type) && node ===
|
|
420
|
+
if (['VariableDeclarator', 'AssignmentExpression', 'ExportDefaultDeclaration'].includes(node.parent.type) || ['Property', 'ObjectProperty', 'ClassProperty', 'PropertyDefinition'].includes(node.parent.type) && node ===
|
|
421
|
+
/**
|
|
422
|
+
* @type {import('@typescript-eslint/types').TSESTree.Property|
|
|
423
|
+
* import('@typescript-eslint/types').TSESTree.PropertyDefinition
|
|
424
|
+
* }
|
|
425
|
+
*/
|
|
426
|
+
node.parent.value) {
|
|
317
427
|
checkJsDoc({
|
|
318
428
|
isFunctionContext: true
|
|
319
429
|
}, null, node);
|
|
@@ -347,7 +457,13 @@ var _default = {
|
|
|
347
457
|
if (!hasOption('FunctionExpression')) {
|
|
348
458
|
return;
|
|
349
459
|
}
|
|
350
|
-
if (['VariableDeclarator', 'AssignmentExpression', 'ExportDefaultDeclaration'].includes(node.parent.type) || ['Property', 'ObjectProperty', 'ClassProperty', 'PropertyDefinition'].includes(node.parent.type) && node ===
|
|
460
|
+
if (['VariableDeclarator', 'AssignmentExpression', 'ExportDefaultDeclaration'].includes(node.parent.type) || ['Property', 'ObjectProperty', 'ClassProperty', 'PropertyDefinition'].includes(node.parent.type) && node ===
|
|
461
|
+
/**
|
|
462
|
+
* @type {import('@typescript-eslint/types').TSESTree.Property|
|
|
463
|
+
* import('@typescript-eslint/types').TSESTree.PropertyDefinition
|
|
464
|
+
* }
|
|
465
|
+
*/
|
|
466
|
+
node.parent.value) {
|
|
351
467
|
checkJsDoc({
|
|
352
468
|
isFunctionContext: true
|
|
353
469
|
}, null, node);
|
|
@@ -360,7 +476,7 @@ var _default = {
|
|
|
360
476
|
checkJsDoc({
|
|
361
477
|
isFunctionContext: true,
|
|
362
478
|
selector: 'MethodDefinition'
|
|
363
|
-
}, null, node.value);
|
|
479
|
+
}, null, /** @type {import('eslint').Rule.Node} */node.value);
|
|
364
480
|
}
|
|
365
481
|
};
|
|
366
482
|
},
|