Skip to content

Commit 67f8d9e

Browse files
committed
Fix overeager JS filtering in polyglot mode.
Fixes #363
1 parent c8ad087 commit 67f8d9e

File tree

4 files changed

+120
-4
lines changed

4 files changed

+120
-4
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ module.exports = function (indexes, options, callback) {
102102
filterAccess(options.access,
103103
hierarchy(
104104
inputs
105-
.filter(filterJS(options.extension))
105+
.filter(filterJS(options.extension, options.polyglot))
106106
.reduce(function (memo, file) {
107107
return memo.concat(parseFn(file));
108108
}, [])
@@ -160,7 +160,7 @@ module.exports.lint = function lint(indexes, options, callback) {
160160
callback(null,
161161
formatLint(hierarchy(
162162
inputs
163-
.filter(filterJS(options.extension))
163+
.filter(filterJS(options.extension, options.polyglot))
164164
.reduce(function (memo, file) {
165165
return memo.concat(parseFn(file));
166166
}, [])

lib/filter_js.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@ var path = require('path');
99
* This creates a filter function for use with Array.prototype.filter, which
1010
* expect as argument a file as an objectg with the 'file' property
1111
*
12-
* @public
12+
* @private
1313
* @param {String|Array} extensions to be filtered
14+
* @param {boolean} allowAll ignore the entire extension check and always
15+
* pass through files. This is used by the polglot mode.
1416
* @return {Function} a filter function, this function returns true if the input filename extension
1517
* is in the extension whitelist
1618
*/
17-
function filterJS(extensions) {
19+
function filterJS(extensions, allowAll) {
20+
21+
if (allowAll) {
22+
return function () {
23+
return true;
24+
};
25+
}
1826

1927
extensions = extensions || [];
2028
if (typeof extensions === 'string') {

test/bin.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@ test('defaults to parsing package.json main', function (t) {
5858
});
5959
}, options);
6060

61+
test('polyglot mode', function (t) {
62+
documentation(['build fixture/polyglot/blend.cpp --polyglot'],
63+
function (err, data) {
64+
t.ifError(err);
65+
if (process.env.UPDATE) {
66+
fs.writeFileSync(
67+
path.resolve(__dirname,
68+
'fixture',
69+
'polyglot/blend.json'), JSON.stringify(normalize(data), null, 2), 'utf8');
70+
}
71+
var expected = fs.readFileSync(
72+
path.resolve(__dirname,
73+
'fixture',
74+
'polyglot/blend.json'), 'utf8');
75+
t.deepEqual(
76+
normalize(data),
77+
JSON.parse(expected),
78+
'parsed C++ file');
79+
t.end();
80+
});
81+
}, options);
82+
6183
test('accepts config file', function (t) {
6284
documentation(['build fixture/sorting/input.js -c fixture/config.json'],
6385
function (err, data) {

test/fixture/polyglot/blend.json

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
[
2+
{
3+
"description": "This method moves a hex to a color",
4+
"tags": [
5+
{
6+
"title": "name",
7+
"description": null,
8+
"lineNumber": 2,
9+
"name": "hexToUInt32Color"
10+
},
11+
{
12+
"title": "param",
13+
"description": null,
14+
"lineNumber": 3,
15+
"type": {
16+
"type": "NameExpression",
17+
"name": "string"
18+
},
19+
"name": "hex"
20+
},
21+
{
22+
"title": "returns",
23+
"description": "color",
24+
"lineNumber": 4,
25+
"type": {
26+
"type": "NameExpression",
27+
"name": "number"
28+
}
29+
}
30+
],
31+
"loc": {
32+
"start": {
33+
"line": 35,
34+
"column": 1
35+
},
36+
"end": {
37+
"line": 40,
38+
"column": 3
39+
}
40+
},
41+
"context": {
42+
"loc": {
43+
"start": {
44+
"line": 35,
45+
"column": 1
46+
},
47+
"end": {
48+
"line": 40,
49+
"column": 3
50+
}
51+
},
52+
"file": "[path]"
53+
},
54+
"name": "hexToUInt32Color",
55+
"params": [
56+
{
57+
"title": "param",
58+
"description": null,
59+
"lineNumber": 3,
60+
"type": {
61+
"type": "NameExpression",
62+
"name": "string"
63+
},
64+
"name": "hex"
65+
}
66+
],
67+
"returns": [
68+
{
69+
"title": "returns",
70+
"description": "color",
71+
"lineNumber": 4,
72+
"type": {
73+
"type": "NameExpression",
74+
"name": "number"
75+
}
76+
}
77+
],
78+
"members": {
79+
"instance": [],
80+
"static": []
81+
},
82+
"path": [
83+
"hexToUInt32Color"
84+
]
85+
}
86+
]

0 commit comments

Comments
 (0)