-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Increase severity of JSDoc to error. #20427
Conversation
I'll leave the decision to @aduth as he has more skin in the game than I do here. |
I've not yet had time to review this in detail, but I'm of course happy to see these warnings bumped to errors. What I'm not sure about on a cursory glance is whether we want to be changing the existing types to |
d551594
to
2123cac
Compare
Rebased. |
@sainthkh What do you think about my remarks at #20427 (comment) ? I'm not entirely comfortable with the changes to use |
I used Record because adding After reading your comment and related code, I agree that restoring But I don't think These are my opinion. The downside is that it is not consistent. If you think |
2123cac
to
b0b0d95
Compare
407ea5c
to
72dd0ba
Compare
Rebased. |
I think it would depend. In this very specific case, you're right that Consider this example: In that case, That said, since we are talking about this specific case, I think it would be fine to use This section of the current documentation is quite relevant, and might need to be updated accordingly: |
I'm trying to understand what the specific difference is between Related: https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkt I have experienced in the past that TypeScript has a tendency to treat |
In TypeScript, [ And according to JSDoc doc, the correct way to specifying types is One difference between interface X {
[x: symbol]: string // error
}
let a: Record<symbol, number> = {} // ok But I guess it doesn't matter much. Because |
My proposal:
|
That seems sensible to me. Would you want to include those documentation changes here as well? |
Yes. I think that's the part of this update. |
72dd0ba
to
ea372c7
Compare
73560e0
to
253a904
Compare
Question:
|
These are good questions, especially considering that the document is pretty unambiguous in calling them "Incorrect" (to clarify, I'm the one who wrote it this way). At least speaking from my own experience, I've not always been successful in following these rules so strictly, and I don't know that we want to put many barriers in place which might dissuade people from using types. At the same time, we should want to encourage people as much as possible to use the best options available to them. Some of these are easier to adopt than others. So to specifically answer your question:
I think any or all of these could change over time as we continue to explore how to implement types in the codebase. I'm also open to arguments to the contrary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good!
One last thing I see is that the Coding Guidelines document still has quite a few references to Object
types throughout. Should these be updated to Record
, at least when used as a generic?
Related to my previous comment, there are also some interesting cases where it's not so clear what the best type would be. Notably, for React function components, how best should we document the props
argument.
For example:
/**
* Renders a toolbar.
*
* @param {Object} props Component props.
* @param {string} [props.className] Class to set on the container `<div />`.
*/
Is {Object}
okay here? Is it something where we want to try to use the "indexable interface" format for describing the keys of the props
object (I don't know that this is feasible since, unlike TypeScript, we're confined to describing the type in a single line)? I had wondered if the props
@param
line even provides any value, vs. just omitting and including only the specific properties. Last time I tried that, I think there were some errors related to the missing props
documentation.
1.
If we're using TypeScript, the type of 2.
It seems that we have no other option for now. /**
*
* @param {number} x xx
* @param {number} y yy
*/
export const x = ( { x, y } ) => {
return x + y;
}; When we write a simple function like above, TypeScript type checker will show us this error message:
3.
I think there's not much difference. And we all know that it's a React function by its name starting with a capital case. This is not a dictionary-like object that we want to add/remove elements on the run time. In addition, we don't need more 4. I checked the guideline and
It seems that nothing should be changed. 5. The best to way to enforce types is to migrate to TS and use But like eslint warnings, when types aren't enforced, people ignore them. Maybe we need to discuss it later. (I know you had a meeting about TypeScript. And I also know that it can't be a priority now.) |
In your example, I sense the individual properties would still need to include some object name in order to use the dot notation: https://jsdoc.app/tags-param.html#parameters-with-properties I was hoping it would work with just an arbitrary name (props, for a function component): /**
* Returns a person's name.
*
* @type {import('react').FC}
*
* @param {string} props.name Person name.
*/
function Person( { name } ) {
return <div>{ name }</div>;
} But the ESLint rule doesn't like it:
Are you referring to this one? /**
* A block selection object.
*
* @typedef {Object} WPBlockSelection
*
* @property {string} clientId A block client ID.
* @property {string} attributeKey A block attribute key.
* @property {number} offset An attribute value offset, based on the rich
* text value.
*/ If I recall correctly, we can remove
Which is this referring to?
What about this one
Should this be
There's definitely a desire to enforce types inferred from JSDoc. See #18838. It's already in place for a handful of modules. It's not quite to the same extent as going full TypeScript, but it is enforced where modules have been opted-in, and I'm highly in favor of more modules to be enabled. To summarize, the only points above that I think need some decision or action:
|
The key name, setting, is meaningful.
I'm sorry. I searched
Yes. eslint and tsc don't complain about this. And
Yes.
This one below: /**
* Renders a toolbar.
*
* @param {Object} props Component props.
* @param {string} [props.className] Class to set on the container `<div />`.
*/ I experimented if we can remove It seems that everything is OK. I'll go fix the coding guideline. |
37be2e9
to
61d7f13
Compare
61d7f13
to
ed598cd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work here, and for your patience and well-reasoned thoughts during the many iterations. This looks good to land now 🎉
Description
eslint-plugin-jsdoc
from 15.8.0 to 21.0.0.How has this been tested?
npm run lint-js
command will not show anywarning
s.Notes about decisions
AS it is written in #18458, eslint-plugin-jsdoc cannot parse some TypeScript types like
[key:string]: any
. So, I fixed the issues like these:[key:string]: any
: Mostly,Record<string, any>
/* eslint-disable */
,/* eslint-enable */
pair. Unfortunately, as JSDoc is written in comment,// eslint-disable-line
doesn't work.Screenshots
N/A
Types of changes
Minor JSDoc comment changes.
Checklist: