From 67f8d9ead9b6beeebfb23ebb2bcaaf439c0d06d2 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Sat, 19 Mar 2016 16:03:37 -0400 Subject: [PATCH] Fix overeager JS filtering in polyglot mode. Fixes #363 --- index.js | 4 +- lib/filter_js.js | 12 ++++- test/bin.js | 22 ++++++++ test/fixture/polyglot/blend.json | 86 ++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 test/fixture/polyglot/blend.json diff --git a/index.js b/index.js index 9cd3f72..2042c7c 100644 --- a/index.js +++ b/index.js @@ -102,7 +102,7 @@ module.exports = function (indexes, options, callback) { filterAccess(options.access, hierarchy( inputs - .filter(filterJS(options.extension)) + .filter(filterJS(options.extension, options.polyglot)) .reduce(function (memo, file) { return memo.concat(parseFn(file)); }, []) @@ -160,7 +160,7 @@ module.exports.lint = function lint(indexes, options, callback) { callback(null, formatLint(hierarchy( inputs - .filter(filterJS(options.extension)) + .filter(filterJS(options.extension, options.polyglot)) .reduce(function (memo, file) { return memo.concat(parseFn(file)); }, []) diff --git a/lib/filter_js.js b/lib/filter_js.js index 1fa9163..589c31f 100644 --- a/lib/filter_js.js +++ b/lib/filter_js.js @@ -9,12 +9,20 @@ var path = require('path'); * This creates a filter function for use with Array.prototype.filter, which * expect as argument a file as an objectg with the 'file' property * - * @public + * @private * @param {String|Array} extensions to be filtered + * @param {boolean} allowAll ignore the entire extension check and always + * pass through files. This is used by the polglot mode. * @return {Function} a filter function, this function returns true if the input filename extension * is in the extension whitelist */ -function filterJS(extensions) { +function filterJS(extensions, allowAll) { + + if (allowAll) { + return function () { + return true; + }; + } extensions = extensions || []; if (typeof extensions === 'string') { diff --git a/test/bin.js b/test/bin.js index 72960dc..5c5b96e 100644 --- a/test/bin.js +++ b/test/bin.js @@ -58,6 +58,28 @@ test('defaults to parsing package.json main', function (t) { }); }, options); +test('polyglot mode', function (t) { + documentation(['build fixture/polyglot/blend.cpp --polyglot'], + function (err, data) { + t.ifError(err); + if (process.env.UPDATE) { + fs.writeFileSync( + path.resolve(__dirname, + 'fixture', + 'polyglot/blend.json'), JSON.stringify(normalize(data), null, 2), 'utf8'); + } + var expected = fs.readFileSync( + path.resolve(__dirname, + 'fixture', + 'polyglot/blend.json'), 'utf8'); + t.deepEqual( + normalize(data), + JSON.parse(expected), + 'parsed C++ file'); + t.end(); + }); +}, options); + test('accepts config file', function (t) { documentation(['build fixture/sorting/input.js -c fixture/config.json'], function (err, data) { diff --git a/test/fixture/polyglot/blend.json b/test/fixture/polyglot/blend.json new file mode 100644 index 0000000..6f73cde --- /dev/null +++ b/test/fixture/polyglot/blend.json @@ -0,0 +1,86 @@ +[ + { + "description": "This method moves a hex to a color", + "tags": [ + { + "title": "name", + "description": null, + "lineNumber": 2, + "name": "hexToUInt32Color" + }, + { + "title": "param", + "description": null, + "lineNumber": 3, + "type": { + "type": "NameExpression", + "name": "string" + }, + "name": "hex" + }, + { + "title": "returns", + "description": "color", + "lineNumber": 4, + "type": { + "type": "NameExpression", + "name": "number" + } + } + ], + "loc": { + "start": { + "line": 35, + "column": 1 + }, + "end": { + "line": 40, + "column": 3 + } + }, + "context": { + "loc": { + "start": { + "line": 35, + "column": 1 + }, + "end": { + "line": 40, + "column": 3 + } + }, + "file": "[path]" + }, + "name": "hexToUInt32Color", + "params": [ + { + "title": "param", + "description": null, + "lineNumber": 3, + "type": { + "type": "NameExpression", + "name": "string" + }, + "name": "hex" + } + ], + "returns": [ + { + "title": "returns", + "description": "color", + "lineNumber": 4, + "type": { + "type": "NameExpression", + "name": "number" + } + } + ], + "members": { + "instance": [], + "static": [] + }, + "path": [ + "hexToUInt32Color" + ] + } +] \ No newline at end of file