Skip to content

Loosen JSDoc rules#433

Open
mcmire wants to merge 19 commits intomainfrom
loosen-jsdoc-rules
Open

Loosen JSDoc rules#433
mcmire wants to merge 19 commits intomainfrom
loosen-jsdoc-rules

Conversation

@mcmire
Copy link
Copy Markdown
Contributor

@mcmire mcmire commented Dec 19, 2025

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:

// 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

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-jsdoc tweaks could subtly change what gets flagged in consumer codebases.

Overview
Relaxes jsdoc/require-jsdoc in 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-based contexts).

Updates the TypeScript config to build on the base rule instead of replacing it, adding TypeScript-specific contexts to require JSDoc for interfaces/type aliases/enums except inside declare blocks, 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.

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
@mcmire mcmire requested a review from a team as a code owner December 19, 2025 22:55
Comment thread packages/typescript/src/index.mjs
Comment thread packages/typescript/src/index.mjs Outdated
@mcmire
Copy link
Copy Markdown
Contributor Author

mcmire commented Feb 17, 2026

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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Comment thread packages/typescript/src/index.mjs
Comment thread packages/typescript/CHANGELOG.md Outdated

- 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).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example for these last two points? I'm not sure that I understand what they mean

Copy link
Copy Markdown
Contributor Author

@mcmire mcmire Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: () => {
    // ...
  }
})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' };
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. What is an "inline object return type"?

Copy link
Copy Markdown
Contributor Author

@mcmire mcmire Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

@Gudahtt Gudahtt Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we still need a changelog update to reflect this

Gudahtt
Gudahtt previously approved these changes Apr 15, 2026
Copy link
Copy Markdown
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Gudahtt Gudahtt dismissed their stale review April 15, 2026 16:08

Changelog update needed to accurately reflect nature of breaking JSDoc changes in typescript package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants