Skip to content

Commit 394b85f

Browse files
committed
fix(require-param): proper errors/fixing for succeeding destructured objects; fixes #762
1 parent 6371c4a commit 394b85f

File tree

4 files changed

+76
-7
lines changed

4 files changed

+76
-7
lines changed

docs/rules/check-param-names.md

+24
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,22 @@ export interface B {
665665
methodB(paramB: string): void
666666
};
667667
// Message: Expected @param names to be "paramB". Got "paramA".
668+
669+
interface A {
670+
/**
671+
* @param params Values for the placeholders
672+
*/
673+
getText(key: string, ...params: string[]): string
674+
}
675+
// Message: Expected @param names to be "key, ...params". Got "params".
676+
677+
/**
678+
* @param arg Arg
679+
*/
680+
export function fn(...[type, arg]: FnArgs): void {
681+
// ...
682+
}
683+
// Message: Expected @param name to be "type". Got "arg".
668684
````
669685

670686

@@ -1095,5 +1111,13 @@ function quux (foo, bar) {
10951111
function quux (foo, bar) {
10961112
}
10971113
// "jsdoc/check-param-names": ["error"|"warn", {"disableMissingParamChecks":true}]
1114+
1115+
/**
1116+
* @param type Type
1117+
* @param arg Arg
1118+
*/
1119+
export function fn(...[type, arg]: FnArgs): void {
1120+
// ...
1121+
}
10981122
````
10991123

docs/rules/require-param.md

+11
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,17 @@ class A {
11511151
}
11521152
// "jsdoc/require-param": ["error"|"warn", {"contexts":["MethodDefinition"]}]
11531153
// Message: Missing JSDoc @param "btnState" declaration.
1154+
1155+
class A {
1156+
/**
1157+
* @param root0
1158+
* @param root0.foo
1159+
*/
1160+
quux({ foo }, { bar }) {
1161+
console.log(foo, bar);
1162+
}
1163+
}
1164+
// Message: Missing JSDoc @param "root1" declaration.
11541165
````
11551166

11561167

src/rules/requireParam.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,10 @@ export default iterateJsdoc(({
220220
functionParameterIdx,
221221
functionParameterName,
222222
] of functionParameterNames.entries()) {
223+
223224
let inc;
224225
if (Array.isArray(functionParameterName)) {
225-
const matchedJsdoc = shallowJsdocParameterNames[functionParameterIdx - thisOffset] ||
226-
jsdocParameterNames[functionParameterIdx - thisOffset];
226+
const matchedJsdoc = shallowJsdocParameterNames[functionParameterIdx - thisOffset];
227227

228228
/** @type {string} */
229229
let rootName;
@@ -237,12 +237,12 @@ export default iterateJsdoc(({
237237
} else {
238238
rootName = nextRootName;
239239
inc = incremented;
240-
[
241-
nextRootName,
242-
incremented,
243-
namer,
244-
] = namer();
245240
}
241+
[
242+
nextRootName,
243+
incremented,
244+
namer,
245+
] = namer();
246246

247247
const {
248248
hasRestElement,

test/rules/assertions/requireParam.js

+34
Original file line numberDiff line numberDiff line change
@@ -2493,6 +2493,40 @@ export default {
24932493
parser: typescriptEslintParser
24942494
},
24952495
},
2496+
{
2497+
code: `
2498+
class A {
2499+
/**
2500+
* @param root0
2501+
* @param root0.foo
2502+
*/
2503+
quux({ foo }, { bar }) {
2504+
console.log(foo, bar);
2505+
}
2506+
}
2507+
`,
2508+
errors: [
2509+
{
2510+
message: 'Missing JSDoc @param "root1" declaration.',
2511+
},
2512+
{
2513+
message: 'Missing JSDoc @param "root1.bar" declaration.',
2514+
}
2515+
],
2516+
output: `
2517+
class A {
2518+
/**
2519+
* @param root0
2520+
* @param root0.foo
2521+
* @param root1
2522+
* @param root1.bar
2523+
*/
2524+
quux({ foo }, { bar }) {
2525+
console.log(foo, bar);
2526+
}
2527+
}
2528+
`,
2529+
},
24962530
],
24972531
valid: [
24982532
{

0 commit comments

Comments
 (0)