Skip to content

Commit

Permalink
fix(require-param): proper errors/fixing for succeeding destructure…
Browse files Browse the repository at this point in the history
…d objects; fixes gajus#762
  • Loading branch information
brettz9 committed Jul 5, 2024
1 parent 6371c4a commit 394b85f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 7 deletions.
24 changes: 24 additions & 0 deletions docs/rules/check-param-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,22 @@ export interface B {
methodB(paramB: string): void
};
// Message: Expected @param names to be "paramB". Got "paramA".

interface A {
/**
* @param params Values for the placeholders
*/
getText(key: string, ...params: string[]): string
}
// Message: Expected @param names to be "key, ...params". Got "params".

/**
* @param arg Arg
*/
export function fn(...[type, arg]: FnArgs): void {
// ...
}
// Message: Expected @param name to be "type". Got "arg".
````


Expand Down Expand Up @@ -1095,5 +1111,13 @@ function quux (foo, bar) {
function quux (foo, bar) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"disableMissingParamChecks":true}]

/**
* @param type Type
* @param arg Arg
*/
export function fn(...[type, arg]: FnArgs): void {
// ...
}
````

11 changes: 11 additions & 0 deletions docs/rules/require-param.md
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,17 @@ class A {
}
// "jsdoc/require-param": ["error"|"warn", {"contexts":["MethodDefinition"]}]
// Message: Missing JSDoc @param "btnState" declaration.

class A {
/**
* @param root0
* @param root0.foo
*/
quux({ foo }, { bar }) {
console.log(foo, bar);
}
}
// Message: Missing JSDoc @param "root1" declaration.
````


Expand Down
14 changes: 7 additions & 7 deletions src/rules/requireParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ export default iterateJsdoc(({
functionParameterIdx,
functionParameterName,
] of functionParameterNames.entries()) {

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

/** @type {string} */
let rootName;
Expand All @@ -237,12 +237,12 @@ export default iterateJsdoc(({
} else {
rootName = nextRootName;
inc = incremented;
[
nextRootName,
incremented,
namer,
] = namer();
}
[
nextRootName,
incremented,
namer,
] = namer();

const {
hasRestElement,
Expand Down
34 changes: 34 additions & 0 deletions test/rules/assertions/requireParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -2493,6 +2493,40 @@ export default {
parser: typescriptEslintParser
},
},
{
code: `
class A {
/**
* @param root0
* @param root0.foo
*/
quux({ foo }, { bar }) {
console.log(foo, bar);
}
}
`,
errors: [
{
message: 'Missing JSDoc @param "root1" declaration.',
},
{
message: 'Missing JSDoc @param "root1.bar" declaration.',
}
],
output: `
class A {
/**
* @param root0
* @param root0.foo
* @param root1
* @param root1.bar
*/
quux({ foo }, { bar }) {
console.log(foo, bar);
}
}
`,
},
],
valid: [
{
Expand Down

0 comments on commit 394b85f

Please sign in to comment.