Skip to content

Commit 19f60ac

Browse files
committed
fix(multiline-blocks): ensure noZeroLineText checks when noMultilineBlocks is true but not matching; fixes #737
1 parent 355da58 commit 19f60ac

File tree

3 files changed

+70
-28
lines changed

3 files changed

+70
-28
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7276,6 +7276,12 @@ The following patterns are considered problems:
72767276
*/
72777277
// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":true,"noSingleLineBlocks":true}]
72787278
// Message: Multiline jsdoc blocks are prohibited by your configuration but fixing would result in a single line block which you have prohibited with `noSingleLineBlocks`.
7279+
7280+
/** This comment is bad
7281+
* It should not have text on line zero
7282+
*/
7283+
// "jsdoc/multiline-blocks": ["error"|"warn", {"minimumLengthForMultiline":50,"noMultilineBlocks":true,"noZeroLineText":true}]
7284+
// Message: Should have no text on the "0th" line (after the `/**`).
72797285
````
72807286
72817287
The following patterns are not considered problems:

src/rules/multilineBlocks.js

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,37 @@ export default iterateJsdoc(({
9696
return;
9797
}
9898

99+
const checkZeroLineText = () => {
100+
if (
101+
noZeroLineText &&
102+
(tag || description)
103+
) {
104+
const fixer = () => {
105+
const line = {...tokens};
106+
emptyTokens();
107+
const {tokens: {delimiter, start}} = jsdoc.source[1];
108+
utils.addLine(1, {...line, delimiter, start});
109+
};
110+
utils.reportJSDoc(
111+
'Should have no text on the "0th" line (after the `/**`).',
112+
null, fixer,
113+
);
114+
}
115+
};
116+
99117
if (noMultilineBlocks) {
100118
if (
101119
jsdoc.tags.length &&
102120
(multilineTags.includes('*') || utils.hasATag(multilineTags))
103121
) {
122+
checkZeroLineText();
123+
104124
return;
105125
}
106126

107127
if (jsdoc.description.length >= minimumLengthForMultiline) {
128+
checkZeroLineText();
129+
108130
return;
109131
}
110132

@@ -120,22 +142,28 @@ export default iterateJsdoc(({
120142
'your configuration but fixing would result in a single ' +
121143
'line block which you have prohibited with `noSingleLineBlocks`.',
122144
);
123-
} else if (jsdoc.tags.length > 1) {
124-
if (allowMultipleTags) {
145+
146+
return;
147+
}
148+
149+
if (jsdoc.tags.length > 1) {
150+
if (!allowMultipleTags) {
151+
utils.reportJSDoc(
152+
'Multiline jsdoc blocks are prohibited by ' +
153+
'your configuration but the block has multiple tags.',
154+
);
155+
125156
return;
126157
}
127-
utils.reportJSDoc(
128-
'Multiline jsdoc blocks are prohibited by ' +
129-
'your configuration but the block has multiple tags.',
130-
);
131158
} else if (jsdoc.tags.length === 1 && jsdoc.description.trim()) {
132-
if (allowMultipleTags) {
159+
if (!allowMultipleTags) {
160+
utils.reportJSDoc(
161+
'Multiline jsdoc blocks are prohibited by ' +
162+
'your configuration but the block has a description with a tag.',
163+
);
164+
133165
return;
134166
}
135-
utils.reportJSDoc(
136-
'Multiline jsdoc blocks are prohibited by ' +
137-
'your configuration but the block has a description with a tag.',
138-
);
139167
} else {
140168
const fixer = () => {
141169
jsdoc.source = [{
@@ -186,26 +214,12 @@ export default iterateJsdoc(({
186214
'your configuration.',
187215
null, fixer,
188216
);
189-
}
190217

191-
return;
218+
return;
219+
}
192220
}
193221

194-
if (
195-
noZeroLineText &&
196-
(tag || description)
197-
) {
198-
const fixer = () => {
199-
const line = {...tokens};
200-
emptyTokens();
201-
const {tokens: {delimiter, start}} = jsdoc.source[1];
202-
utils.addLine(1, {...line, delimiter, start});
203-
};
204-
utils.reportJSDoc(
205-
'Should have no text on the "0th" line (after the `/**`).',
206-
null, fixer,
207-
);
208-
}
222+
checkZeroLineText();
209223
}, {
210224
iterateAllJsdocs: true,
211225
meta: {

test/rules/assertions/multilineBlocks.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,28 @@ export default {
425425
noSingleLineBlocks: true,
426426
}],
427427
},
428+
{
429+
code: `
430+
/** This comment is bad
431+
* It should not have text on line zero
432+
*/
433+
`,
434+
errors: [{
435+
line: 2,
436+
message: 'Should have no text on the "0th" line (after the `/**`).',
437+
}],
438+
options: [{
439+
minimumLengthForMultiline: 50,
440+
noMultilineBlocks: true,
441+
noZeroLineText: true,
442+
}],
443+
output: `
444+
/**
445+
* This comment is bad
446+
* It should not have text on line zero
447+
*/
448+
`,
449+
},
428450
],
429451
valid: [
430452
{

0 commit comments

Comments
 (0)