From 854fb244be890d5ca5af98bd678580256ca7b984 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Mon, 20 Jul 2020 22:34:18 +0800 Subject: [PATCH] fix(`require-jsdoc`): avoid error with `checkConstructors: false` when attempting to check tags; fixes #611 In this rule, jsdocNode is empty by the time we check for `exemptSpecialMethods`, so ensure there is a no-op for its tags --- README.md | 6 ++++++ src/rules/requireJsdoc.js | 2 +- test/rules/assertions/requireJsdoc.js | 30 +++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c6c5a0e54..4da221eef 100644 --- a/README.md +++ b/README.md @@ -9212,6 +9212,12 @@ function quux() { } // Settings: {"jsdoc":{"structuredTags":{"see":{"name":false,"required":["name"]}}}} // Message: Cannot add "name" to `require` with the tag's `name` set to `false` + +class Test { + aFunc() {} +} +// Options: [{"checkConstructors":false,"require":{"ArrowFunctionExpression":true,"ClassDeclaration":false,"ClassExpression":true,"FunctionDeclaration":true,"FunctionExpression":true,"MethodDefinition":true}}] +// Message: Missing JSDoc comment. ```` The following patterns are not considered problems: diff --git a/src/rules/requireJsdoc.js b/src/rules/requireJsdoc.js index 62a4a95f7..d104a6d61 100644 --- a/src/rules/requireJsdoc.js +++ b/src/rules/requireJsdoc.js @@ -185,7 +185,7 @@ export default { // For those who have options configured against ANY constructors (or setters or getters) being reported if (jsdocUtils.exemptSpeciaMethods( - jsDocNode, node, context, [OPTIONS_SCHEMA], + {tags: []}, node, context, [OPTIONS_SCHEMA], )) { return; } diff --git a/test/rules/assertions/requireJsdoc.js b/test/rules/assertions/requireJsdoc.js index bad5d6571..24cbd9c01 100644 --- a/test/rules/assertions/requireJsdoc.js +++ b/test/rules/assertions/requireJsdoc.js @@ -2428,6 +2428,36 @@ export default { }, }, }, + { + code: ` + class Test { + aFunc() {} + } + `, + errors: [{ + line: 3, + message: 'Missing JSDoc comment.', + }], + options: [{ + checkConstructors: false, + require: { + ArrowFunctionExpression: true, + ClassDeclaration: false, + ClassExpression: true, + FunctionDeclaration: true, + FunctionExpression: true, + MethodDefinition: true, + }, + }], + output: ` + class Test { + /** + * + */ + aFunc() {} + } + `, + }, ], valid: [{ code: `