Skip to content

Loosen JSDoc rules#433

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

Loosen JSDoc rules#433
mcmire wants to merge 11 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

Note

Medium Risk
Changes lint enforcement for jsdoc/require-jsdoc, which can significantly alter consumer CI outcomes (fewer required docblocks) and relies on AST selector contexts behaving as intended across JS/TS code.

Overview
Loosens jsdoc/require-jsdoc in the base config by replacing the blanket requirement for all arrow functions and function expressions with AST-selector contexts that only require JSDoc when those functions are not object properties and are not passed as call/new arguments.

In the TypeScript config, replaces the previous simple jsdoc/require-jsdoc: 'error' with an explicit rule config that extends the base rule options (via a new helper to collect upstream array-valued rule options) and adds TS-specific contexts to require docs for non-ambient (declare-block excluded) interfaces/type aliases plus enums. Changelogs and rule snapshots are updated to match.

Written by Cursor Bugbot for commit 140fdf5. This will update automatically on new commits. 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
@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.

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.

1 participant