Skip to content

Commit 74b9bd4

Browse files
committed
Fix tests for new error strategy
1 parent a848202 commit 74b9bd4

File tree

10 files changed

+22
-18
lines changed

10 files changed

+22
-18
lines changed

index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,12 @@ module.exports = function (indexes, options, callback) {
5252
return inputStream.pipe(concat(function (inputs) {
5353
try {
5454

55-
var errors = [];
56-
5755
var docs = inputs
5856
.filter(filterJS)
5957
.reduce(function (memo, file) {
6058
return memo.concat(parse(file));
6159
}, [])
6260
.map(function (comment) {
63-
comment.errors = [];
6461
// compose nesting & membership to avoid intermediate arrays
6562
comment = nestParams(inferMembership(inferKind(inferName(lint(comment)))));
6663
if (options.github) {
@@ -71,7 +68,7 @@ module.exports = function (indexes, options, callback) {
7168
.sort(sort.bind(undefined, options.order))
7269
.filter(filterAccess.bind(undefined, options.private ? [] : undefined));
7370

74-
callback(null, docs, errors);
71+
callback(null, docs);
7572
} catch (e) {
7673
callback(e);
7774
}

lib/hierarchy.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
var error = require('../lib/error');
4-
53
/**
64
* Add paths to each comment, making it possible to generate permalinks
75
* that differentiate between instance functions with the same name but

lib/lint.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
var error = require('../lib/error');
4-
53
var CANONICAL = {
64
'String': 'string',
75
'Boolean': 'boolean',

lib/output/json.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,14 @@
1313
* @return {undefined} calls callback
1414
*/
1515
module.exports = function (comments, opts, callback) {
16+
17+
opts = opts || {};
18+
19+
if (!opts.preserveErrors) {
20+
comments.forEach(function (comment) {
21+
delete comment.errors;
22+
});
23+
}
24+
1625
return callback(null, JSON.stringify(comments, null, 2));
1726
};

lib/parse.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ module.exports = function (comment, loc, context) {
3030

3131
result.loc = loc;
3232
result.context = context;
33+
result.errors = [];
3334

3435
var i = 0;
3536
var errors = [];
3637
while (i < result.tags.length) {
3738
var tag = result.tags[i];
3839
if (tag.errors) {
3940
for (var j = 0; j < tag.errors.length; j++) {
40-
errors.push(error(tag, result, tag.errors[j]));
41+
result.errors.push(tag.errors[j]);
4142
}
4243
result.tags.splice(i, 1);
4344
} else {

test/lib/error.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ test('error', function (t) {
2020
}
2121
};
2222

23-
t.deepEqual(error(tag, comment, 'test'), 'file.js:3: test');
24-
t.deepEqual(error(tag, comment, '%s', 'test'), 'file.js:3: test');
23+
t.deepEqual(error(comment, 'test'), 'file.js:1: test');
2524

2625
t.end();
2726
});

test/lib/lint.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ test('lint', function (t) {
2222
* @param {array} bar
2323
*/
2424
return 0;
25-
}), [
26-
'input.js:3: type String found, string is standard',
27-
'input.js:4: type array found, Array is standard'],
25+
}).errors, [
26+
'type String found, string is standard',
27+
'type array found, Array is standard'],
2828
'non-canonical');
2929

3030
t.deepEqual(evaluate(function () {
3131
/**
3232
* @param {string} foo
3333
*/
3434
return 0;
35-
}), [], 'no errors');
35+
}).errors, [], 'no errors');
3636

3737
t.end();
3838
});

test/streams/parse.js renamed to test/lib/parsers/javascript.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
var test = require('tap').test,
4-
parse = require('../../lib/parsers/javascript');
4+
parse = require('../../../lib/parsers/javascript');
55

66
function toComment(fn, filename) {
77
return parse({
@@ -23,7 +23,7 @@ test('parse - error', function (t) {
2323
/** @param {foo */
2424
return 0;
2525
})[0].errors, [
26-
'test.js:2: Braces are not balanced',
27-
'test.js:2: Missing or invalid tag name']);
26+
'Braces are not balanced',
27+
'Missing or invalid tag name']);
2828
t.end();
2929
});

test/lib/polyglot.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ test('polyglot', function (t) {
1313
});
1414
delete result[0].context.file;
1515
t.deepEqual(result, [{
16+
errors: [],
1617
context: {
1718
loc: { end: { column: 3, line: 40 }, start: { column: 1, line: 35 } } },
1819
description: 'This method moves a hex to a color',

test/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var UPDATE = !!process.env.UPDATE;
1313

1414
function normalize(result) {
1515
result.forEach(function (item) {
16+
delete item.errors;
1617
item.context.file = path.relative(__dirname, item.context.file);
1718
});
1819
return result;

0 commit comments

Comments
 (0)