Skip to content

Commit e67b5d2

Browse files
committed
Use walk where appropriate
1 parent a5b94ac commit e67b5d2

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

bin/documentation.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var documentation = require('../'),
88
streamArray = require('stream-array'),
99
fs = require('fs'),
1010
vfs = require('vinyl-fs'),
11+
walk = require('../lib/walk'),
1112
formatError = require('../lib/format_error'),
1213
args = require('../lib/args.js');
1314

@@ -16,18 +17,18 @@ var parsedArgs = args(process.argv.slice(2)),
1617
outputLocation = parsedArgs.output,
1718
formatter = documentation.formats[parsedArgs.formatter];
1819

19-
documentation(parsedArgs.inputs, parsedArgs.options, function (err, result) {
20+
documentation(parsedArgs.inputs, parsedArgs.options, function (err, comments) {
2021
if (err) {
2122
throw err;
2223
}
2324

24-
result.forEach(function (comment) {
25+
walk(comments, function (comment) {
2526
comment.errors.forEach(function (error) {
2627
console.error(formatError(comment, error));
2728
});
2829
});
2930

30-
formatter(result, formatterOptions, function (err, output) {
31+
formatter(comments, formatterOptions, function (err, output) {
3132
if (outputLocation !== 'stdout') {
3233
if (parsedArgs.formatter === 'html') {
3334
streamArray(output).pipe(vfs.dest(outputLocation));

lib/output/json.js

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

3+
var walk = require('../walk');
4+
35
/**
46
* Formats documentation as a JSON string.
57
*
@@ -14,7 +16,7 @@ module.exports = function (comments, opts, callback) {
1416
opts = opts || {};
1517

1618
if (!opts.preserveErrors) {
17-
comments.forEach(function (comment) {
19+
walk(comments, function (comment) {
1820
delete comment.errors;
1921
});
2022
}

lib/walk.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
*
55
* @param {Array<Object>} comments an array of nested comments
66
* @param {Function} fn a walker function
7-
* @returns {undefined} calls fn
7+
* @returns {Array<Object>} comments
88
*/
99
function walk(comments, fn) {
10-
return comments.map(function (comment) {
11-
comment.members.instance = walk(comment.members.instance, fn);
12-
comment.members.static = walk(comment.members.static, fn);
13-
return fn(comment);
10+
comments.forEach(function (comment) {
11+
for (var scope in comment.members) {
12+
walk(comment.members[scope], fn);
13+
}
14+
fn(comment);
1415
});
16+
return comments;
1517
}
1618

1719
module.exports = walk;

test/normalize.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
function normalize(comments) {
2-
comments.forEach(function (comment) {
1+
var walk = require('../lib/walk');
2+
3+
module.exports = function (comments) {
4+
return walk(comments, function (comment) {
35
delete comment.context.file;
46
if (comment.context.github) {
57
comment.context.github = '[github]';
68
}
7-
normalize(comment.members.instance);
8-
normalize(comment.members.static);
99
});
10-
return comments;
1110
}
12-
13-
module.exports = normalize;

0 commit comments

Comments
 (0)