From ef02d5b5a7c385d83792f1d3c6ba6f472c7abc76 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Thu, 20 Apr 2023 08:36:41 -0700 Subject: [PATCH] fix: description retrieval logic was problematic for single line tags; fixes #1036 --- README.md | 12 ++++++++++++ src/iterateJsdoc.js | 9 +++++++-- .../requireDescriptionCompleteSentence.js | 6 ++++++ test/rules/assertions/tagLines.js | 18 ++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5f54b8215..4e7ee052c 100644 --- a/README.md +++ b/README.md @@ -12329,6 +12329,9 @@ export default (foo) => { /** @file To learn more, * see: https://github.com/d3/d3-ease. */ +/** To learn more, + * see: https://github.com/d3/d3-ease. */ + /** * This is a complete sentence... */ @@ -23488,6 +23491,15 @@ function processSass (input) { function updateIconButton () { } // "jsdoc/tag-lines": ["error"|"warn", "never",{"startLines":1}] + +/** A class. */ +class _Foo { + /** @param arg Argument. */ + conststructor(arg: string) { + console.log(arg); + } +} +// "jsdoc/tag-lines": ["error"|"warn", "any",{"startLines":1}] ```` diff --git a/src/iterateJsdoc.js b/src/iterateJsdoc.js index 66227ffe9..a59382bb9 100644 --- a/src/iterateJsdoc.js +++ b/src/iterateJsdoc.js @@ -229,6 +229,7 @@ const getUtils = ( utils.getDescription = () => { const descriptions = []; let lastDescriptionLine = 0; + let tagsBegun = false; jsdoc.source.some(({ tokens: { description, @@ -236,16 +237,20 @@ const getUtils = ( end, }, }, idx) => { + if (tag) { + tagsBegun = true; + } + if (idx && (tag || end)) { lastDescriptionLine = idx - 1; - if (!tag && description) { + if (!tagsBegun && description) { descriptions.push(description); } return true; } - if (idx || description) { + if (!tagsBegun && (idx || description)) { descriptions.push(description || (descriptions.length ? '' : '\n')); } diff --git a/test/rules/assertions/requireDescriptionCompleteSentence.js b/test/rules/assertions/requireDescriptionCompleteSentence.js index 2261cd884..b7ca18d65 100644 --- a/test/rules/assertions/requireDescriptionCompleteSentence.js +++ b/test/rules/assertions/requireDescriptionCompleteSentence.js @@ -1486,6 +1486,12 @@ export default { * see: https://github.com/d3/d3-ease. */ `, }, + { + code: ` + /** To learn more, + * see: https://github.com/d3/d3-ease. */ + `, + }, { code: ` /** diff --git a/test/rules/assertions/tagLines.js b/test/rules/assertions/tagLines.js index eef984925..15b732974 100644 --- a/test/rules/assertions/tagLines.js +++ b/test/rules/assertions/tagLines.js @@ -1139,5 +1139,23 @@ export default { }, ], }, + { + code: ` + /** A class. */ + class _Foo { + /** @param arg Argument. */ + conststructor(arg: string) { + console.log(arg); + } + } + `, + options: [ + 'any', + { + startLines: 1, + }, + ], + parser: require.resolve('@typescript-eslint/parser'), + }, ], };