Conversation
Currently, all arrow functions and function expressions are required to
be documented with JSDoc, and object types in return types are required
to documented as well.
This means:
``` typescript
// The arrow function here is now required to be documented
foo(() => {
// ...
})
foo({
// The arrow function here is now required to be documented
bar: () => {
// ...
}
})
function foo(): {
// This is now required to be documented
bar: string;
} {
// ...
}
```
This commit loosens the rules so that:
- Instead of restricting all arrow functions and function expressions,
restrict only those that are not contained within plain objects or are
not arguments to functions or methods
- Instead of restricting all interfaces or type aliases, restrict only
those that do not appear in `declare` blocks (ambient declarations)
- Instead of restricting object types in return types, restrict object
types in "root" types
|
This PR was derived directly from MetaMask/create-release-branch#168. The last changes I made to this PR tweaked the rules further. I was hoping to get another review on those changes, but assuming they are good, I planned on integrating them back into this PR. I don't have time to do this right now, but I talked with Mark and he said that he might have time. @Gudahtt If you do have time, feel free to take over this PR and get it merged. |
| - New things that now require documentation are: | ||
| - Arrow functions | ||
| - Class declarations | ||
| - TypeScript enum declarations |
There was a problem hiding this comment.
While it's true that the base config did apparently require JSDoc for TypeScript symbols, that wasn't true in practice because the JSDoc plugin within the base config doesn't know about TypeScript.
| - **BREAKING:** Update type import specifier rules ([#381](https://github.com/MetaMask/eslint-config/pull/381)) | ||
| - `@typescript-eslint/consistent-type-imports` has been replaced with `import-x/consistent-type-specifier-style` | ||
| - The rule now prefers "top-level" type imports over inline. e.g. `import type { a } from 'x'` over `import { type a } from 'x'` | ||
| - **BREAKING:** Update `jsdoc/require-jsdoc` to require documentation for more things ([#394](https://github.com/MetaMask/eslint-config/pull/394)) |
There was a problem hiding this comment.
This changelog entry was missing when 15.0.0 was released. This should list TypeScript symbols for which documentation is required (not the changelog for the base config).
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
|
|
||
| - Update `jsdoc/require-jsdoc` to loosen requirements for various kinds of symbols ([#433](https://github.com/MetaMask/eslint-config/pull/433)) | ||
| - Require JSDoc not for all arrow functions, but only those not contained within plain objects or are not arguments to functions or methods. | ||
| - Require JSDoc not for all interfaces or type aliases, but only those that do not appear in declare blocks (ambient declarations). |
There was a problem hiding this comment.
Do you have an example for these last two points? I'm not sure that I understand what they mean
There was a problem hiding this comment.
I didn't word this very well, sorry.
Here are some examples for the arrow function entry:
// The arrow function here is no longer required to be documented
foo(() => {
// ...
})
foo({
// The arrow function here is no longer required to be documented
bar: () => {
// ...
}
})There was a problem hiding this comment.
Here are some examples for the interfaces / type aliases entry:
declare module 'prettier' {
// This is no longer required to be documented
type Bar = 'baz';
// This is no longer required to be documented
export interface Y {
// whatever
}
}Here are some examples for the "object types in return types" entry:
// The object type which is the return type of this function
// is no longer required to be documented
function foo(): {
bar: 'baz';
qux: 'blargh';
} {
return { bar: 'baz', qux: 'blargh' };
}There was a problem hiding this comment.
I've updated the changelogs so the changes are more clear. I also realized that enums weren't properly scoped so I fixed that as well: d64d667
There was a problem hiding this comment.
I am having trouble understanding that last example. What specifically no longer needs to be documented there - what do you mean by "the object type"? We don't document types in JSDoc at all in TypeScript projects - why would any type documentation be needed there in the first place?
There was a problem hiding this comment.
Interesting. What is an "inline object return type"?
There was a problem hiding this comment.
Sorry, what I meant is an object type used as a return type which is written inline (not extracted to its own named type).
In code, the change I think I ought to make here is:
function foo(): {
// We should not require this property to be documented
bar: 'baz';
} {
// ...
}
type Foo = {
// But we should continue to require this property to be documented
bar: 'baz';
}Any thoughts on this?
There was a problem hiding this comment.
Oh I see, you mean the properties of an object return type. Interesting.
I see what you mean, it is awkward to document properties inline as part of a function signature. I would never expect to be asked to do that. But then again, we do want return types to have docs.
For example if we call that function:
const { bar } = foo();
and hover over bar, it would have no docs at all. Not ideal.
There was a problem hiding this comment.
Though if we're unsure at all about a stylistic rule, it would be better to err on the side of loosening it, so I'm still in favour of this (if you find a way to accomplish it that is).
There was a problem hiding this comment.
Okay, this should take care of it. JSDoc will still be required for properties, as long as they are not part of an inline return type: b702649
| "jsdoc/require-example": "off", | ||
| "jsdoc/require-file-overview": "off", | ||
| "jsdoc/require-hyphen-before-param-description": "off", | ||
| "jsdoc/require-jsdoc": "error", |
There was a problem hiding this comment.
Hmm... this might be a breaking change. It seems that the typescript package has been overriding the base package :(
I'll have to double-check this.
There was a problem hiding this comment.
Yeah, so it was. It was overwritten by jsdoc.configs['flat/recommended-typescript-error'],.
That's fine, we can include this in v16 instead then
There was a problem hiding this comment.
Actually we still need a changelog update to reflect this
Changelog update needed to accurately reflect nature of breaking JSDoc changes in typescript package

Currently, all arrow functions and function expressions are required to be documented with JSDoc, and object types in return types are required to documented as well.
This means:
This commit loosens the rules so that:
declareblocks (ambient declarations)References
https://consensyssoftware.atlassian.net/browse/WPC-955
Note
Low Risk
Low risk: config-only changes that mainly reduce lint noise, though selector-based
jsdoc/require-jsdoctweaks could subtly change what gets flagged in consumer codebases.Overview
Relaxes
jsdoc/require-jsdocin the base config so arrow functions and function expressions only require JSDoc when they’re not object property values and not callback arguments (via selector-basedcontexts).Updates the TypeScript config to build on the base rule instead of replacing it, adding TypeScript-specific
contextsto require JSDoc for interfaces/type aliases/enums except insidedeclareblocks, and for property signatures only on named interfaces/type aliases (not inline object return types). Changelogs and rule snapshots are updated accordingly.Reviewed by Cursor Bugbot for commit 5b07ebc. Bugbot is set up for automated code reviews on this repo. Configure here.