From 33aa92155ed96acb0509546c5cafb816daa73bb7 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Wed, 19 May 2021 12:08:52 +0800 Subject: [PATCH] fix(`tag-lines`): ensure a middle-of-block empty line doesn't suppress "always" errors Also ensure reporting line number at end of any muitline tag description --- README.md | 46 +++++++++++++++++ src/rules/tagLines.js | 9 +++- test/rules/assertions/tagLines.js | 86 +++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ebb33149f..f70838715 100644 --- a/README.md +++ b/README.md @@ -19151,6 +19151,28 @@ The following patterns are considered problems: */ // "jsdoc/tag-lines": ["error"|"warn", "always",{"tags":{"anotherTag":{"lines":"never"}}}] // Message: Expected 1 line between tags but found 0 + +/** + * Some description + * @param {string} A broken up + * + * tag description. + * @param {number} b + * + */ +// "jsdoc/tag-lines": ["error"|"warn", "always"] +// Message: Expected 1 line between tags but found 0 + +/** + * Some description + * @param {number} b + * + * @returns {string} A broken up + * + * tag description. + */ +// "jsdoc/tag-lines": ["error"|"warn", "always"] +// Message: Expected 1 line between tags but found 0 ```` The following patterns are not considered problems: @@ -19269,6 +19291,30 @@ The following patterns are not considered problems: * This is still part of `@returns`. */ // "jsdoc/tag-lines": ["error"|"warn", "never"] + +/** + * Some description + * @param {string} a + * + * This is still part of `@param`. + * + * @returns {SomeType} An extended + * description. + * + */ +// "jsdoc/tag-lines": ["error"|"warn", "always"] + +/** + * Some description + * @param {string} a + * + * @returns {SomeType} An extended + * description. + * + * This is still part of `@returns`. + * + */ +// "jsdoc/tag-lines": ["error"|"warn", "always"] ```` diff --git a/src/rules/tagLines.js b/src/rules/tagLines.js index d4ac9a5c7..dede7835a 100644 --- a/src/rules/tagLines.js +++ b/src/rules/tagLines.js @@ -60,7 +60,12 @@ export default iterateJsdoc(({ const lines = []; let currentTag; + let tagSourceIdx = 0; tg.source.forEach(({number, tokens: {tag, name, type, description, end}}, idx) => { + if (description) { + lines.splice(0, lines.length); + tagSourceIdx = idx; + } if (tag) { currentTag = tag; } @@ -85,9 +90,9 @@ export default iterateJsdoc(({ if (defaultAlways || overrideAlways) { const fixer = () => { - utils.addLines(tagIdx, lines[lines.length - 1]?.idx || 1, fixCount - lines.length); + utils.addLines(tagIdx, lines[lines.length - 1]?.idx || tagSourceIdx + 1, fixCount - lines.length); }; - const line = lines[lines.length - 1]?.number || tg.source[0].number; + const line = lines[lines.length - 1]?.number || tg.source[tagSourceIdx].number; utils.reportJSDoc( `Expected ${fixCount} line${fixCount === 1 ? '' : 's'} between tags but found ${lines.length}`, { diff --git a/test/rules/assertions/tagLines.js b/test/rules/assertions/tagLines.js index e0885deef..e6092d000 100644 --- a/test/rules/assertions/tagLines.js +++ b/test/rules/assertions/tagLines.js @@ -348,6 +348,62 @@ export default { */ `, }, + { + code: ` + /** + * Some description + * @param {string} A broken up + * + * tag description. + * @param {number} b + * + */ + `, + errors: [{ + line: 6, + message: 'Expected 1 line between tags but found 0', + }], + options: ['always'], + output: ` + /** + * Some description + * @param {string} A broken up + * + * tag description. + * + * @param {number} b + * + */ + `, + }, + { + code: ` + /** + * Some description + * @param {number} b + * + * @returns {string} A broken up + * + * tag description. + */ + `, + errors: [{ + line: 8, + message: 'Expected 1 line between tags but found 0', + }], + options: ['always'], + output: ` + /** + * Some description + * @param {number} b + * + * @returns {string} A broken up + * + * tag description. + * + */ + `, + }, ], valid: [ { @@ -555,5 +611,35 @@ export default { `, options: ['never'], }, + { + code: ` + /** + * Some description + * @param {string} a + * + * This is still part of \`@param\`. + * + * @returns {SomeType} An extended + * description. + * + */ + `, + options: ['always'], + }, + { + code: ` + /** + * Some description + * @param {string} a + * + * @returns {SomeType} An extended + * description. + * + * This is still part of \`@returns\`. + * + */ + `, + options: ['always'], + }, ], };