Skip to content

Commit

Permalink
fix(require-jsdoc): do not report PropertyDefinition's with non-p…
Browse files Browse the repository at this point in the history
…ublic `accessibility`; fixes #1122
  • Loading branch information
brettz9 committed Jun 28, 2023
1 parent 1886b36 commit 1e45ae4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/rules/require-jsdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,19 @@ class A {
}
// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":[{"context":"MethodDefinition","minLineCount":3}],"require":{"ClassDeclaration":false,"FunctionExpression":false,"MethodDefinition":false}}]
// Message: Missing JSDoc comment.

export class MyClass {

public myPublicProperty: number = 1;
/* ^ Missing JSDoc comment. eslint(jsdoc/require-jsdoc) - expected ✅ */

private myPrivateProp: number = -1;
/* ^ Missing JSDoc comment. eslint(jsdoc/require-jsdoc) - unexpected ❌ */

// ...
}
// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["PropertyDefinition"],"publicOnly":true}]
// Message: Missing JSDoc comment.
````


Expand Down
7 changes: 7 additions & 0 deletions src/exportParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,13 @@ const isUncommentedExport = function (node, sourceCode, opt, settings) {
// console.log({node});
// Optimize with ancestor check for esm
if (opt.esm) {
if (
node.type === 'PropertyDefinition' && 'accessibility' in node &&
node.accessibility !== 'public'
) {
return false;
}

const exportNode = getExportAncestor(node);

// Is export node comment
Expand Down
44 changes: 44 additions & 0 deletions test/rules/assertions/requireJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4081,6 +4081,50 @@ function quux (foo) {
`,
parser: require.resolve('@typescript-eslint/parser'),
},
{
code: `
export class MyClass {
public myPublicProperty: number = 1;
/* ^ Missing JSDoc comment. eslint(jsdoc/require-jsdoc) - expected ✅ */
private myPrivateProp: number = -1;
/* ^ Missing JSDoc comment. eslint(jsdoc/require-jsdoc) - unexpected ❌ */
// ...
}
`,
errors: [
{
line: 4,
message: 'Missing JSDoc comment.',
},
],
options: [
{
contexts: [
'PropertyDefinition',
],
publicOnly: true,
},
],
output: `
export class MyClass {
/**
*
*/
public myPublicProperty: number = 1;
/* ^ Missing JSDoc comment. eslint(jsdoc/require-jsdoc) - expected ✅ */
private myPrivateProp: number = -1;
/* ^ Missing JSDoc comment. eslint(jsdoc/require-jsdoc) - unexpected ❌ */
// ...
}
`,
parser: require.resolve('@typescript-eslint/parser'),
},
],
valid: [
{
Expand Down

0 comments on commit 1e45ae4

Please sign in to comment.