diff --git a/README.md b/README.md index a224464a5..a28a4e804 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/src/rules/multilineBlocks.js b/src/rules/multilineBlocks.js index ef570478e..b633d81d4 100644 --- a/src/rules/multilineBlocks.js +++ b/src/rules/multilineBlocks.js @@ -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; } @@ -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 = [{ @@ -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: { diff --git a/test/rules/assertions/multilineBlocks.js b/test/rules/assertions/multilineBlocks.js index 5911ef92c..d12968d97 100644 --- a/test/rules/assertions/multilineBlocks.js +++ b/test/rules/assertions/multilineBlocks.js @@ -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: [ {