Skip to content

Commit 8222262

Browse files
committed
fix(require-jsdoc): avoid erring on static blocks
1 parent 288f0ae commit 8222262

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

docs/rules/require-jsdoc.md

+7
Original file line numberDiff line numberDiff line change
@@ -1894,5 +1894,12 @@ export class MyClass {
18941894
#myPrivateProp = 5;
18951895
}
18961896
// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"contexts":["PropertyDefinition"],"require":{"MethodDefinition":true}}]
1897+
1898+
class Abc {
1899+
static {
1900+
this.x = '2'
1901+
}
1902+
}
1903+
// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"ClassDeclaration":true}}]
18971904
````
18981905

src/exportParser.js

+3
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ const getSymbol = function (node, globals, scope, opt) {
212212
case 'ClassBody': {
213213
const val = createNode();
214214
for (const method of node.body) {
215+
if (!('key' in method)) { // StaticBlock
216+
continue;
217+
}
215218
val.props[
216219
/** @type {import('estree').Identifier} */ (
217220
/** @type {import('estree').MethodDefinition} */ (

test/rules/assertions/requireJsdoc.js

+20
Original file line numberDiff line numberDiff line change
@@ -6293,5 +6293,25 @@ function quux (foo) {
62936293
},
62946294
],
62956295
},
6296+
{
6297+
code: `
6298+
class Abc {
6299+
static {
6300+
this.x = '2'
6301+
}
6302+
}
6303+
`,
6304+
languageOptions: {
6305+
parser: babelEslintParser,
6306+
},
6307+
options: [
6308+
{
6309+
publicOnly: true,
6310+
require: {
6311+
ClassDeclaration: true
6312+
}
6313+
}
6314+
],
6315+
}
62966316
],
62976317
};

0 commit comments

Comments
 (0)