@@ -16,7 +16,8 @@ var sort = require('./lib/sort'),
16
16
inferProperties = require ( './lib/infer/properties' ) ,
17
17
inferMembership = require ( './lib/infer/membership' ) ,
18
18
inferReturn = require ( './lib/infer/return' ) ,
19
- lint = require ( './lib/lint' ) ;
19
+ formatLint = require ( './lib/lint' ) . formatLint ,
20
+ lintComments = require ( './lib/lint' ) . lintComments ;
20
21
21
22
/**
22
23
* Build a pipeline of comment handlers.
@@ -45,6 +46,20 @@ function noop(comment) {
45
46
return comment ;
46
47
}
47
48
49
+ /**
50
+ * Given an array of indexes and options for whether to resolve shallow
51
+ * or deep dependencies, resolve dependencies.
52
+ *
53
+ * @param {Array<string>|string } indexes files to process
54
+ * @param {Object } options options
55
+ * @param {Function } callback called with results
56
+ * @returns {undefined }
57
+ */
58
+ function expandInputs ( indexes , options , callback ) {
59
+ var inputFn = ( options . polyglot || options . shallow ) ? shallow : dependency ;
60
+ inputFn ( indexes , options , callback ) ;
61
+ }
62
+
48
63
/**
49
64
* Generate JavaScript documentation as a list of parsed JSDoc
50
65
* comments, given a root file as a path.
@@ -75,25 +90,23 @@ module.exports = function (indexes, options, callback) {
75
90
indexes = [ indexes ] ;
76
91
}
77
92
78
- var inputFn = ( options . polyglot || options . shallow ) ? shallow : dependency ;
79
93
var parseFn = ( options . polyglot ) ? polyglot : parseJavaScript ;
80
94
81
- return inputFn ( indexes , options , function ( error , inputs ) {
95
+ return expandInputs ( indexes , options , function ( error , inputs ) {
82
96
if ( error ) {
83
97
return callback ( error ) ;
84
98
}
85
99
try {
86
100
callback ( null ,
87
101
filterAccess (
88
- ( options . private || options . lint ) ? [ ] : undefined ,
102
+ options . private ? [ ] : undefined ,
89
103
hierarchy (
90
104
inputs
91
105
. filter ( filterJS )
92
106
. reduce ( function ( memo , file ) {
93
107
return memo . concat ( parseFn ( file ) ) ;
94
108
} , [ ] )
95
109
. map ( pipeline (
96
- lint . lint ,
97
110
inferName ( ) ,
98
111
inferKind ( ) ,
99
112
inferParams ( ) ,
@@ -111,6 +124,62 @@ module.exports = function (indexes, options, callback) {
111
124
} ) ;
112
125
} ;
113
126
127
+ /**
128
+ * Lint files for non-standard or incorrect documentation
129
+ * information, returning a potentially-empty string
130
+ * of lint information intended for human-readable output.
131
+ *
132
+ * @param {Array<string>|string } indexes files to process
133
+ * @param {Object } options options
134
+ * @param {Array<string> } options.external a string regex / glob match pattern
135
+ * that defines what external modules will be whitelisted and included in the
136
+ * generated documentation.
137
+ * @param {Array<string> } options.transform source transforms given as strings
138
+ * passed to [the module-deps transform option](https://github.com/substack/module-deps)
139
+ * @param {boolean } [options.polyglot=false] parse comments with a regex rather than
140
+ * a proper parser. This enables support of non-JavaScript languages but
141
+ * reduces documentation's ability to infer structure of code.
142
+ * @param {boolean } [options.shallow=false] whether to avoid dependency parsing
143
+ * even in JavaScript code. With the polyglot option set, this has no effect.
144
+ * @param {Function } callback to be called when the documentation generation
145
+ * is complete, with (err, result) argumentsj
146
+ * @returns {undefined } calls callback
147
+ */
148
+ module . exports . lint = function lint ( indexes , options , callback ) {
149
+ options = options || { } ;
150
+
151
+ if ( typeof indexes === 'string' ) {
152
+ indexes = [ indexes ] ;
153
+ }
154
+
155
+ var parseFn = ( options . polyglot ) ? polyglot : parseJavaScript ;
156
+
157
+ return expandInputs ( indexes , options , function ( error , inputs ) {
158
+ if ( error ) {
159
+ return callback ( error ) ;
160
+ }
161
+ callback ( null ,
162
+ formatLint ( hierarchy (
163
+ inputs
164
+ . filter ( filterJS )
165
+ . reduce ( function ( memo , file ) {
166
+ return memo . concat ( parseFn ( file ) ) ;
167
+ } , [ ] )
168
+ . map ( pipeline (
169
+ lintComments ,
170
+ inferName ( ) ,
171
+ inferKind ( ) ,
172
+ inferParams ( ) ,
173
+ inferProperties ( ) ,
174
+ inferReturn ( ) ,
175
+ inferMembership ( ) ,
176
+ nest ) )
177
+ . filter ( Boolean ) ) ) ) ;
178
+ } ) ;
179
+ } ;
180
+
181
+ module . exports . expandInputs = expandInputs ;
182
+
114
183
module . exports . formats = {
115
184
html : require ( './lib/output/html' ) ,
116
185
md : require ( './lib/output/markdown' ) ,
0 commit comments