Skip to content

Commit c70a3ff

Browse files
authored
BREAKING: Update jsdoc/require-jsdoc to require documentation for more things (#394)
This updates the `jsdoc/require-jsdoc` rule to require documentation for: - Arrow functions. ```ts const myFunction = () => { // ... }; ``` - Class declarations. ```ts class MyClass { // ... } ``` - TypeScript enum declarations. ```ts enum MyEnum { // ... }; ``` - Function expressions. ```ts const myFunction = function () { // ... }; ``` - TypeScript interface declarations. ```ts interface MyInterface { // ... }; ``` - Method definitions. ```ts const myObject = { myFunction() { // ... }, }; ``` - TypeScript type alias declarations. ```ts type MyType = { // ... }; - TypeScript property signatures. ```ts type MyType = { myProperty: string; }; ``` ## Breaking changes Each of the code blocks above was previously valid, but will now produce an error. Closes #223. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Expands `jsdoc/require-jsdoc` to require JSDoc on more JS/TS constructs and adds a brief doc comment to `ConfigWithExtends.extends`. > > - **ESLint config (`packages/base/src/index.mjs`, `packages/base/rules-snapshot.json`)**: > - Expand `jsdoc/require-jsdoc` from a simple enablement to a configured rule requiring docs for: > - `ArrowFunctionExpression`, `ClassDeclaration`, `FunctionDeclaration`, `FunctionExpression`, `MethodDefinition`. > - TS contexts: `TSInterfaceDeclaration`, `TSTypeAliasDeclaration`, `TSEnumDeclaration`, `TSPropertySignature`. > - **Types (`packages/base/src/index.d.mts`)**: > - Add JSDoc for `ConfigWithExtends`.`extends` detailing supported shapes. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit e0efa13. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 636bc75 commit c70a3ff

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

packages/base/rules-snapshot.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,24 @@
176176
"always",
177177
{ "tags": { "returns": "never", "template": "always", "throws": "never" } }
178178
],
179-
"jsdoc/require-jsdoc": "error",
179+
"jsdoc/require-jsdoc": [
180+
"error",
181+
{
182+
"require": {
183+
"ArrowFunctionExpression": true,
184+
"ClassDeclaration": true,
185+
"FunctionDeclaration": true,
186+
"FunctionExpression": true,
187+
"MethodDefinition": true
188+
},
189+
"contexts": [
190+
"TSInterfaceDeclaration",
191+
"TSTypeAliasDeclaration",
192+
"TSEnumDeclaration",
193+
"TSPropertySignature"
194+
]
195+
}
196+
],
180197
"jsdoc/require-param": ["error", { "unnamedRootBase": ["options"] }],
181198
"jsdoc/require-param-description": "error",
182199
"jsdoc/require-param-name": "error",

packages/base/src/index.d.mts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ declare module '@metamask/eslint-config' {
1111
* can only be used with the {@link createConfig} function.
1212
*/
1313
type ConfigWithExtends = Config & {
14+
/**
15+
* The configuration(s) to extend. This can be a single configuration, an
16+
* array of configurations, or an array of arrays of configurations.
17+
*/
1418
extends?: Config | Config[] | Config[][];
1519
};
1620

packages/base/src/index.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,24 @@ const rules = createConfig({
393393
'always',
394394
{ tags: { returns: 'never', template: 'always', throws: 'never' } },
395395
],
396-
'jsdoc/require-jsdoc': 'error',
396+
'jsdoc/require-jsdoc': [
397+
'error',
398+
{
399+
require: {
400+
ArrowFunctionExpression: true,
401+
ClassDeclaration: true,
402+
FunctionDeclaration: true,
403+
FunctionExpression: true,
404+
MethodDefinition: true,
405+
},
406+
contexts: [
407+
'TSInterfaceDeclaration',
408+
'TSTypeAliasDeclaration',
409+
'TSEnumDeclaration',
410+
'TSPropertySignature',
411+
],
412+
},
413+
],
397414
'jsdoc/require-param-name': 'error',
398415
'jsdoc/require-param': ['error', { unnamedRootBase: ['options'] }],
399416
'jsdoc/require-param-description': 'error',

0 commit comments

Comments
 (0)