Skip to content

Commit

Permalink
Support an Array of tags titles in allowUnknownTags
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kevinoid authored and hegemonic committed Aug 25, 2016
1 parent c3399bf commit afe7571
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/jsdoc/tag/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') );
}

Expand Down
14 changes: 14 additions & 0 deletions test/specs/jsdoc/tag/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,27 @@ 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);

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);
Expand Down

0 comments on commit afe7571

Please sign in to comment.