Skip to content

Commit a8581b4

Browse files
Lucas Wojciechowskitmcw
Lucas Wojciechowski
authored andcommitted
Fix exception when formatting lint errors
1 parent ab31812 commit a8581b4

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

lib/parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function parseJSDoc(comment, loc, context) {
3636
var tag = result.tags[i];
3737
if (tag.errors) {
3838
for (var j = 0; j < tag.errors.length; j++) {
39-
result.errors.push(tag.errors[j]);
39+
result.errors.push({message: tag.errors[j]});
4040
}
4141
result.tags.splice(i, 1);
4242
} else {

test/lib/lint.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
var test = require('tap').test,
44
parse = require('../../lib/parsers/javascript'),
5-
lint = require('../../lib/lint').lint;
5+
lint = require('../../lib/lint').lint,
6+
format = require('../../lib/lint').format;
67

78
function toComment(fn, filename) {
89
return parse({
@@ -20,8 +21,11 @@ test('lint', function (t) {
2021
/**
2122
* @param {String} foo
2223
* @param {array} bar
24+
* @param {foo
2325
*/
2426
}).errors, [
27+
{ message: 'Braces are not balanced' },
28+
{ message: 'Missing or invalid tag name' },
2529
{ commentLineNumber: 1, message: 'type String found, string is standard' },
2630
{ commentLineNumber: 2, message: 'type array found, Array is standard' }],
2731
'non-canonical');
@@ -40,3 +44,24 @@ test('lint', function (t) {
4044

4145
t.end();
4246
});
47+
48+
test('format', function (t) {
49+
var comment = evaluate(function () {
50+
/**
51+
* @param {String} foo
52+
* @param {array} bar
53+
* @param {foo
54+
*/
55+
});
56+
57+
var formatted = format([comment]);
58+
59+
t.contains(formatted, 'input.js');
60+
t.contains(formatted, /1:1[^\n]+Braces are not balanced/);
61+
t.contains(formatted, /1:1[^\n]+Missing or invalid tag name/);
62+
t.contains(formatted, /3:1[^\n]+type String found, string is standard/);
63+
t.contains(formatted, /4:1[^\n]+type array found, Array is standard/);
64+
t.contains(formatted, '4 warnings');
65+
66+
t.end();
67+
});

test/lib/parsers/javascript.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test('parse - error', function (t) {
2121
t.deepEqual(toComment(function () {
2222
/** @param {foo */
2323
})[0].errors, [
24-
'Braces are not balanced',
25-
'Missing or invalid tag name']);
24+
{ message: 'Braces are not balanced' },
25+
{ message: 'Missing or invalid tag name' }]);
2626
t.end();
2727
});

0 commit comments

Comments
 (0)