From 74b9bd4e0e72ba3f1099254cd68cd5baadcc1d45 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Thu, 1 Oct 2015 18:24:04 -0400 Subject: [PATCH] Fix tests for new error strategy --- index.js | 5 +---- lib/hierarchy.js | 2 -- lib/lint.js | 2 -- lib/output/json.js | 9 +++++++++ lib/parse.js | 3 ++- test/lib/error.js | 3 +-- test/lib/lint.js | 8 ++++---- test/{streams/parse.js => lib/parsers/javascript.js} | 6 +++--- test/lib/polyglot.js | 1 + test/test.js | 1 + 10 files changed, 22 insertions(+), 18 deletions(-) rename test/{streams/parse.js => lib/parsers/javascript.js} (78%) diff --git a/index.js b/index.js index a3a0d29..d24bf85 100644 --- a/index.js +++ b/index.js @@ -52,15 +52,12 @@ module.exports = function (indexes, options, callback) { return inputStream.pipe(concat(function (inputs) { try { - var errors = []; - var docs = inputs .filter(filterJS) .reduce(function (memo, file) { return memo.concat(parse(file)); }, []) .map(function (comment) { - comment.errors = []; // compose nesting & membership to avoid intermediate arrays comment = nestParams(inferMembership(inferKind(inferName(lint(comment))))); if (options.github) { @@ -71,7 +68,7 @@ module.exports = function (indexes, options, callback) { .sort(sort.bind(undefined, options.order)) .filter(filterAccess.bind(undefined, options.private ? [] : undefined)); - callback(null, docs, errors); + callback(null, docs); } catch (e) { callback(e); } diff --git a/lib/hierarchy.js b/lib/hierarchy.js index c9c1a8d..c307162 100644 --- a/lib/hierarchy.js +++ b/lib/hierarchy.js @@ -1,7 +1,5 @@ 'use strict'; -var error = require('../lib/error'); - /** * Add paths to each comment, making it possible to generate permalinks * that differentiate between instance functions with the same name but diff --git a/lib/lint.js b/lib/lint.js index 861695d..016fa3a 100644 --- a/lib/lint.js +++ b/lib/lint.js @@ -1,7 +1,5 @@ 'use strict'; -var error = require('../lib/error'); - var CANONICAL = { 'String': 'string', 'Boolean': 'boolean', diff --git a/lib/output/json.js b/lib/output/json.js index 977fd51..ed45a36 100644 --- a/lib/output/json.js +++ b/lib/output/json.js @@ -13,5 +13,14 @@ * @return {undefined} calls callback */ module.exports = function (comments, opts, callback) { + + opts = opts || {}; + + if (!opts.preserveErrors) { + comments.forEach(function (comment) { + delete comment.errors; + }); + } + return callback(null, JSON.stringify(comments, null, 2)); }; diff --git a/lib/parse.js b/lib/parse.js index 72371c9..5070eaf 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -30,6 +30,7 @@ module.exports = function (comment, loc, context) { result.loc = loc; result.context = context; + result.errors = []; var i = 0; var errors = []; @@ -37,7 +38,7 @@ module.exports = function (comment, loc, context) { var tag = result.tags[i]; if (tag.errors) { for (var j = 0; j < tag.errors.length; j++) { - errors.push(error(tag, result, tag.errors[j])); + result.errors.push(tag.errors[j]); } result.tags.splice(i, 1); } else { diff --git a/test/lib/error.js b/test/lib/error.js index 51600f5..e95bc3c 100644 --- a/test/lib/error.js +++ b/test/lib/error.js @@ -20,8 +20,7 @@ test('error', function (t) { } }; - t.deepEqual(error(tag, comment, 'test'), 'file.js:3: test'); - t.deepEqual(error(tag, comment, '%s', 'test'), 'file.js:3: test'); + t.deepEqual(error(comment, 'test'), 'file.js:1: test'); t.end(); }); diff --git a/test/lib/lint.js b/test/lib/lint.js index 045a3e1..0f373f1 100644 --- a/test/lib/lint.js +++ b/test/lib/lint.js @@ -22,9 +22,9 @@ test('lint', function (t) { * @param {array} bar */ return 0; - }), [ - 'input.js:3: type String found, string is standard', - 'input.js:4: type array found, Array is standard'], + }).errors, [ + 'type String found, string is standard', + 'type array found, Array is standard'], 'non-canonical'); t.deepEqual(evaluate(function () { @@ -32,7 +32,7 @@ test('lint', function (t) { * @param {string} foo */ return 0; - }), [], 'no errors'); + }).errors, [], 'no errors'); t.end(); }); diff --git a/test/streams/parse.js b/test/lib/parsers/javascript.js similarity index 78% rename from test/streams/parse.js rename to test/lib/parsers/javascript.js index f227df2..78887dd 100644 --- a/test/streams/parse.js +++ b/test/lib/parsers/javascript.js @@ -1,7 +1,7 @@ 'use strict'; var test = require('tap').test, - parse = require('../../lib/parsers/javascript'); + parse = require('../../../lib/parsers/javascript'); function toComment(fn, filename) { return parse({ @@ -23,7 +23,7 @@ test('parse - error', function (t) { /** @param {foo */ return 0; })[0].errors, [ - 'test.js:2: Braces are not balanced', - 'test.js:2: Missing or invalid tag name']); + 'Braces are not balanced', + 'Missing or invalid tag name']); t.end(); }); diff --git a/test/lib/polyglot.js b/test/lib/polyglot.js index 73f8fa4..46e9591 100644 --- a/test/lib/polyglot.js +++ b/test/lib/polyglot.js @@ -13,6 +13,7 @@ test('polyglot', function (t) { }); delete result[0].context.file; t.deepEqual(result, [{ + errors: [], context: { loc: { end: { column: 3, line: 40 }, start: { column: 1, line: 35 } } }, description: 'This method moves a hex to a color', diff --git a/test/test.js b/test/test.js index fcd8c85..667ee81 100644 --- a/test/test.js +++ b/test/test.js @@ -13,6 +13,7 @@ var UPDATE = !!process.env.UPDATE; function normalize(result) { result.forEach(function (item) { + delete item.errors; item.context.file = path.relative(__dirname, item.context.file); }); return result;