mirror of
https://github.com/documentationjs/documentation.git
synced 2026-01-25 14:26:29 +00:00
Simplify extension check, add coverage
This commit is contained in:
parent
356616ea1e
commit
cd0e8143db
2
index.js
2
index.js
@ -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));
|
||||
}, [])
|
||||
|
||||
@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
4
test/fixture/extension/jsx.jsx
Normal file
4
test/fixture/extension/jsx.jsx
Normal file
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* apples
|
||||
*/
|
||||
function apples() {}
|
||||
Loading…
x
Reference in New Issue
Block a user