Skip to content

Commit d7f06fa

Browse files
committed
Store commentLineNumber on errors. Fixes #159
cc @jfirebaugh for the review
1 parent a65801a commit d7f06fa

23 files changed

+125
-35
lines changed

bin/documentation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var documentation = require('../'),
66
streamArray = require('stream-array'),
77
fs = require('fs'),
88
vfs = require('vinyl-fs'),
9-
formatError = require('../lib/error'),
9+
formatError = require('../lib/format_error'),
1010
args = require('../lib/args.js');
1111

1212
var parsedArgs = args(process.argv.slice(2)),

lib/error.js renamed to lib/format_error.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ var path = require('path');
1313
*/
1414
module.exports = function (comment, error) {
1515
var relativePath = path.relative(process.cwd(), comment.context.file),
16-
lineNumber = comment.loc.start.line;
16+
lineNumber = comment.loc.start.line + (error.commentLineNumber || 0);
1717

18-
return format.apply(format, ['%s:%d: ' + error, relativePath, lineNumber]
18+
return format.apply(format, ['%s:%d: ' + error.message, relativePath, lineNumber]
1919
.concat(Array.prototype.slice.call(arguments, 3)));
2020
};

lib/hierarchy.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,18 @@ function inferHierarchy(comments) {
5555
continue;
5656
}
5757

58+
var memberOfTag = comment.tags.filter(function (tag) {
59+
return tag.title === 'memberof'
60+
})[0];
61+
var memberOfTagLineNumber = (memberOfTag && memberOfTag.lineNumber) || 0;
62+
5863
var parent = nameIndex[comment.memberof];
5964

6065
if (!parent) {
61-
comment.errors.push('memberof reference to ' + comment.memberof + ' not found');
66+
comment.errors.push({
67+
message: 'memberof reference to ' + comment.memberof + ' not found',
68+
commentLineNumber: memberOfTagLineNumber
69+
});
6270
continue;
6371
}
6472

@@ -70,7 +78,10 @@ function inferHierarchy(comments) {
7078

7179
default:
7280
if (!comment.scope) {
73-
parent.errors.push('found memberof but no @scope, @static, or @instance tag');
81+
parent.errors.push({
82+
message: 'found memberof but no @scope, @static, or @instance tag',
83+
commentLineNumber: memberOfTagLineNumber
84+
});
7485
continue;
7586
}
7687
parent.members[comment.scope].push(comment);

lib/lint.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ module.exports = function (comment) {
2121
comment.tags.forEach(function (tag) {
2222
function nameInvariant(name) {
2323
if (CANONICAL[name]) {
24-
comment.errors.push(
25-
'type ' + name + ' found, ' + CANONICAL[name] + ' is standard');
24+
comment.errors.push({
25+
message: 'type ' + name + ' found, ' + CANONICAL[name] + ' is standard',
26+
commentLineNumber: tag.lineNumber
27+
});
2628
}
2729
}
2830

lib/nest_params.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ module.exports = function (comment) {
3030
if (parts.length > 1) {
3131
var parent = index[parts[0]];
3232
if (parent === undefined) {
33-
result.errors.push(
34-
'@param ' + param.name + '\'s parent ' + parts[0] + ' not found');
33+
result.errors.push({
34+
message: '@param ' + param.name + '\'s parent ' + parts[0] + ' not found',
35+
commentLineNumber: param.lineNumber
36+
});
3537
result.params.push(param);
3638
return;
3739
}

test/fixture/_external-deps-included.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
"code": "/**\n * This function returns the number one.\n * @return {Number} numberone\n */\nmodule.exports = function () {\n // this returns 1\n return 1;\n};\n"
3737
},
3838
"errors": [
39-
"memberof reference to module not found"
39+
{
40+
"message": "memberof reference to module not found",
41+
"commentLineNumber": 0
42+
}
4043
],
4144
"returns": [
4245
{
@@ -99,7 +102,10 @@
99102
"code": "'use strict';\n\nvar otherDep = require('external2');\n\n/**\n * This function returns the number one.\n * @return {Number} numberone\n */\nmodule.exports = function () {\n // this returns 1\n return otherDep() - 1;\n};\n"
100103
},
101104
"errors": [
102-
"memberof reference to module not found"
105+
{
106+
"message": "memberof reference to module not found",
107+
"commentLineNumber": 0
108+
}
103109
],
104110
"returns": [
105111
{

test/fixture/_multi-file-input.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
"code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nmodule.exports = function () {\n // this returns 1\n return 1;\n};\n"
3737
},
3838
"errors": [
39-
"memberof reference to module not found"
39+
{
40+
"message": "memberof reference to module not found",
41+
"commentLineNumber": 0
42+
}
4043
],
4144
"returns": [
4245
{
@@ -114,7 +117,10 @@
114117
"code": "/**\n * This function returns the number plus two.\n *\n * @param {Number} a the number\n * @returns {Number} numbertwo\n * @example\n * var result = returnTwo(4);\n * // result is 6\n */\nfunction returnTwo(a) {\n // this returns a + 2\n return a + 2;\n}\n"
115118
},
116119
"errors": [
117-
"type Number found, number is standard"
120+
{
121+
"message": "type Number found, number is standard",
122+
"commentLineNumber": 3
123+
}
118124
],
119125
"params": [
120126
{

test/fixture/factory.output.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@
148148
"code": "/**\n * an area chart generator\n * @returns {area} chart\n */\nvar area = function() {\n\n /**\n * @class area\n */\n var chart = function(selection) {\n };\n\n /**\n * Sets the chart data.\n * @method\n */\n chart.data = function(_) {\n };\n\n return chart;\n};\n"
149149
},
150150
"errors": [
151-
"memberof reference to chart not found"
151+
{
152+
"message": "memberof reference to chart not found",
153+
"commentLineNumber": 0
154+
}
152155
],
153156
"function": null,
154157
"name": "data",

test/fixture/inline-link.output.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@
127127
"code": "/**\n * Adds one to a number\n * @param {number} a the input\n * @returns {number} the output\n */\nfunction addOne(a) {\n return a + 1;\n}\n\n/**\n * This function returns the number one. Internally, this uses\n * {@link addOne} to do the math.\n * @param {number} a the input\n * @returns {number} numberone\n */\nmodule.exports = function (a) {\n return addOne(a);\n};\n"
128128
},
129129
"errors": [
130-
"memberof reference to module not found"
130+
{
131+
"message": "memberof reference to module not found",
132+
"commentLineNumber": 0
133+
}
131134
],
132135
"params": [
133136
{

test/fixture/jsx.output.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
"code": "var util = require('util');\n\n/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nmodule.exports = (<p>hello</p>);\n"
3737
},
3838
"errors": [
39-
"memberof reference to module not found"
39+
{
40+
"message": "memberof reference to module not found",
41+
"commentLineNumber": 0
42+
}
4043
],
4144
"returns": [
4245
{

0 commit comments

Comments
 (0)