-
-
Notifications
You must be signed in to change notification settings - Fork 163
Description
If an overload of a function does not contain some parameters, but the functions which has not jsdoc below it do contain these parameters, the jsdoc of the overloaded function will incorrectly report irrelevant parameters.
Expected behavior
Nothing reported.
Actual behavior
Parameters of other functions below the overloaded function (including other overloaded functions or implementation functions) will be accidentally absorbed into the jsdoc of this function, which should not happen.
Minimal Reproduction
https://stackblitz.com/edit/stackblitz-starters-vnabrjsk?file=index.ts
ESLint Config
export default [
tseslint.configs.base,
{
files: ["**/*.{js,ts}"],
plugins: {
jsdoc,
},
rules: {
"jsdoc/require-param": "warn",
},
},
];
ESLint sample
The implement function which has no jsdoc, below the overload param-less function
Code:
/**
* Test function with param.
* @param foo - Test param.
*/
function myFunction(foo: string): void;
/**
* Test function without param.
*/
function myFunction(): void;
function myFunction(foo?: string) {}
Report:
6:1 warning Missing JSDoc @param "foo" declaration jsdoc/require-param
✖ 1 problem (0 errors, 1 warning)
0 errors and 1 warning potentially fixable with the `--fix` option.
After fixed:
/**
* Test function with param.
* @param foo - Test param.
*/
function myFunction(foo: string): void;
/**
* Test function without param.
* @param foo
*/
function myFunction(): void;
function myFunction(foo?: string) {}
Why? Where is param foo
in the overload function function myFunction(): void;
???
The implement function has jsdoc
Code:
/**
* Test function with param.
* @param foo - Test param.
*/
function myFunction(foo: string): void;
/**
* Test function without param.
*/
function myFunction(): void;
/**
* Test function with param.
* @param foo - Test param.
*/
function myFunction(foo?: string) {}
Nothing reported!
But the jsdoc for the implement function is useless, it almost same as the first overload, and TypeScript will not read it.
Move the overload param-less function above other overload functions which has jsdoc
Code:
/**
* Test function without param.
*/
function myFunction(): void;
/**
* Test function with param.
* @param foo - Test param.
*/
function myFunction(foo: string): void;
function myFunction(foo?: string) {}
Nothing reported!
Move the overload param-less function above other overload functions which has no jsdoc
Code:
/**
* Test function without param.
*/
function myFunction(): void;
function myFunction(foo: string): void;
function myFunction(foo?: string) {}
Report:
1:1 warning Missing JSDoc @param "foo" declaration jsdoc/require-param
1:1 warning Missing JSDoc @param "foo" declaration jsdoc/require-param
✖ 2 problems (0 errors, 2 warnings)
0 errors and 2 warnings potentially fixable with the `--fix` option.
I got two param foo
warnings, they come from the second overloaded function and the implementation function respectively, and have no relationship with the current overloaded function.
After fixed:
/**
* Test function without param.
* @param foo
*/
function myFunction(): void;
function myFunction(foo: string): void;
function myFunction(foo?: string) {}
Environment
- Node version: v23.6.1
- ESLint version v9.32.0
eslint-plugin-jsdoc
version: v51.4.1