From 9af6e3615f318f92d2e108fe5d7a03b837d89ed7 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Mon, 17 May 2021 02:00:16 +0800 Subject: [PATCH] fix(`multiline-blocks`): fix merging of lines to prevent removal of spaces, though removing where needed --- README.md | 7 +++++++ src/rules/multilineBlocks.js | 7 +++++-- test/rules/assertions/multilineBlocks.js | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a28a4e804..789da96f7 100644 --- a/README.md +++ b/README.md @@ -7282,6 +7282,13 @@ The following patterns are considered problems: */ // "jsdoc/multiline-blocks": ["error"|"warn", {"minimumLengthForMultiline":50,"noMultilineBlocks":true,"noZeroLineText":true}] // Message: Should have no text on the "0th" line (after the `/**`). + +/** + * @lends This can be safely fixed + * to a single + * line. */ +// "jsdoc/multiline-blocks": ["error"|"warn", {"multilineTags":[],"noMultilineBlocks":true}] +// Message: Multiline jsdoc blocks are prohibited by your configuration. ```` The following patterns are not considered problems: diff --git a/src/rules/multilineBlocks.js b/src/rules/multilineBlocks.js index b633d81d4..52f65d5e6 100644 --- a/src/rules/multilineBlocks.js +++ b/src/rules/multilineBlocks.js @@ -174,7 +174,7 @@ export default iterateJsdoc(({ description: desc, tag: tg, type: typ, name: nme, postType, postName, postTag, }, - }, idx, arr) => { + }) => { if (typ) { obj.type = typ; } @@ -189,7 +189,10 @@ export default iterateJsdoc(({ } obj.description += desc; - if ((obj.name || obj.description) && idx === arr.length - 1) { + const nameOrDescription = obj.description || obj.name; + if ( + nameOrDescription && nameOrDescription.slice(-1) !== ' ' + ) { obj.description += ' '; } diff --git a/test/rules/assertions/multilineBlocks.js b/test/rules/assertions/multilineBlocks.js index d12968d97..5617f6ad7 100644 --- a/test/rules/assertions/multilineBlocks.js +++ b/test/rules/assertions/multilineBlocks.js @@ -447,6 +447,26 @@ export default { */ `, }, + { + code: ` + /** + * @lends This can be safely fixed + * to a single + * line. */ + `, + errors: [{ + line: 2, + message: 'Multiline jsdoc blocks are prohibited by ' + + 'your configuration.', + }], + options: [{ + multilineTags: [], + noMultilineBlocks: true, + }], + output: ` + /** @lends This can be safely fixed to a single line. */ + `, + }, ], valid: [ {