Skip to content

Commit

Permalink
fix(require-jsdoc): avoid class jsdoc blocks suppressing errors for…
Browse files Browse the repository at this point in the history
… `PropertyDefinition`; fixes #841
  • Loading branch information
brettz9 committed Feb 18, 2022
1 parent 06c3163 commit ef68427
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13322,6 +13322,24 @@ export const outer = () => {
};
// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"ArrowFunctionExpression":true,"ClassDeclaration":true,"ClassExpression":true,"FunctionDeclaration":true,"FunctionExpression":true,"MethodDefinition":true}}]
// Message: Missing JSDoc comment.

/**
*
*/
export class InovaAutoCompleteComponent {
public disabled = false;
}
// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["PropertyDefinition"],"publicOnly":true}]
// Message: Missing JSDoc comment.

/**
* Some comment.
*/
export class Component {
public foo?: number;
}
// "jsdoc/require-jsdoc": ["error"|"warn", {"checkConstructors":false,"contexts":["PropertyDefinition"],"publicOnly":true}]
// Message: Missing JSDoc comment.
````

The following patterns are not considered problems:
Expand Down
7 changes: 5 additions & 2 deletions src/exportParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,23 +445,26 @@ const getExportAncestor = function (nde) {
return false;
};

const canExportedByAncestorType = new Set([
const canBeExportedByAncestorType = new Set([
'TSPropertySignature',
'TSMethodSignature',
'ClassProperty',
'PropertyDefinition',
'Method',
]);

const canExportChildrenType = new Set([
'TSInterfaceBody',
'TSInterfaceDeclaration',
'ClassDeclaration',
'ClassBody',
'ClassDefinition',
'ClassExpression',
'Program',
]);

const isExportByAncestor = function (nde) {
if (!canExportedByAncestorType.has(nde.type)) {
if (!canBeExportedByAncestorType.has(nde.type)) {
return false;
}

Expand Down
76 changes: 76 additions & 0 deletions test/rules/assertions/requireJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3650,6 +3650,82 @@ function quux (foo) {
sourceType: 'module',
},
},
{
code: `
/**
*
*/
export class InovaAutoCompleteComponent {
public disabled = false;
}
`,
errors: [
{
line: 6,
message: 'Missing JSDoc comment.',
},
],
options: [
{
contexts: [
'PropertyDefinition',
],
publicOnly: true,
},
],
output: `
/**
*
*/
export class InovaAutoCompleteComponent {
/**
*
*/
public disabled = false;
}
`,
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: {
sourceType: 'module',
},
},
{
code: `
/**
* Some comment.
*/
export class Component {
public foo?: number;
}
`,
errors: [
{
line: 6,
message: 'Missing JSDoc comment.',
},
],
options: [
{
checkConstructors: false,
contexts: [
'PropertyDefinition',
],
publicOnly: true,
},
],
output: `
/**
* Some comment.
*/
export class Component {
/**
*
*/
public foo?: number;
}
`,
parser: require.resolve('@typescript-eslint/parser'),
},
],
valid: [
{
Expand Down

0 comments on commit ef68427

Please sign in to comment.