Skip to content

Commit

Permalink
feat(check-param-names): check TSMethodSignature (as on interface…
Browse files Browse the repository at this point in the history
… methods); fixes #1249
  • Loading branch information
brettz9 committed Jun 26, 2024
1 parent 1aa3313 commit 49400e1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/rules/check-param-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,14 @@ function quux (foo) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"disableMissingParamChecks":true}]
// Message: @param "bar" does not match an existing function parameter.

export interface B {
/**
* @param paramA Something something
*/
methodB(paramB: string): void
};
// Message: Expected @param names to be "paramB". Got "paramA".
````


Expand Down
5 changes: 5 additions & 0 deletions src/rules/checkParamNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ export default iterateJsdoc(({
targetTagName, allowExtraTrailingParamDocs, jsdocParameterNamesDeep, jsdoc, report,
);
}, {
contextDefaults: [
'ArrowFunctionExpression', 'FunctionDeclaration', 'FunctionExpression', 'TSDeclareFunction',
// Add this to above defaults
'TSMethodSignature'
],
meta: {
docs: {
description: 'Ensures that parameter names in JSDoc match those in the function declaration.',
Expand Down
20 changes: 20 additions & 0 deletions test/rules/assertions/checkParamNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,26 @@ export default {
},
],
},
{
code: `
export interface B {
/**
* @param paramA Something something
*/
methodB(paramB: string): void
};
`,
errors: [
{
line: 4,
message: 'Expected @param names to be "paramB". Got "paramA".',
},
],
languageOptions: {
parser: typescriptEslintParser,
sourceType: 'module',
},
}
],
valid: [
{
Expand Down

0 comments on commit 49400e1

Please sign in to comment.