Skip to content

Commit

Permalink
fix(require-param): skip this parameter in checks (when followed …
Browse files Browse the repository at this point in the history
…by destructured content); fixes #1190
  • Loading branch information
brettz9 committed Jan 24, 2024
1 parent 7461e01 commit 0cd761b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
10 changes: 10 additions & 0 deletions docs/rules/require-jsdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,16 @@ export class MyClass {
export const Comp = observer(() => <>Hello</>);
// "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}}]
// Message: Missing JSDoc comment.

/**
* Command options for the login command
*/
export type LoginOptions = CmdOptions<{
username?: string;
password?: string;
}>;
// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"ancestorsOnly":true},"contexts":["TSTypeAliasDeclaration","TSInterfaceDeclaration","TSMethodSignature","TSPropertySignature"]}]
// Message: Missing JSDoc comment.
````


Expand Down
11 changes: 11 additions & 0 deletions docs/rules/require-param.md
Original file line number Diff line number Diff line change
Expand Up @@ -1832,5 +1832,16 @@ function foo(this: T, bar: number): number {
/** {@link someOtherval} */
function a (b) {}
// "jsdoc/require-param": ["error"|"warn", {"contexts":[{"comment":"*:not(JsdocBlock:has(JsdocInlineTag[tag=link]))","context":"FunctionDeclaration"}]}]

/**
* Returns the sum of two numbers
* @param options Object to destructure
* @param options.a First value
* @param options.b Second value
* @returns Sum of a and b
*/
function sumDestructure(this: unknown, { a, b }: { a: number, b: number }) {
return a + b;
}
````

6 changes: 4 additions & 2 deletions src/rules/requireParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,16 @@ export default iterateJsdoc(({
...unnamedRootBase,
], autoIncrementBase);

const thisOffset = functionParameterNames[0] === 'this' ? 1 : 0;

for (const [
functionParameterIdx,
functionParameterName,
] of functionParameterNames.entries()) {
let inc;
if (Array.isArray(functionParameterName)) {
const matchedJsdoc = shallowJsdocParameterNames[functionParameterIdx] ||
jsdocParameterNames[functionParameterIdx];
const matchedJsdoc = shallowJsdocParameterNames[functionParameterIdx - thisOffset] ||
jsdocParameterNames[functionParameterIdx - thisOffset];

/** @type {string} */
let rootName;
Expand Down
17 changes: 17 additions & 0 deletions test/rules/assertions/requireParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -3640,5 +3640,22 @@ export default {
},
],
},
{
code: `
/**
* Returns the sum of two numbers
* @param options Object to destructure
* @param options.a First value
* @param options.b Second value
* @returns Sum of a and b
*/
function sumDestructure(this: unknown, { a, b }: { a: number, b: number }) {
return a + b;
}
`,
languageOptions: {
parser: typescriptEslintParser,
},
},
],
};

0 comments on commit 0cd761b

Please sign in to comment.