Simplify extension check, add coverage

This commit is contained in:
Tom MacWright 2015-11-24 13:00:32 -05:00
parent 356616ea1e
commit cd0e8143db
4 changed files with 23 additions and 15 deletions

View File

@ -161,7 +161,7 @@ module.exports.lint = function lint(indexes, options, callback) {
callback(null,
formatLint(hierarchy(
inputs
.filter(filterJS)
.filter(filterJS(options.extension))
.reduce(function (memo, file) {
return memo.concat(parseFn(file));
}, [])

View File

@ -1,9 +1,11 @@
'use strict';
var path = require('path');
/**
* Node & browserify support requiring JSON files. JSON files can't be documented
* with JSDoc or parsed with espree, so we filter them out before
* they reach documentation's machinery.
* they reach documentation's machinery.
* This creates a filter function for use with Array.prototype.filter, which
* expect as argument a file as an objectg with the 'file' property
*
@ -13,22 +15,15 @@
* is in the extension whitelist
*/
function filterJS(extensions) {
if (!(extensions instanceof Array)) {
extensions = typeof extensions === 'string' ? [extensions] : [];
}
extensions.push('js');
extensions = extensions || [];
if (typeof extensions === 'string') {
extensions = [extensions];
}
extensions = extensions.concat('js');
return function (data) {
var extension;
for (var i = 0; i < extensions.length; i++) {
extension = extensions[i];
if (data.file.slice(-(extension.length + 1)) === '.' + extension) {
return true;
}
}
return false;
return extensions.indexOf(path.extname(data.file).substring(1)) !== -1;
};
}

View File

@ -96,6 +96,15 @@ test('external modules option', function (t) {
});
});
test('extension option', function (t) {
documentation(['build fixture/extension/jsx.jsx ' +
'--extension=jsx'], function (err, data) {
t.ifError(err);
t.equal(data.length, 1, 'includes jsx file');
t.end();
});
});
test('invalid arguments', function (group) {
group.test('bad -f option', function (t) {
documentation(['build -f DOES-NOT-EXIST fixture/internal.input.js'], function (err) {

View File

@ -0,0 +1,4 @@
/**
* apples
*/
function apples() {}