Skip to content

Commit

Permalink
fix(require-jsdoc): support TSEnumDeclaration with publicOnly; f…
Browse files Browse the repository at this point in the history
…ixes #640
  • Loading branch information
brettz9 committed Sep 25, 2020
1 parent a1d95e6 commit 63ef3bc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -9951,6 +9951,12 @@ class Test {
}
// Options: [{"require":{"ArrowFunctionExpression":true,"ClassDeclaration":false,"ClassExpression":true,"FunctionDeclaration":true,"FunctionExpression":true,"MethodDefinition":true}}]
// Message: Missing JSDoc comment.

export enum testEnum {
A, B
}
// Options: [{"contexts":["TSEnumDeclaration"],"publicOnly":true}]
// Message: Missing JSDoc comment.
````

The following patterns are not considered problems:
Expand Down
7 changes: 6 additions & 1 deletion src/exportParser.js
Expand Up @@ -80,7 +80,11 @@ const getSymbol = function (node, globals, scope, opt) {

/* istanbul ignore next */
return null;
} case 'ClassDeclaration': case 'ClassExpression': case 'FunctionExpression': case 'FunctionDeclaration': case 'ArrowFunctionExpression': {
}
case 'TSEnumDeclaration':
case 'ClassDeclaration': case 'ClassExpression':
case 'FunctionExpression': case 'FunctionDeclaration':
case 'ArrowFunctionExpression': {
const val = createNode();
val.props.prototype = createNode();
val.props.prototype.type = 'object';
Expand Down Expand Up @@ -146,6 +150,7 @@ createSymbol = function (node, globals, value, scope, isGlobal) {
const block = scope || globals;
let symbol;
switch (node.type) {
case 'TSEnumDeclaration':
case 'FunctionDeclaration':

// Fallthrough
Expand Down
31 changes: 31 additions & 0 deletions test/rules/assertions/requireJsdoc.js
Expand Up @@ -2554,6 +2554,37 @@ export default {
`,
parser: require.resolve('babel-eslint'),
},
{
code: `
export enum testEnum {
A, B
}
`,
errors: [
{
line: 2,
message: 'Missing JSDoc comment.',
},
],
options: [
{
contexts: ['TSEnumDeclaration'],
publicOnly: true,
},
],
output: `
/**
*
*/
export enum testEnum {
A, B
}
`,
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: {
sourceType: 'module',
},
},
],
valid: [{
code: `
Expand Down

0 comments on commit 63ef3bc

Please sign in to comment.