Open scinos opened 2 years ago
I've been looking at the lint rules related to JSDoc params, and I think there is room for improvement.
Given that we don't generate external docs from the source code, and I assume that most devs use VSCode (or an editor with very similar features regarding code intellisense), I based this analysis on the usefulness of JSDoc @param
for VSCode in two scenarios: code intellisense when typing and when mouse hover the function.
With no @param
documented
On hover | On type |
---|---|
![]() |
![]() |
Note how VSCode correctly infers the parameters name and types them as any
.
With just @param <name> |
On hover | On type |
---|---|---|
![]() |
![]() |
Intellisense when typing is exactly the same. On hover it adds the parameter names after the function description, but that info was already visible in the function signature.
With @param <type> <name> |
On hover | On type |
---|---|---|
![]() |
![]() |
Now it shows the types in the function signature in both cases, but it doesn't in param list after the function description
With @param <type> <name> <description> |
On hover | On type |
---|---|---|
![]() |
![]() |
Shows the description in both cases.
Given the results above, I think adding just @param <name>
doesn't provide any value. As such, I think we should disable jsdoc/require-param
but keep jsdoc/check-param-names
(don't force adding @param
, but if a @param
is present, ensure it matches the actual param name).
Enforcing param description is also counter productive. In many cases the param information is available in the function description, can be easily inferred by the name or there is simply no relevant description. Enforcing it will likely cause lots of useless @param <string> id - The id
The same applies to jsdoc/require-returns-description
Now only @param <type> <name>
is left. We can enforce it by enabling jsdoc/require-param-type
. While arguably it adds some value, the reality is we'll have lots errors (348 errors) if we enable it. Fixing them is not a trivial task.
Type checks won't be enforced (at least my VSCode config ignores any type discrepancy). Given that we already have infrastructure in place to transpile TypeScript in most packages (example: client/
is already a TypeScript + JavaScript project), if we think types are important enough to be mandatory, maybe we should convert those files to TypeScript.
In short, I propose:
jsdoc/require-param
jsdoc/require-returns-description
jsdoc/require-param-description
jsdoc/no-undefined-types
jsdoc/check-param-names
For me personally, I only find useful the rules that say "I was able to detect there's something obviously wrong about your jsdoc comment", ones that enforce some consistency, like newline between description and params or {boolean}
and {String}
type names over {bool}
and {string}
.
On the other hand, rules that say "you need to fill in this required information" mostly lead to jsdoc comments that are repetitive, like:
/**
* Function that converts dogs to cats
*
* @param {Dog} dog the dog
* @returns {Cat} cat the cat
*/
function dogToCat( dog ) {
/* ... */
return cat;
}
where the jsdoc comment doesn't really say anything new.
This anti-pattern is very common in our Redux code where we are forced to document action creators as:
/**
* @returns {Action} an action object to be dispatched
*/
or reducers as:
/**
* @param state The original state
* @param action An action object
* @returns Updated state
*/
I would be better if the linter let the author decide what's worth documenting and let them omit the parts that are obvious.
I don't have much to add, but I agree with your logic and the proposal to change these rules.
If one wants great type analysis for a JS function, I think we should be encouraging them to re-write in TS rather than jsdoc. I guess it's even possible that jsdoc gives a false sense of security that types are checked by something before deploy.
@scinos I'm excited to see such great use of eslint-nibble, and I hope it's been helpful. Let me know if you have any suggestions or requests for it.
Details
Current list of errors (updated to commit 6a130575c5759ba153f1310e9de36cb4629a19a4)
Fixed errors
These errors have been already fixed. The list is here for documentation purposes:
Checklist
No response
Related
No response