diff --git a/docs/rules/require-jsdoc.md b/docs/rules/require-jsdoc.md index 5f120d084..8447bfd74 100644 --- a/docs/rules/require-jsdoc.md +++ b/docs/rules/require-jsdoc.md @@ -1898,5 +1898,12 @@ export default { } }; // "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["ExportDefaultDeclaration > ObjectExpression > Property[key.name!=/^(created|beforeUpdate)$/] > FunctionExpression","ExportDefaultDeclaration > ObjectExpression > Property[key.name!=/^(watch|computed|methods)$/] > ObjectExpression > Property > FunctionExpression"]}] + +export class MyClass { + #myPrivateMethod(): void { } + + #myPrivateProp = 5; +} +// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"contexts":["PropertyDefinition"],"require":{"MethodDefinition":true}}] ```` diff --git a/src/exportParser.js b/src/exportParser.js index 590650bd3..fe74c197e 100644 --- a/src/exportParser.js +++ b/src/exportParser.js @@ -899,9 +899,14 @@ const accessibilityNodes = new Set([ * @param {import('eslint').Rule.Node} node * @returns {boolean} */ -const hasAccessibility = (node) => { - return accessibilityNodes.has(node.type) && 'accessibility' in node && - node.accessibility !== 'public' && node.accessibility !== undefined; +const isPrivate = (node) => { + return accessibilityNodes.has(node.type) && + ( + 'accessibility' in node && + node.accessibility !== 'public' && node.accessibility !== undefined + ) || + 'key' in node && + node.key.type === 'PrivateIdentifier'; }; /** @@ -916,8 +921,8 @@ const isUncommentedExport = function (node, sourceCode, opt, settings) { // console.log({node}); // Optimize with ancestor check for esm if (opt.esm) { - if (hasAccessibility(node) || - node.parent && hasAccessibility(node.parent)) { + if (isPrivate(node) || + node.parent && isPrivate(node.parent)) { return false; } diff --git a/test/rules/assertions/requireJsdoc.js b/test/rules/assertions/requireJsdoc.js index 411d8505a..71f0903eb 100644 --- a/test/rules/assertions/requireJsdoc.js +++ b/test/rules/assertions/requireJsdoc.js @@ -6342,5 +6342,26 @@ function quux (foo) { parser: typescriptEslintParser, } }, + { + code: ` + export class MyClass { + #myPrivateMethod(): void { } + + #myPrivateProp = 5; + } + `, + languageOptions: { + parser: typescriptEslintParser, + }, + options: [ + { + publicOnly: true, + contexts: ['PropertyDefinition'], + require: { + MethodDefinition: true, + }, + }, + ], + }, ], };