Skip to content

Commit

Permalink
fix(tag-lines): ensure a middle-of-block empty line doesn't suppres…
Browse files Browse the repository at this point in the history
…s "always" errors

Also ensure reporting line number at end of any muitline tag description
  • Loading branch information
brettz9 committed May 19, 2021
1 parent 3496011 commit 33aa921
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 2 deletions.
46 changes: 46 additions & 0 deletions README.md
Expand Up @@ -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:
Expand Down Expand Up @@ -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"]
````


Expand Down
9 changes: 7 additions & 2 deletions src/rules/tagLines.js
Expand Up @@ -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;
}
Expand All @@ -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}`,
{
Expand Down
86 changes: 86 additions & 0 deletions test/rules/assertions/tagLines.js
Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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'],
},
],
};

0 comments on commit 33aa921

Please sign in to comment.