Skip to content

Commit

Permalink
fix: multiline tag fixers omitting subsequent tag lines with new comm…
Browse files Browse the repository at this point in the history
…and-parser API
  • Loading branch information
brettz9 committed May 11, 2021
1 parent afcc8ed commit 8fa7f9b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3024,6 +3024,17 @@ function quux ({cfg}) {

}
// Message: @param "root.cfg.foo" does not exist on root

/**
* @param foo
* @param foo
* on another line
*/
function quux (foo) {

}
// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
// Message: Duplicate @param "foo"
````

The following patterns are not considered problems:
Expand Down
22 changes: 19 additions & 3 deletions src/iterateJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,35 @@ const getUtils = (
};

utils.removeTag = (tagIndex) => {
const {source} = jsdoc.tags[tagIndex];
const {source: tagSource} = jsdoc.tags[tagIndex];
let lastIndex;
const firstNumber = jsdoc.source[0].number;
source.forEach(({number}) => {
tagSource.some(({number}, tagIdx) => {
const sourceIndex = jsdoc.source.findIndex(({
number: srcNumber, tokens: {end},
}) => {
return number === srcNumber && !end;
});
// istanbul ignore else
if (sourceIndex > -1) {
jsdoc.source.splice(sourceIndex, 1);
let spliceCount = 1;
tagSource.slice(tagIdx + 1).some(({tokens: {tag, end}}) => {
if (!tag && !end) {
spliceCount++;

return false;
}

return true;
});
jsdoc.source.splice(sourceIndex, spliceCount);
lastIndex = sourceIndex;

return true;
}

// istanbul ignore next
return false;
});
jsdoc.source.slice(lastIndex).forEach((src, idx) => {
src.number = firstNumber + lastIndex + idx;
Expand Down
31 changes: 31 additions & 0 deletions test/rules/assertions/checkParamNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,37 @@ export default {
},
],
},
{
code: `
/**
* @param foo
* @param foo
* on another line
*/
function quux (foo) {
}
`,
errors: [
{
line: 4,
message: 'Duplicate @param "foo"',
},
],
options: [
{
enableFixer: true,
},
],
output: `
/**
* @param foo
*/
function quux (foo) {
}
`,
},
],
valid: [
{
Expand Down

0 comments on commit 8fa7f9b

Please sign in to comment.