Skip to content

Commit 874adab

Browse files
committed
fix(require-jsdoc): avoid exported functions possessing jsdoc blocks causing other non-public functions to be treated as exported; fixes #358
1 parent 5bb9182 commit 874adab

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5638,6 +5638,15 @@ const myObject = {
56385638
myProp: true
56395639
};
56405640
// Options: [{"contexts":[]}]
5641+
5642+
function bear() {}
5643+
/**
5644+
*
5645+
*/
5646+
function quux () {
5647+
}
5648+
export default quux;
5649+
// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
56415650
````
56425651

56435652

src/exportParser.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,7 @@ const findExportedNode = function (block, node, cache) {
340340
if (Object.prototype.hasOwnProperty.call(props, key)) {
341341
blockCache.push(props[key]);
342342
if (props[key].exported) {
343-
// If not always true, we need a test
344-
/* istanbul ignore next */
345-
if (findNode(node, block)) {
343+
if (node === props[key].value || findNode(node, props[key].value)) {
346344
return true;
347345
}
348346
}

test/rules/assertions/requireJsdoc.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,5 +2163,24 @@ export default {
21632163
contexts: [],
21642164
},
21652165
],
2166+
}, {
2167+
code: `
2168+
function bear() {}
2169+
/**
2170+
*
2171+
*/
2172+
function quux () {
2173+
}
2174+
export default quux;
2175+
`,
2176+
options: [{
2177+
publicOnly: true,
2178+
require: {
2179+
FunctionExpression: true,
2180+
},
2181+
}],
2182+
parserOptions: {
2183+
sourceType: 'module',
2184+
},
21662185
}],
21672186
};

0 commit comments

Comments
 (0)