Skip to content

Commit

Permalink
fix(multiline-blocks): fix merging of lines to prevent removal of s…
Browse files Browse the repository at this point in the history
…paces, though removing where needed
  • Loading branch information
brettz9 committed May 16, 2021
1 parent 19f60ac commit 9af6e36
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions src/rules/multilineBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 += ' ';
}

Expand Down
20 changes: 20 additions & 0 deletions test/rules/assertions/multilineBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down

0 comments on commit 9af6e36

Please sign in to comment.