Skip to content

Commit 0cd761b

Browse files
committed
fix(require-param): skip this parameter in checks (when followed by destructured content); fixes #1190
1 parent 7461e01 commit 0cd761b

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

docs/rules/require-jsdoc.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,16 @@ export class MyClass {
10161016
export const Comp = observer(() => <>Hello</>);
10171017
// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["CallExpression[callee.name=\"observer\"]"],"enableFixer":false,"publicOnly":true,"require":{"ArrowFunctionExpression":true,"ClassDeclaration":true,"ClassExpression":true,"FunctionDeclaration":true,"FunctionExpression":true,"MethodDefinition":true}}]
10181018
// Message: Missing JSDoc comment.
1019+
1020+
/**
1021+
* Command options for the login command
1022+
*/
1023+
export type LoginOptions = CmdOptions<{
1024+
username?: string;
1025+
password?: string;
1026+
}>;
1027+
// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"ancestorsOnly":true},"contexts":["TSTypeAliasDeclaration","TSInterfaceDeclaration","TSMethodSignature","TSPropertySignature"]}]
1028+
// Message: Missing JSDoc comment.
10191029
````
10201030

10211031

docs/rules/require-param.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,5 +1832,16 @@ function foo(this: T, bar: number): number {
18321832
/** {@link someOtherval} */
18331833
function a (b) {}
18341834
// "jsdoc/require-param": ["error"|"warn", {"contexts":[{"comment":"*:not(JsdocBlock:has(JsdocInlineTag[tag=link]))","context":"FunctionDeclaration"}]}]
1835+
1836+
/**
1837+
* Returns the sum of two numbers
1838+
* @param options Object to destructure
1839+
* @param options.a First value
1840+
* @param options.b Second value
1841+
* @returns Sum of a and b
1842+
*/
1843+
function sumDestructure(this: unknown, { a, b }: { a: number, b: number }) {
1844+
return a + b;
1845+
}
18351846
````
18361847

src/rules/requireParam.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,16 @@ export default iterateJsdoc(({
214214
...unnamedRootBase,
215215
], autoIncrementBase);
216216

217+
const thisOffset = functionParameterNames[0] === 'this' ? 1 : 0;
218+
217219
for (const [
218220
functionParameterIdx,
219221
functionParameterName,
220222
] of functionParameterNames.entries()) {
221223
let inc;
222224
if (Array.isArray(functionParameterName)) {
223-
const matchedJsdoc = shallowJsdocParameterNames[functionParameterIdx] ||
224-
jsdocParameterNames[functionParameterIdx];
225+
const matchedJsdoc = shallowJsdocParameterNames[functionParameterIdx - thisOffset] ||
226+
jsdocParameterNames[functionParameterIdx - thisOffset];
225227

226228
/** @type {string} */
227229
let rootName;

test/rules/assertions/requireParam.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,5 +3640,22 @@ export default {
36403640
},
36413641
],
36423642
},
3643+
{
3644+
code: `
3645+
/**
3646+
* Returns the sum of two numbers
3647+
* @param options Object to destructure
3648+
* @param options.a First value
3649+
* @param options.b Second value
3650+
* @returns Sum of a and b
3651+
*/
3652+
function sumDestructure(this: unknown, { a, b }: { a: number, b: number }) {
3653+
return a + b;
3654+
}
3655+
`,
3656+
languageOptions: {
3657+
parser: typescriptEslintParser,
3658+
},
3659+
},
36433660
],
36443661
};

0 commit comments

Comments
 (0)