Open desandro opened 2 years ago
Totally understand - this rule annoys me more than any other. But, it annoys me to get me to do some documentation I should have done to begin with. Short of going to typescript, I find it helpful to document parameters and the types of data they are expecting.
Do you have any thoughts on how we might approach documentation and/or encourage the team towards documentation without this?
TEAM KEEEEEP
Team keep IF we can customise the rules. Please show me how to turn off some stuff like return π
I like having something that pesters me to add documentation, but I would like to relax the rules. For example, sometimes param or return descriptions can be redundant and not all that useful, and you can turn those off with requireParamDescription
and requireReturnDescription
I personally don't like the required parameters part of this.
But, I agree with Sandy that if it's a contentious issue, that means we should keep it.
per @nerdpruitt:
I like having something that pesters me to add documentation
I agree. Interestingly, having strict rules here doesn't mean that you add accurate or meaningful documentation. Sometimes a simple "psst, don't forget to document this for future you and your teammates" is probably the best thing we're trying to achieve here.
For me, knowing the type of data expected is helpful. I guess that's why typescript has really taken off, but I don't want that level of forced conformity, so forcing it here feels maybe like the wrong thing.
I don't want to use Ashur's words in a way he might not have intended, but I do think having a team culture of documenting is a good thing. I've been too lax there in the past β just trying to move fast, thinking how I write things is plenty self-documenting, deadlines, etc β and we can see how that has made it harder for people to get up to speed.
tl;dr β I think tooling that enforces some kind of documentation is important as part of our collective code building; whether that's require-jsdoc
, or something else that helps us maintain what I see as benefits of documentation, I'm game.
Note β This is primarily in reference to non-TypeScript projects βΊοΈ
Things I really appreciate from documented code:
JSDoc is a little goofy and maybe kind of old, but it has a nice, cross-language history and lots of native support in tooling.
JSDoc supports a ton of properties, but my ideal block looks something like this:
/**
* Shortest possible summary of what the function does
* @param {type} name - optional summary where warranted; use your best judgment
* @return {type}
*/
/**
* Shortest possible summary of what the function does
Helps me understand what the function does without having to read and interpret the code. Sometimes I'm just perusing things rather than using them (reading utility functions, filters, shortcodes, etc.) just to familiarize myself with a codebase.
This can feel redundant for very simple functions. I definitely get that! My personal opinion is to trust your best judgment βΒ can the next developer who looks at your code:
understand what it does just by reading the function name and its signature?
function addTwoNumbers(a, b) {
If so, then maybe a summary is OK to skip π
Note β This is an important part of populating editor autocompletion
@param {type} name [- optional summary]
In short, what does this function expect me to pass along when I call it?
Data types are particularly important to me here: I can read through the code to figure out that foo
could be a string, or an Object, or an instance of Foo
, but it's a lot faster and more reliable to see it documented all in one spot:
@param {string|Object|Foo} foo
(In many, many cases, the variable name is self-documenting. In that case, I think it makes a lot of sense to skip the summary!)
Note β This also helps populate editor autocompletion
* @return {type}
*/
What should I expect when I call this function? An array? A Promise
I need to await
? Nothing at all?
Again, this is something you can glean from reading over the code, but (in my opinion) relying on that exclusively would tend to decelerate our overall velocity rather than accelerate it.
I have two snippets in my text editor to make building out a JSDoc block quick and easy:
/**
β
/**
* @param {type} name
* @return {type}
*/
and @param
β
@param {type} name
to quickly add additional @param
entries.
TODO Sandy - add writing JSDocs to the UXE Styleguide
End-of-Life for Built-in JSDoc Support in ESLint
I recommend removing
require-jsdoc
all together. I find it more a nuisance than useful. If we do want JS Doc stuff, then we can add it back with eslint-plugin-jsdoc