Skip to content

Commit

Permalink
fix(tag-lines): avoid false positive for "never" when line break oc…
Browse files Browse the repository at this point in the history
…curs in the middle of a tag description.
  • Loading branch information
brettz9 committed May 19, 2021
1 parent 6e5e76d commit 3496011
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 13 deletions.
20 changes: 20 additions & 0 deletions README.md
Expand Up @@ -19249,6 +19249,26 @@ The following patterns are not considered problems:
* @param {number} b
*/
// "jsdoc/tag-lines": ["error"|"warn", "never",{"tags":{"anotherTag":{"lines":"always"}}}]

/**
* Some description
* @param {string} a
*
* This is still part of `@param`.
* @returns {SomeType} An extended
* description.
*/
// "jsdoc/tag-lines": ["error"|"warn", "never"]

/**
* Some description
* @param {string} a
* @returns {SomeType} An extended
* description.
*
* This is still part of `@returns`.
*/
// "jsdoc/tag-lines": ["error"|"warn", "never"]
````


Expand Down
36 changes: 23 additions & 13 deletions src/rules/tagLines.js
Expand Up @@ -17,12 +17,14 @@ export default iterateJsdoc(({
jsdoc.tags.some((tg, tagIdx) => {
let lastTag;

return tg.source.some(({tokens: {tag, name, type, description, end}}, idx) => {
const fixer = () => {
utils.removeTagItem(tagIdx, idx);
};
let reportIndex = null;
tg.source.forEach(({tokens: {tag, name, type, description, end}}, idx) => {
// May be text after a line break within a tag description
if (description) {
reportIndex = null;
}
if (lastTag && tags[lastTag.slice(1)]?.lines === 'always') {
return false;
return;
}

if (
Expand All @@ -31,19 +33,27 @@ export default iterateJsdoc(({
lastTag && tags[lastTag.slice(1)]?.lines === 'never'
)
) {
utils.reportJSDoc(
'Expected no lines between tags',
{line: tg.source[0].number + 1},
fixer,
);
reportIndex = idx;

return true;
return;
}

lastTag = tag;

return false;
});
if (reportIndex !== null) {
const fixer = () => {
utils.removeTagItem(tagIdx, reportIndex);
};
utils.reportJSDoc(
'Expected no lines between tags',
{line: tg.source[0].number + 1},
fixer,
);

return true;
}

return false;
});

(noEndLines ? jsdoc.tags.slice(0, -1) : jsdoc.tags).some((tg, tagIdx) => {
Expand Down
26 changes: 26 additions & 0 deletions test/rules/assertions/tagLines.js
Expand Up @@ -529,5 +529,31 @@ export default {
},
}],
},
{
code: `
/**
* Some description
* @param {string} a
*
* This is still part of \`@param\`.
* @returns {SomeType} An extended
* description.
*/
`,
options: ['never'],
},
{
code: `
/**
* Some description
* @param {string} a
* @returns {SomeType} An extended
* description.
*
* This is still part of \`@returns\`.
*/
`,
options: ['never'],
},
],
};

0 comments on commit 3496011

Please sign in to comment.