From 2d6a720f73b06285d951ef3740de5e5cfffc56ee Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Fri, 13 Sep 2024 17:18:04 +0800 Subject: [PATCH] fix(`require-jsdoc`): avoid erring on static blocks --- docs/rules/require-jsdoc.md | 7 +++++++ src/exportParser.js | 3 +++ test/rules/assertions/requireJsdoc.js | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/docs/rules/require-jsdoc.md b/docs/rules/require-jsdoc.md index 744803d4..411f596f 100644 --- a/docs/rules/require-jsdoc.md +++ b/docs/rules/require-jsdoc.md @@ -1894,5 +1894,12 @@ export class MyClass { #myPrivateProp = 5; } // "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"contexts":["PropertyDefinition"],"require":{"MethodDefinition":true}}] + +class Abc { + static { + this.x = '2' + } +} +// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"ClassDeclaration":true}}] ```` diff --git a/src/exportParser.js b/src/exportParser.js index 4bb2e13b..b9dff88c 100644 --- a/src/exportParser.js +++ b/src/exportParser.js @@ -212,6 +212,9 @@ const getSymbol = function (node, globals, scope, opt) { case 'ClassBody': { const val = createNode(); for (const method of node.body) { + if (!('key' in method)) { // StaticBlock + continue; + } val.props[ /** @type {import('estree').Identifier} */ ( /** @type {import('estree').MethodDefinition} */ ( diff --git a/test/rules/assertions/requireJsdoc.js b/test/rules/assertions/requireJsdoc.js index 48ddb50d..e8ab9b0f 100644 --- a/test/rules/assertions/requireJsdoc.js +++ b/test/rules/assertions/requireJsdoc.js @@ -6293,5 +6293,25 @@ function quux (foo) { }, ], }, + { + code: ` + class Abc { + static { + this.x = '2' + } + } + `, + languageOptions: { + parser: babelEslintParser, + }, + options: [ + { + publicOnly: true, + require: { + ClassDeclaration: true + } + } + ], + } ], };