Skip to content

Commit 9b8efbd

Browse files
authored
fix(multiline-blocks): for requireSingleLineUnderCount, ensure multi-line types nullify checks (#1422)
1 parent 3748bbe commit 9b8efbd

File tree

4 files changed

+67
-15
lines changed

4 files changed

+67
-15
lines changed

.README/rules/multiline-blocks.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ are whitelisted in `singleLineTags`.
4141
### `requireSingleLineUnderCount` (defaults to `null`)
4242

4343
If this number is set, it indicates a minimum line width for a single line of
44-
JSDoc content spread over a multi-line comment block. If a line is under the
45-
minimum length, it will be reported so as to enforce single line JSDoc blocks
46-
for such cases.
44+
JSDoc content spread over a multi-line comment block. If a single line is under
45+
the minimum length, it will be reported so as to enforce single line JSDoc blocks
46+
for such cases. Blocks are not reported which have multi-line descriptions,
47+
multiple tags, a block description and tag, or tags with multi-line types or
48+
descriptions.
4749

4850
### `singleLineTags` (defaults to `['lends', 'type']`)
4951

docs/rules/multiline-blocks.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ are whitelisted in `singleLineTags`.
5555
### <code>requireSingleLineUnderCount</code> (defaults to <code>null</code>)
5656

5757
If this number is set, it indicates a minimum line width for a single line of
58-
JSDoc content spread over a multi-line comment block. If a line is under the
59-
minimum length, it will be reported so as to enforce single line JSDoc blocks
60-
for such cases.
58+
JSDoc content spread over a multi-line comment block. If a single line is under
59+
the minimum length, it will be reported so as to enforce single line JSDoc blocks
60+
for such cases. Blocks are not reported which have multi-line descriptions,
61+
multiple tags, a block description and tag, or tags with multi-line types or
62+
descriptions.
6163

6264
<a name="user-content-options-singlelinetags-defaults-to-lends-type"></a>
6365
<a name="options-singlelinetags-defaults-to-lends-type"></a>
@@ -469,5 +471,22 @@ The following patterns are not considered problems:
469471
* @someTag
470472
*/
471473
// "jsdoc/multiline-blocks": ["error"|"warn", {"requireSingleLineUnderCount":80}]
474+
475+
/**
476+
* @someTag
477+
* @anotherTag
478+
*/
479+
// "jsdoc/multiline-blocks": ["error"|"warn", {"requireSingleLineUnderCount":80}]
480+
481+
/**
482+
* @type {{
483+
visible: import("vue").Ref<boolean>,
484+
attack: import("vue").Ref<AttackPve|AttackPvp|undefined>,
485+
hero: import("vue").Ref<HeroOwn|undefined>,
486+
outpost: import("vue").Ref<Outpost|undefined>,
487+
rewards: import("vue").Ref<Rewards|undefined>
488+
* }}
489+
*/
490+
// "jsdoc/multiline-blocks": ["error"|"warn", {"requireSingleLineUnderCount":120}]
472491
````
473492

src/rules/multilineBlocks.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const checkForShortTags = (jsdoc, utils, requireSingleLineUnderCount) => {
1111
}
1212

1313
let lastLineWithTag = 0;
14-
let exceedsLength = false;
15-
let hasDesc = false;
14+
let isUnderCountLimit = false;
15+
let hasMultiDescOrType = false;
1616
const tagLines = jsdoc.source.reduce((acc, {
1717
tokens: {
1818
delimiter,
@@ -35,19 +35,19 @@ const checkForShortTags = (jsdoc, utils, requireSingleLineUnderCount) => {
3535
tag.length + postTag.length + desc.length <
3636
requireSingleLineUnderCount
3737
) {
38-
exceedsLength = true;
38+
isUnderCountLimit = true;
3939
}
4040

4141
return acc + 1;
42-
} else if (desc.length) {
43-
hasDesc = true;
42+
} else if (desc.length || type.length) {
43+
hasMultiDescOrType = true;
4444
return acc;
4545
}
4646

4747
return acc;
4848
}, 0);
4949
// Could be tagLines > 1
50-
if (!hasDesc && exceedsLength && tagLines === 1) {
50+
if (!hasMultiDescOrType && isUnderCountLimit && tagLines === 1) {
5151
const fixer = () => {
5252
const tokens = jsdoc.source[lastLineWithTag].tokens;
5353
jsdoc.source = [
@@ -93,7 +93,7 @@ const checkForShortDescriptions = (jsdoc, utils, requireSingleLineUnderCount) =>
9393
}
9494

9595
let lastLineWithDesc = 0;
96-
let exceedsLength = false;
96+
let isUnderCountLimit = false;
9797
const descLines = jsdoc.source.reduce((acc, {
9898
tokens: {
9999
delimiter,
@@ -108,7 +108,7 @@ const checkForShortDescriptions = (jsdoc, utils, requireSingleLineUnderCount) =>
108108
start.length + delimiter.length + postDelimiter.length + desc.length <
109109
requireSingleLineUnderCount
110110
) {
111-
exceedsLength = true;
111+
isUnderCountLimit = true;
112112
}
113113

114114
return acc + 1;
@@ -117,7 +117,7 @@ const checkForShortDescriptions = (jsdoc, utils, requireSingleLineUnderCount) =>
117117
return acc;
118118
}, 0);
119119
// Could be descLines > 1
120-
if (exceedsLength && descLines === 1) {
120+
if (isUnderCountLimit && descLines === 1) {
121121
const fixer = () => {
122122
const desc = jsdoc.source[lastLineWithDesc].tokens.description;
123123
jsdoc.source = [

test/rules/assertions/multilineBlocks.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,5 +1100,36 @@ export default /** @type {import('../index.js').TestCases} */ ({
11001100
},
11011101
],
11021102
},
1103+
{
1104+
code: `
1105+
/**
1106+
* @someTag
1107+
* @anotherTag
1108+
*/
1109+
`,
1110+
options: [
1111+
{
1112+
requireSingleLineUnderCount: 80,
1113+
},
1114+
],
1115+
},
1116+
{
1117+
code: `
1118+
/**
1119+
* @type {{
1120+
visible: import("vue").Ref<boolean>,
1121+
attack: import("vue").Ref<AttackPve|AttackPvp|undefined>,
1122+
hero: import("vue").Ref<HeroOwn|undefined>,
1123+
outpost: import("vue").Ref<Outpost|undefined>,
1124+
rewards: import("vue").Ref<Rewards|undefined>
1125+
* }}
1126+
*/
1127+
`,
1128+
options: [
1129+
{
1130+
requireSingleLineUnderCount: 120,
1131+
},
1132+
],
1133+
},
11031134
],
11041135
});

0 commit comments

Comments
 (0)