From 61a3599154bb570aca3e1eeee614c1e597ead266 Mon Sep 17 00:00:00 2001 From: Kevin Locke Date: Wed, 24 Feb 2016 11:38:56 -0800 Subject: [PATCH] Support an Array of tags titles in allowUnknownTags This commit adds support for specifying an Array of tags which are unknown to JSDoc, but allowed without error. It provides a more granular way to disable such errors while retaining the benefits of catching errant tags (e.g. typos). The intended use case is catching errant tags when using additional tools which support tags not recognized by JSDoc (e.g. Closure Compiler and the tags discussed in #605). Signed-off-by: Kevin Locke --- lib/jsdoc/tag/validator.js | 5 ++++- test/specs/jsdoc/tag/validator.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/jsdoc/tag/validator.js b/lib/jsdoc/tag/validator.js index 0e78bf6ea..7614b14d2 100644 --- a/lib/jsdoc/tag/validator.js +++ b/lib/jsdoc/tag/validator.js @@ -28,7 +28,10 @@ exports.validate = function(tag, tagDef, meta) { // handle cases where the tag definition does not exist if (!tagDef) { // log an error if unknown tags are not allowed - if (!env.conf.tags.allowUnknownTags) { + var allowUnknownTags = env.conf.tags.allowUnknownTags; + if (!allowUnknownTags || + (Array.isArray(allowUnknownTags) && + allowUnknownTags.indexOf(tag.title) < 0)) { logger.error( buildMessage(tag.title, meta, 'is not a known tag') ); } diff --git a/test/specs/jsdoc/tag/validator.js b/test/specs/jsdoc/tag/validator.js index b22151ea8..04ee42ba9 100644 --- a/test/specs/jsdoc/tag/validator.js +++ b/test/specs/jsdoc/tag/validator.js @@ -51,6 +51,13 @@ describe('jsdoc/tag/validator', function() { expect(logger.error).toHaveBeenCalled(); }); + it('logs an error if the tag is not in the dictionary and conf.tags.allowUnknownTags is does not include it', function() { + env.conf.tags.allowUnknownTags = []; + validateTag(badTag); + + expect(logger.error).toHaveBeenCalled(); + }); + it('does not log an error if the tag is not in the dictionary and conf.tags.allowUnknownTags is true', function() { env.conf.tags.allowUnknownTags = true; validateTag(badTag); @@ -58,6 +65,13 @@ describe('jsdoc/tag/validator', function() { expect(logger.error).not.toHaveBeenCalled(); }); + it('does not log an error if the tag is not in the dictionary and conf.tags.allowUnknownTags includes it', function() { + env.conf.tags.allowUnknownTags = [badTag.title]; + validateTag(badTag); + + expect(logger.error).not.toHaveBeenCalled(); + }); + it('does not log an error for valid tags', function() { validateTag(goodTag); validateTag(goodTag2);