Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check @param names in JSDoc method documentation #11378

Closed
friflo opened this issue Oct 5, 2016 · 8 comments · Fixed by #47257
Closed

Check @param names in JSDoc method documentation #11378

friflo opened this issue Oct 5, 2016 · 8 comments · Fixed by #47257
Labels
Committed The team has roadmapped this issue Domain: JSDoc Relates to JSDoc parsing and type generation Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this Suggestion An idea for TypeScript VS Code Tracked There is a VS Code equivalent to this issue
Milestone

Comments

@friflo
Copy link

friflo commented Oct 5, 2016

JSDoc applied to methods tend to age. Typically method parameters are added / removed / changed but their documentation remain unchanged.

Typescript compiler should check the @param names and should write an error, if they are not found in the method signature. Maybe this check should be optional, by a compiler flag.

TypeScript Version: (2.0.3)

Code

class TestValidateJSDocParams {
    /** Calculate the sum of the given numbers
     * @param x     first summand
     * @param y     second summand
     * @param z     third summand
     */
    public sum (a: number, b: number) : number {
        return a + b;
    }
}

Expected behavior:
Should log an tsc compiler error for unknown methods parameters: x, y, z

Actual behavior:
Compiles without an error.

@kitsonk
Copy link
Contributor

kitsonk commented Oct 5, 2016

My personal opinion is that this would be a great linter feature in something like tslint.

@mhegazy mhegazy added Suggestion An idea for TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation labels Dec 15, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Dec 15, 2016

@kitsonk, while i agree with you in a .ts file, in a .js file we already use the JSDoc comments for type information. the function in the OP, would not be typed correctly as we did not find the documentation for parameter a; so seems like a nice error to show to avoid such situations.

@RyanCavanaugh, we should consider doing this as part of #6802. make JSDoc errors a category by their own. we today swallow all these errors.

@mhegazy mhegazy added the VS Code Tracked There is a VS Code equivalent to this issue label Dec 20, 2016
@brettz9
Copy link

brettz9 commented Jul 3, 2018

Did #18777 address this? If not, should #15852 subsume this issue?

@sandersn
Copy link
Member

@brettz9 #18777 fixes this bug, but only for Javascript, where we use jsdoc for typing. It still feels like a lint feature in Typescript.

@sandersn
Copy link
Member

sandersn commented May 20, 2019

Now that we have info-level diagnostics with codefixes, we could do it that way. Accepting PRs for this one.

This one is a good bit of work, but it's all based on existing code. You'll just have to

  1. Give the jsdoc-mismatch error in TS as well, but as an info.
  2. Copy the structure of an existing codefix to change the param name.
  3. Decide how to fix the error. Do you match by position? By levenshtein distance? Do you default to changing the jsdoc? The parameter? Do you offer to reorder the jsdoc or the parameters?

Make sure the codefix works in JS too!

@sandersn sandersn added Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this labels May 20, 2019
@Kingwl
Copy link
Contributor

Kingwl commented Jul 17, 2019

I'd like to have a try on it

@sandersn
Copy link
Member

OK, I assigned you to the issue, @Kingwl. Unassign yourself if you decide not to do this.

@Kingwl
Copy link
Contributor

Kingwl commented Feb 22, 2021

Oh. Sorry. I forget this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Committed The team has roadmapped this issue Domain: JSDoc Relates to JSDoc parsing and type generation Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this Suggestion An idea for TypeScript VS Code Tracked There is a VS Code equivalent to this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants