-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add eslint-plugin-jsdoc for better JSDoc linting #16869
Conversation
Some things to note1. There is still some discrepancy with respect to how arrays are documented using the long format.For example... /**
* @param {Array.<string>} foo
*/
// vs
/**
* @param {Array<string>} foo
*/ As far as typescript is concerned, only the second format is legal (to my knowledge). It appears that this can be enforced rather simply for arrays, but I'm not sure if you'd also have to add in all other potential uses of this as well (which could get long for other globals (e.g. 2. I didn't check uses of
|
3259970
to
0fe3391
Compare
Note: I rebased from master after #16870 merged. So now this PR should be good to merge/review. |
Testing this PR currently: Running the following tasks passed without issue: • As there are no regressions in testing existing The 1-4 points listed in the above comments should be addressed in follow up issues and pull requests as required. |
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.
Fantastic work @dsifford, thanks a bunch 💐
}, | ||
requireParamDescription: false, | ||
requireReturn: false, | ||
} ], | ||
'valid-typeof': 'error', |
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.
Does it mean that es5
config will no longer validate JSDoc comments?
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.
Correct. If that's the intention also, you'd have to have es5.js extend
jsdoc.js (and then probably remove jsdoc.js from the top-level, since it already imports es5.js there).
Good catch.
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.
Based on the previous implementation and knowing that sometimes we want to explicitly use ES5 I guess you are all correct.
* feat(eslint-plugin): add eslint-plugin-jsdoc for improved jsdoc linting * chore: fix all JSDoc eslint errors/warnings across the entire repository
* feat(eslint-plugin): add eslint-plugin-jsdoc for improved jsdoc linting * chore: fix all JSDoc eslint errors/warnings across the entire repository
}, | ||
}, | ||
rules: { | ||
'jsdoc/no-undefined-types': [ 'warning', { |
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.
Is there any desire or intention to eventually increase this severity to "error" ? I understand there's a number of existing issues which would need to be resolved first, but my experience with "warning" is that they're often overlooked (in many cases by lack of installed tooling on the part of new contributors) and that the number of issues present can still trend upward.
(Noting this also applies to every rule defined in jsdoc/recommended
)
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.
I brought the number to 0 last week, it's up to 2 now. We should enforce the error
level everywhere even if this requires a major version update for the plugin.
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.
For tracking, I created an issue at #18458
preferType: { | ||
array: 'Array', | ||
bool: 'boolean', | ||
Boolean: 'boolean', |
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.
Did we lose most of these preferred types and tags with the transition? I only see "Object" type being enforced in the current configuration, and return
and yield
tags:
gutenberg/packages/eslint-plugin/configs/jsdoc.js
Lines 72 to 78 in da54d11
preferredTypes: { | |
object: 'Object', | |
}, | |
tagNamePreference: { | |
returns: 'return', | |
yields: 'yield', | |
}, |
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 something I did?
I may have deleted those that were set to the default value. Hindsight, that may have been wrong because doing that may have loosened the enforcement.
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.
Hm, I guess it may work just as well still. I haven't tested all of the previous values, but I do see a warning (as expected) when trying to capitalize a {String}
type.
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.
Description
This PR is the first part of adding typescript type checking in JS files to the project. This was discussed rather exhaustively in slack, so I'll spare you all the regurgitation of that discussion.
Per @aduth, I'm going to cherry pick the second commit with all the lint fixes and PR that separately so that this PR will be more easily reviewable.
In the meantime, just focus your attention on the first commit.
How has this been tested?
Eslint runs successfully and all errors/warnings that turned up after applying the new plugin were addressed in the second commit. There are no more warnings/errors.
Screenshots
N/A
Types of changes
Build Tooling
Checklist:
Closes #13741
Related: https://make.wordpress.org/core/2019/08/01/javascript-chat-summary-july-30-2019/