Skip to content

Commit 783b4e9

Browse files
committedMar 7, 2024·
fix(require-jsdoc): avoid erring on #-marked private methods; fixes #1212
1 parent e948bee commit 783b4e9

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed
 

‎docs/rules/require-jsdoc.md

+7
Original file line numberDiff line numberDiff line change
@@ -1898,5 +1898,12 @@ export default {
18981898
}
18991899
};
19001900
// "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"]}]
1901+
1902+
export class MyClass {
1903+
#myPrivateMethod(): void { }
1904+
1905+
#myPrivateProp = 5;
1906+
}
1907+
// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"contexts":["PropertyDefinition"],"require":{"MethodDefinition":true}}]
19011908
````
19021909

‎src/exportParser.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -899,9 +899,14 @@ const accessibilityNodes = new Set([
899899
* @param {import('eslint').Rule.Node} node
900900
* @returns {boolean}
901901
*/
902-
const hasAccessibility = (node) => {
903-
return accessibilityNodes.has(node.type) && 'accessibility' in node &&
904-
node.accessibility !== 'public' && node.accessibility !== undefined;
902+
const isPrivate = (node) => {
903+
return accessibilityNodes.has(node.type) &&
904+
(
905+
'accessibility' in node &&
906+
node.accessibility !== 'public' && node.accessibility !== undefined
907+
) ||
908+
'key' in node &&
909+
node.key.type === 'PrivateIdentifier';
905910
};
906911

907912
/**
@@ -916,8 +921,8 @@ const isUncommentedExport = function (node, sourceCode, opt, settings) {
916921
// console.log({node});
917922
// Optimize with ancestor check for esm
918923
if (opt.esm) {
919-
if (hasAccessibility(node) ||
920-
node.parent && hasAccessibility(node.parent)) {
924+
if (isPrivate(node) ||
925+
node.parent && isPrivate(node.parent)) {
921926
return false;
922927
}
923928

‎test/rules/assertions/requireJsdoc.js

+21
Original file line numberDiff line numberDiff line change
@@ -6342,5 +6342,26 @@ function quux (foo) {
63426342
parser: typescriptEslintParser,
63436343
}
63446344
},
6345+
{
6346+
code: `
6347+
export class MyClass {
6348+
#myPrivateMethod(): void { }
6349+
6350+
#myPrivateProp = 5;
6351+
}
6352+
`,
6353+
languageOptions: {
6354+
parser: typescriptEslintParser,
6355+
},
6356+
options: [
6357+
{
6358+
publicOnly: true,
6359+
contexts: ['PropertyDefinition'],
6360+
require: {
6361+
MethodDefinition: true,
6362+
},
6363+
},
6364+
],
6365+
},
63456366
],
63466367
};

0 commit comments

Comments
 (0)
Please sign in to comment.