Skip to content

Commit 6d8f028

Browse files
committed
fix(require-param): ensure all structures with interfaces do not trigger with interfaceExemptsParamsCheck: true
1 parent 2018ed0 commit 6d8f028

File tree

5 files changed

+55
-17
lines changed

5 files changed

+55
-17
lines changed

docs/rules/require-param.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,5 +1998,16 @@ function quux ({
19981998
}: FunctionInterface) {
19991999
}
20002000
// "jsdoc/require-param": ["error"|"warn", {"interfaceExemptsParamsCheck":true}]
2001+
2002+
/**
2003+
*
2004+
*/
2005+
export async function fetchMarketstackEOD(
2006+
parameters: FetchEODParameters,
2007+
): Promise<MarketstackDataPoint[]>
2008+
{
2009+
// ...
2010+
};
2011+
// "jsdoc/require-param": ["error"|"warn", {"interfaceExemptsParamsCheck":true}]
20012012
````
20022013

src/iterateJsdoc.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ import esquery from 'esquery';
257257
/**
258258
* @callback GetFunctionParameterNames
259259
* @param {boolean} [useDefaultObjectProperties]
260+
* @param {boolean} [ignoreInterfacedParameters]
260261
* @returns {import('./jsdocUtils.js').ParamNameInfo[]}
261262
*/
262263

@@ -1369,8 +1370,8 @@ const getUtils = (
13691370
utils.flattenRoots = jsdocUtils.flattenRoots;
13701371

13711372
/** @type {GetFunctionParameterNames} */
1372-
utils.getFunctionParameterNames = (useDefaultObjectProperties) => {
1373-
return jsdocUtils.getFunctionParameterNames(node, useDefaultObjectProperties);
1373+
utils.getFunctionParameterNames = (useDefaultObjectProperties, ignoreInterfacedParameters) => {
1374+
return jsdocUtils.getFunctionParameterNames(node, useDefaultObjectProperties, ignoreInterfacedParameters);
13741375
};
13751376

13761377
/** @type {HasParams} */

src/jsdocUtils.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,12 @@ const getPropertiesFromPropertySignature = (propSignature) => {
203203
/**
204204
* @param {ESTreeOrTypeScriptNode|null} functionNode
205205
* @param {boolean} [checkDefaultObjects]
206+
* @param {boolean} [ignoreInterfacedParameters]
206207
* @throws {Error}
207208
* @returns {ParamNameInfo[]}
208209
*/
209210
const getFunctionParameterNames = (
210-
functionNode, checkDefaultObjects,
211+
functionNode, checkDefaultObjects, ignoreInterfacedParameters,
211212
) => {
212213
/* eslint-disable complexity -- Temporary */
213214
/**
@@ -230,6 +231,19 @@ const getFunctionParameterNames = (
230231
const hasLeftTypeAnnotation = 'left' in param && 'typeAnnotation' in param.left;
231232

232233
if ('typeAnnotation' in param || hasLeftTypeAnnotation) {
234+
if (ignoreInterfacedParameters && 'typeAnnotation' in param &&
235+
param.typeAnnotation) {
236+
// No-op
237+
return [
238+
undefined, {
239+
hasPropertyRest: false,
240+
hasRestElement: false,
241+
names: [],
242+
rests: [],
243+
},
244+
];
245+
}
246+
233247
const typeAnnotation = hasLeftTypeAnnotation ?
234248
/** @type {import('@typescript-eslint/types').TSESTree.Identifier} */ (
235249
param.left

src/rules/requireParam.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,10 @@ export default iterateJsdoc(({
6565
useDefaultObjectProperties = false,
6666
} = context.options[0] || {};
6767

68-
if (interfaceExemptsParamsCheck) {
69-
if (node && 'params' in node && node.params.length === 1 &&
70-
node.params?.[0] && typeof node.params[0] === 'object' &&
71-
node.params[0].type === 'ObjectPattern' &&
72-
'typeAnnotation' in node.params[0] && node.params[0].typeAnnotation
73-
) {
74-
return;
75-
}
76-
77-
if (node && node.parent?.type === 'VariableDeclarator' &&
78-
'typeAnnotation' in node.parent.id && node.parent.id.typeAnnotation) {
79-
return;
80-
}
68+
if (interfaceExemptsParamsCheck && node &&
69+
node.parent?.type === 'VariableDeclarator' &&
70+
'typeAnnotation' in node.parent.id && node.parent.id.typeAnnotation) {
71+
return;
8172
}
8273

8374
const preferredTagName = /** @type {string} */ (utils.getPreferredTagName({
@@ -87,7 +78,7 @@ export default iterateJsdoc(({
8778
return;
8879
}
8980

90-
const functionParameterNames = utils.getFunctionParameterNames(useDefaultObjectProperties);
81+
const functionParameterNames = utils.getFunctionParameterNames(useDefaultObjectProperties, interfaceExemptsParamsCheck);
9182
if (!functionParameterNames.length) {
9283
return;
9384
}

test/rules/assertions/requireParam.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3953,5 +3953,26 @@ export default /** @type {import('../index.js').TestCases} */ ({
39533953
},
39543954
],
39553955
},
3956+
{
3957+
code: `
3958+
/**
3959+
*
3960+
*/
3961+
export async function fetchMarketstackEOD(
3962+
parameters: FetchEODParameters,
3963+
): Promise<MarketstackDataPoint[]>
3964+
{
3965+
// ...
3966+
};
3967+
`,
3968+
languageOptions: {
3969+
parser: typescriptEslintParser,
3970+
},
3971+
options: [
3972+
{
3973+
interfaceExemptsParamsCheck: true,
3974+
},
3975+
],
3976+
},
39563977
],
39573978
});

0 commit comments

Comments
 (0)