documentation/lib/input/shallow.js
Tom Macwright ed5c2a04a4 feat(lint): Identify explicit tags that don't match inference in lint stage
This will flag cases where people explicitly document things in JSDoc that don't reflect the code
reality - in many cases, misnamed parameter names in documentation tags.

Fixes https://github.com/documentationjs/documentation/issues/575
2017-05-01 14:26:00 -04:00

47 lines
1.3 KiB
JavaScript

'use strict';
/* @flow */
var smartGlob = require('../smart_glob.js');
/**
* A readable source for content that doesn't do dependency resolution, but
* simply reads files and pushes them onto a stream.
*
* If an array of strings is provided as input to this method, then
* they will be treated as filenames and read into the stream.
*
* If an array of objects is provided, then we assume that they are valid
* objects with `source` and `file` properties, and don't use the filesystem
* at all. This is one way of getting documentation.js to run in a browser
* or without fs access.
*
* @param indexes entry points
* @param config parsing options
* @return promise with parsed files
*/
module.exports = function(
indexes /*: Array<string|Object>*/,
config /*: DocumentationConfig */
) /*: Promise<Array<SourceFile>>*/ {
var objects = [];
var strings = [];
for (var index of indexes) {
if (typeof index === 'string') {
strings.push(index);
} else if (typeof index === 'object') {
objects.push(index);
} else {
return Promise.reject(
new Error('Indexes should be either strings or objects')
);
}
}
return Promise.resolve(
objects.concat(
smartGlob(strings, config.parseExtension).map(file => ({
file
}))
)
);
};