Skip to content

Commit

Permalink
fix(multiline-blocks): ensure noZeroLineText checks when `noMulti…
Browse files Browse the repository at this point in the history
…lineBlocks` is `true` but not matching; fixes #737
  • Loading branch information
brettz9 committed May 16, 2021
1 parent 355da58 commit 19f60ac
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 28 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -7276,6 +7276,12 @@ The following patterns are considered problems:
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":true,"noSingleLineBlocks":true}]
// Message: Multiline jsdoc blocks are prohibited by your configuration but fixing would result in a single line block which you have prohibited with `noSingleLineBlocks`.
/** This comment is bad
* It should not have text on line zero
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"minimumLengthForMultiline":50,"noMultilineBlocks":true,"noZeroLineText":true}]
// Message: Should have no text on the "0th" line (after the `/**`).
````
The following patterns are not considered problems:
Expand Down
70 changes: 42 additions & 28 deletions src/rules/multilineBlocks.js
Expand Up @@ -96,15 +96,37 @@ export default iterateJsdoc(({
return;
}

const checkZeroLineText = () => {
if (
noZeroLineText &&
(tag || description)
) {
const fixer = () => {
const line = {...tokens};
emptyTokens();
const {tokens: {delimiter, start}} = jsdoc.source[1];
utils.addLine(1, {...line, delimiter, start});
};
utils.reportJSDoc(
'Should have no text on the "0th" line (after the `/**`).',
null, fixer,
);
}
};

if (noMultilineBlocks) {
if (
jsdoc.tags.length &&
(multilineTags.includes('*') || utils.hasATag(multilineTags))
) {
checkZeroLineText();

return;
}

if (jsdoc.description.length >= minimumLengthForMultiline) {
checkZeroLineText();

return;
}

Expand All @@ -120,22 +142,28 @@ export default iterateJsdoc(({
'your configuration but fixing would result in a single ' +
'line block which you have prohibited with `noSingleLineBlocks`.',
);
} else if (jsdoc.tags.length > 1) {
if (allowMultipleTags) {

return;
}

if (jsdoc.tags.length > 1) {
if (!allowMultipleTags) {
utils.reportJSDoc(
'Multiline jsdoc blocks are prohibited by ' +
'your configuration but the block has multiple tags.',
);

return;
}
utils.reportJSDoc(
'Multiline jsdoc blocks are prohibited by ' +
'your configuration but the block has multiple tags.',
);
} else if (jsdoc.tags.length === 1 && jsdoc.description.trim()) {
if (allowMultipleTags) {
if (!allowMultipleTags) {
utils.reportJSDoc(
'Multiline jsdoc blocks are prohibited by ' +
'your configuration but the block has a description with a tag.',
);

return;
}
utils.reportJSDoc(
'Multiline jsdoc blocks are prohibited by ' +
'your configuration but the block has a description with a tag.',
);
} else {
const fixer = () => {
jsdoc.source = [{
Expand Down Expand Up @@ -186,26 +214,12 @@ export default iterateJsdoc(({
'your configuration.',
null, fixer,
);
}

return;
return;
}
}

if (
noZeroLineText &&
(tag || description)
) {
const fixer = () => {
const line = {...tokens};
emptyTokens();
const {tokens: {delimiter, start}} = jsdoc.source[1];
utils.addLine(1, {...line, delimiter, start});
};
utils.reportJSDoc(
'Should have no text on the "0th" line (after the `/**`).',
null, fixer,
);
}
checkZeroLineText();
}, {
iterateAllJsdocs: true,
meta: {
Expand Down
22 changes: 22 additions & 0 deletions test/rules/assertions/multilineBlocks.js
Expand Up @@ -425,6 +425,28 @@ export default {
noSingleLineBlocks: true,
}],
},
{
code: `
/** This comment is bad
* It should not have text on line zero
*/
`,
errors: [{
line: 2,
message: 'Should have no text on the "0th" line (after the `/**`).',
}],
options: [{
minimumLengthForMultiline: 50,
noMultilineBlocks: true,
noZeroLineText: true,
}],
output: `
/**
* This comment is bad
* It should not have text on line zero
*/
`,
},
],
valid: [
{
Expand Down

0 comments on commit 19f60ac

Please sign in to comment.