Merge pull request #1159 from kevinoid/allow-unknown-tags-array

Support an Array of tags titles in allowUnknownTags
This commit is contained in:
Jeff Williams 2016-03-21 16:17:40 -07:00
commit 854e7cc9da
2 changed files with 19 additions and 5 deletions

View File

@ -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') );
}
@ -37,10 +40,7 @@ exports.validate = function(tag, tagDef, meta) {
}
// check for errors that make the tag useless
if (!tagDef && !env.conf.tags.allowUnknownTags) {
logger.error( buildMessage(tag.title, meta, 'is not a known tag') );
}
else if (!tag.text && tagDef.mustHaveValue) {
if (!tag.text && tagDef.mustHaveValue) {
logger.error( buildMessage(tag.title, meta, 'requires a value') );
}

View File

@ -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);