From 10bb92ec588779866f13e028ce433d57285f2de6 Mon Sep 17 00:00:00 2001 From: Extersky Date: Sat, 25 May 2019 13:03:30 +0300 Subject: [PATCH] fix: check class declarations * Class declarations were not checked * Added guards symbol exports, which caused errors before class declaration handling was added --- src/exportParser.js | 17 +++++++++++++---- test/rules/assertions/requireJsdoc.js | 24 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/exportParser.js b/src/exportParser.js index 2ecae911f..a666973e8 100644 --- a/src/exportParser.js +++ b/src/exportParser.js @@ -67,7 +67,7 @@ const getSymbol = function (node, globals, scope, opt) { debug('MemberExpression: Missing property ' + node.property.name); return null; - } case 'FunctionExpression': case 'FunctionDeclaration': case 'ArrowFunctionExpression': { + } case 'ClassDeclaration': case 'FunctionExpression': case 'FunctionDeclaration': case 'ArrowFunctionExpression': { const val = createNode(); val.props.prototype = createNode(); val.props.prototype.type = 'object'; @@ -115,7 +115,12 @@ createSymbol = function (node, globals, value, scope) { const block = scope || globals; let symbol; switch (node.type) { - case 'Identifier': { + case 'ClassDeclaration': { + if (node.id.type === 'Identifier') { + return createSymbol(node.id, globals, node, globals); + } + break; + } case 'Identifier': { if (value) { const valueSymbol = getSymbol(value, globals, block); if (valueSymbol) { @@ -204,7 +209,9 @@ const mapVariables = function (node, globals) { break; } case 'ExportDefaultDeclaration': { const symbol = createSymbol(node.declaration, globals, node.declaration); - symbol.exported = true; + if (symbol) { + symbol.exported = true; + } break; } case 'ExportNamedDeclaration': { if (node.declaration) { @@ -217,7 +224,9 @@ const mapVariables = function (node, globals) { break; } case 'ExportSpecifier': { const symbol = getSymbol(node.local, globals, globals); - symbol.exported = true; + if (symbol) { + symbol.exported = true; + } break; } case 'ClassDeclaration': { createSymbol(node.id, globals, node.body, globals); diff --git a/test/rules/assertions/requireJsdoc.js b/test/rules/assertions/requireJsdoc.js index 87624005a..010f4f038 100644 --- a/test/rules/assertions/requireJsdoc.js +++ b/test/rules/assertions/requireJsdoc.js @@ -583,6 +583,30 @@ export default { publicFunctionsOnly: true } } + }, + { + code: ` + export default class A { + + } + `, + errors: [{ + message: 'Missing JSDoc comment.', + type: 'ClassDeclaration' + }], + options: [{ + require: { + ClassDeclaration: true + } + }], + parserOptions: { + sourceType: 'module' + }, + settings: { + jsdoc: { + publicFunctionsOnly: true + } + } } ], valid: [{