add a strict validation option (defaults to true) that controls whether validation errors are fatal (issue #134)

This commit is contained in:
Jeff Williams 2012-07-02 22:52:46 -07:00
parent aad1a85ffd
commit c095b6e20c
3 changed files with 52 additions and 2 deletions

View File

@ -12,7 +12,8 @@ var common = {
var argParser = new common.args.ArgParser(), var argParser = new common.args.ArgParser(),
ourOptions, ourOptions,
defaults = { defaults = {
destination: './out/' destination: './out/',
strict: true
}; };
argParser.addOption('t', 'template', true, 'The name of the template to use. Default: the "default" template'); argParser.addOption('t', 'template', true, 'The name of the template to use. Default: the "default" template');
@ -22,6 +23,7 @@ argParser.addOption('T', 'test', false, 'Run all tests and quit.');
argParser.addOption('d', 'destination', true, 'The path to the output folder. Use "console" to dump data to the console. Default: console'); argParser.addOption('d', 'destination', true, 'The path to the output folder. Use "console" to dump data to the console. Default: console');
argParser.addOption('p', 'private', false, 'Display symbols marked with the @private tag. Default: false.'); argParser.addOption('p', 'private', false, 'Display symbols marked with the @private tag. Default: false.');
argParser.addOption('r', 'recurse', false, 'Recurse into subdirectories when scanning for source code files.'); argParser.addOption('r', 'recurse', false, 'Recurse into subdirectories when scanning for source code files.');
argParser.addOption('s', 'strict', false, 'Exit immediately if a doclet is incomplete or contains errors. Default: true');
argParser.addOption('h', 'help', false, 'Print this message and quit.'); argParser.addOption('h', 'help', false, 'Print this message and quit.');
argParser.addOption('X', 'explain', false, 'Dump all found doclet internals to console and quit.'); argParser.addOption('X', 'explain', false, 'Dump all found doclet internals to console and quit.');
argParser.addOption('q', 'query', true, 'Provide a querystring to define custom variable names/values to add to the options hash.'); argParser.addOption('q', 'query', true, 'Provide a querystring to define custom variable names/values to add to the options hash.');

View File

@ -91,7 +91,17 @@ exports.Tag = function(tagTitle, tagBody, meta) {
} }
} }
jsdoc.tag.validator.validate(this, meta); // validate the tag. for strict validation, throw an exception; otherwise, log a warning.
try {
jsdoc.tag.validator.validate(this, meta);
}
catch (e) {
if (env.opts.strict) {
throw e;
} else {
console.log(e);
}
}
} }
function trim(text, newlines) { function trim(text, newlines) {

38
test/specs/jsdoc/tag.js Normal file
View File

@ -0,0 +1,38 @@
/*global describe: true, env: true, it: true */
describe("jsdoc/tag", function() {
// TODO: more tests
function badTag() {
var Tag = require("jsdoc/tag").Tag;
var tag = new Tag("name");
return tag;
}
it("has strict validation enabled by default", function() {
expect(badTag).toThrow();
});
it("throws an exception for bad tags if strict validation is enabled", function() {
var strict = !!env.opts.strict;
env.opts.strict = true;
expect(badTag).toThrow();
env.opts.strict = strict;
});
it("doesn't throw an exception for bad tags if strict validation is disabled", function() {
/*jshint evil: true */
var strict = !!env.opts.strict,
log = new Function(console.log);
console.log = function() {};
env.opts.strict = false;
expect(badTag).not.toThrow();
env.opts.strict = strict;
console.log = log;
});
});