Skip to content

Commit 24a8b51

Browse files
mvarchdevbrettz9
authored andcommitted
fix(requireParam): update return type to include foundIndex and tagLineCount, fixes #1530
1 parent 751428c commit 24a8b51

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/rules/requireParam.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ export default iterateJsdoc(({
175175
* newAdd?: boolean
176176
* })[]} jsdocTags
177177
* @param {import('../iterateJsdoc.js').Integer} indexAtFunctionParams
178-
* @returns {import('../iterateJsdoc.js').Integer}
178+
* @returns {{
179+
* foundIndex: import('../iterateJsdoc.js').Integer,
180+
* tagLineCount: import('../iterateJsdoc.js').Integer,
181+
* }}
179182
*/
180183
const findExpectedIndex = (jsdocTags, indexAtFunctionParams) => {
181184
const remainingRoots = functionParameterNames.slice(indexAtFunctionParams || 0);
@@ -225,7 +228,10 @@ export default iterateJsdoc(({
225228
}
226229
}
227230

228-
return tagLineCount;
231+
return {
232+
foundIndex,
233+
tagLineCount,
234+
};
229235
};
230236

231237
let [
@@ -486,8 +492,22 @@ export default iterateJsdoc(({
486492
if (remove) {
487493
createTokens(functionParameterIdx, offset + functionParameterIdx, 1);
488494
} else {
489-
const expectedIdx = findExpectedIndex(jsdoc.tags, functionParameterIdx);
490-
createTokens(expectedIdx, offset + expectedIdx, 0);
495+
const {
496+
foundIndex,
497+
tagLineCount: expectedIdx,
498+
} =
499+
findExpectedIndex(jsdoc.tags, functionParameterIdx);
500+
501+
const firstParamLine = jsdoc.source.findIndex(({
502+
tokens,
503+
}) => {
504+
return tokens.tag === `@${preferredTagName}`;
505+
});
506+
const baseOffset = foundIndex > -1 || firstParamLine === -1 ?
507+
offset :
508+
firstParamLine;
509+
510+
createTokens(expectedIdx, baseOffset + expectedIdx, 0);
491511
}
492512
};
493513

0 commit comments

Comments
 (0)