Code coverage report for master/lib/jsdoc/tag/validator.js

Statements: 95.45% (21 / 22)      Branches: 91.3% (21 / 23)      Functions: 100% (2 / 2)      Lines: 95.45% (21 / 22)      Ignored: none     

All files » master/lib/jsdoc/tag/ » validator.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57                  1 1 1 1   1 17   17 5   17           1   5929   42 2       42       5887     5887 3       5884 8     5876 4        
/**
    @module jsdoc/tag/validator
    @requires jsdoc/tag/dictionary
 
    @author Michael Mathews <micmath@gmail.com>
    @license Apache License 2.0 - See file 'LICENSE.md' in this project.
 */
'use strict';
 
var dictionary = require('jsdoc/tag/dictionary');
var env = require('jsdoc/env');
var format = require('util').format;
var logger = require('jsdoc/util/logger');
 
function buildMessage(tagName, meta, desc) {
    var result = format('The @%s tag %s. File: %s, line: %s', tagName, desc, meta.filename,
        meta.lineno);
    if (meta.comment) {
        result += '\n' + meta.comment;
    }
    return result;
}
 
/**
 * Validate the given tag.
 */
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) {
            logger.error( buildMessage(tag.title, meta, 'is not a known tag') );
        }
 
        // stop validation, since there's nothing to validate against
        return;
    }
 
    // check for errors that make the tag useless
    Iif (!tagDef && !env.conf.tags.allowUnknownTags) {
        logger.error( buildMessage(tag.title, meta, 'is not a known tag') );
    }
    else if (!tag.text && tagDef.mustHaveValue) {
        logger.error( buildMessage(tag.title, meta, 'requires a value') );
    }
 
    // check for minor issues that are usually harmless
    else if (tag.text && tagDef.mustNotHaveValue) {
        logger.warn( buildMessage(tag.title, meta,
            'does not permit a value; the value will be ignored') );
    }
    else if (tag.value && tag.value.description && tagDef.mustNotHaveDescription) {
        logger.warn( buildMessage(tag.title, meta,
            'does not permit a description; the description will be ignored') );
    }
};