Skip to content

Commit 3e8ea59

Browse files
committed
fix(require-jsdoc): handle spread elements in typescript-eslint/parser; for #378
1 parent b1ce407 commit 3e8ea59

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8171,6 +8171,14 @@ export default class Foo {
81718171
// ....
81728172
}
81738173
// Options: [{"exemptEmptyFunctions":false,"require":{"ClassDeclaration":true}}]
8174+
8175+
const a = {};
8176+
const b = {
8177+
...a
8178+
};
8179+
8180+
export default b;
8181+
// Options: [{"contexts":["ObjectExpression"],"exemptEmptyFunctions":false,"publicOnly":true}]
81748182
````
81758183
81768184

src/exportParser.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,13 @@ const getSymbol = function (node, globals, scope, opt) {
105105
const val = createNode();
106106
val.type = 'object';
107107
node.properties.forEach((prop) => {
108-
if (prop.type === 'ExperimentalSpreadProperty') {
108+
if ([
109+
// @typescript-eslint/parser, espree, acorn, etc.
110+
'SpreadElement',
111+
112+
// babel-eslint
113+
'ExperimentalSpreadProperty',
114+
].includes(prop.type)) {
109115
return;
110116
}
111117
const propVal = getSymbol(prop.value, globals, scope, opts);

test/rules/assertions/requireJsdoc.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,5 +2383,26 @@ export default {
23832383
sourceType: 'module',
23842384
},
23852385
},
2386+
{
2387+
code: `
2388+
const a = {};
2389+
const b = {
2390+
...a
2391+
};
2392+
2393+
export default b;
2394+
`,
2395+
options: [
2396+
{
2397+
contexts: ['ObjectExpression'],
2398+
exemptEmptyFunctions: false,
2399+
publicOnly: true,
2400+
},
2401+
],
2402+
parser: require.resolve('@typescript-eslint/parser'),
2403+
parserOptions: {
2404+
sourceType: 'module',
2405+
},
2406+
},
23862407
],
23872408
};

0 commit comments

Comments
 (0)