From 34960110f0480e953432f305929cb8e22285f2f4 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Wed, 19 May 2021 11:48:43 +0800 Subject: [PATCH] fix(`tag-lines`): avoid false positive for "never" when line break occurs in the middle of a tag description. --- README.md | 20 +++++++++++++++++ src/rules/tagLines.js | 36 ++++++++++++++++++++----------- test/rules/assertions/tagLines.js | 26 ++++++++++++++++++++++ 3 files changed, 69 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6a5407eca..ebb33149f 100644 --- a/README.md +++ b/README.md @@ -19249,6 +19249,26 @@ The following patterns are not considered problems: * @param {number} b */ // "jsdoc/tag-lines": ["error"|"warn", "never",{"tags":{"anotherTag":{"lines":"always"}}}] + +/** + * Some description + * @param {string} a + * + * This is still part of `@param`. + * @returns {SomeType} An extended + * description. + */ +// "jsdoc/tag-lines": ["error"|"warn", "never"] + +/** + * Some description + * @param {string} a + * @returns {SomeType} An extended + * description. + * + * This is still part of `@returns`. + */ +// "jsdoc/tag-lines": ["error"|"warn", "never"] ```` diff --git a/src/rules/tagLines.js b/src/rules/tagLines.js index e55e423e2..d4ac9a5c7 100644 --- a/src/rules/tagLines.js +++ b/src/rules/tagLines.js @@ -17,12 +17,14 @@ export default iterateJsdoc(({ jsdoc.tags.some((tg, tagIdx) => { let lastTag; - return tg.source.some(({tokens: {tag, name, type, description, end}}, idx) => { - const fixer = () => { - utils.removeTagItem(tagIdx, idx); - }; + let reportIndex = null; + tg.source.forEach(({tokens: {tag, name, type, description, end}}, idx) => { + // May be text after a line break within a tag description + if (description) { + reportIndex = null; + } if (lastTag && tags[lastTag.slice(1)]?.lines === 'always') { - return false; + return; } if ( @@ -31,19 +33,27 @@ export default iterateJsdoc(({ lastTag && tags[lastTag.slice(1)]?.lines === 'never' ) ) { - utils.reportJSDoc( - 'Expected no lines between tags', - {line: tg.source[0].number + 1}, - fixer, - ); + reportIndex = idx; - return true; + return; } lastTag = tag; - - return false; }); + if (reportIndex !== null) { + const fixer = () => { + utils.removeTagItem(tagIdx, reportIndex); + }; + utils.reportJSDoc( + 'Expected no lines between tags', + {line: tg.source[0].number + 1}, + fixer, + ); + + return true; + } + + return false; }); (noEndLines ? jsdoc.tags.slice(0, -1) : jsdoc.tags).some((tg, tagIdx) => { diff --git a/test/rules/assertions/tagLines.js b/test/rules/assertions/tagLines.js index fb5f95d38..e0885deef 100644 --- a/test/rules/assertions/tagLines.js +++ b/test/rules/assertions/tagLines.js @@ -529,5 +529,31 @@ export default { }, }], }, + { + code: ` + /** + * Some description + * @param {string} a + * + * This is still part of \`@param\`. + * @returns {SomeType} An extended + * description. + */ + `, + options: ['never'], + }, + { + code: ` + /** + * Some description + * @param {string} a + * @returns {SomeType} An extended + * description. + * + * This is still part of \`@returns\`. + */ + `, + options: ['never'], + }, ], };