Skip to content

Commit 2ed4a79

Browse files
committed
lint filters
1 parent 7e66042 commit 2ed4a79

File tree

9 files changed

+60
-42
lines changed

9 files changed

+60
-42
lines changed

generate/templates/filters/args_info.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
module.exports = function(args) {
2-
var result = [],
3-
cArg,
4-
jsArg;
2+
var result = [];
53

6-
for(cArg = 0, jsArg = 0; cArg < args.length; cArg++) {
4+
for(var cArg = 0, jsArg = 0; cArg < args.length; cArg++) {
75
var arg = args[cArg];
86

97
if (!arg.isReturn && !arg.isSelf) {
@@ -17,13 +15,15 @@ module.exports = function(args) {
1715
arg.firstArg = !arg.lastArg && cArg === 0;
1816

1917
arg.cArg = cArg;
20-
arg.isCppClassStringOrArray = ~["String", "Array"].indexOf(arg.cppClassName);
18+
arg.isCppClassStringOrArray =
19+
~["String", "Array"].indexOf(arg.cppClassName);
2120
arg.isConst = ~arg.cType.indexOf("const ");
2221

23-
// if we have a callback then we also need the corresponding payload for that callback
22+
// if we have a callback then we also need
23+
// the corresponding payload for that callback
2424
if (arg.isCallbackFunction) {
25-
var payload = args.filter(function(payload) {
26-
return payload.payloadFor == arg.name || payload.payloadFor == '*';
25+
var payload = args.filter(function(payload) { // jshint ignore:line
26+
return payload.payloadFor == arg.name || payload.payloadFor == "*";
2727
})[0];
2828

2929
if (payload) {

generate/templates/filters/fields_info.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ module.exports = function(fields) {
77
fieldInfo.__proto__ = field;
88

99
fieldInfo.parsedName = field.name || "result";
10-
fieldInfo.isCppClassIntType = ~["Uint32", "Int32"].indexOf(field.cppClassName);
11-
fieldInfo.parsedClassName = (field.cppClassName || '').toLowerCase() + "_t";
10+
fieldInfo.isCppClassIntType = ~["Uint32", "Int32"]
11+
.indexOf(field.cppClassName);
12+
fieldInfo.parsedClassName = (field.cppClassName || "").toLowerCase() + "_t";
1213

1314
result.push(fieldInfo);
1415
});

generate/templates/filters/has_return_type.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = function(functionInfo) {
22
if (functionInfo.return) {
3-
return functionInfo.return.cType != "void" || functionInfo.return.isErrorCode;
3+
return functionInfo.return.cType != "void" ||
4+
functionInfo.return.isErrorCode;
45
}
56

67
return false;

generate/templates/filters/has_return_value.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module.exports = function(fn) {
2-
if (fn.return
3-
&& !fn.return.isErrorCode
4-
&& fn.return.cType != "void") {
5-
return true
2+
if (fn.return &&
3+
!fn.return.isErrorCode &&
4+
fn.return.cType != "void"
5+
) {
6+
return true;
67
}
78

89
return false;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = function(field) {
2-
return field.name == 'payload' || field.payload || field.payloadFor;
2+
return field.name == "payload" || field.payload || field.payloadFor;
33
};

generate/templates/filters/payload_for.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module.exports = function(fields, payloadForField) {
22
fields = fields || [];
33

44
var result = fields.filter(function (field) {
5-
return field.payloadFor && (field.payloadFor === payloadForField || field.payloadFor === "*");
5+
return field.payloadFor &&
6+
(field.payloadFor === payloadForField || field.payloadFor === "*");
67
});
78

89
if (result.length > 0) {

generate/templates/filters/returns_count.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ module.exports = function(fn) {
44
return currentValue + (arg.isReturn ? 1 : 0);
55
}, 0);
66

7-
if (!result
8-
&& fn.return
9-
&& !fn.return.isErrorCode
10-
&& fn.return.cType != "void") {
7+
if (!result &&
8+
fn.return &&
9+
!fn.return.isErrorCode &&
10+
fn.return.cType != "void"
11+
) {
1112
result = 1;
1213
}
1314

generate/templates/filters/returns_info.js

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,52 @@ module.exports = function(fn, argReturnsOnly, isAsync) {
55
var args = fn.args || [];
66

77
args.forEach(function (arg) {
8-
if (!arg.isReturn) return;
8+
if (!arg.isReturn) {
9+
return;
10+
}
911

1012
var return_info = {};
1113

1214
return_info.__proto__ = arg;
1315

14-
return_info.parsedName = isAsync ? "baton->" + return_info.name : return_info.name;
15-
return_info.isCppClassIntType = ~['Uint32', 'Int32'].indexOf(return_info.cppClassName);
16-
return_info.needsDereference
17-
= isAsync &&
18-
return_info.cppClassName == "Number" &&
19-
isPointer(return_info.cType);
20-
return_info.parsedClassName = (return_info.cppClassName || '').toLowerCase() + "_t";
21-
return_info.returnNameOrName = return_info.returnName || return_info.name;
22-
return_info.jsOrCppClassName = return_info.jsClassName || return_info.cppClassName;
16+
return_info.parsedName =
17+
isAsync ? "baton->" + return_info.name : return_info.name;
18+
return_info.isCppClassIntType =
19+
~["Uint32", "Int32"].indexOf(return_info.cppClassName);
20+
return_info.needsDereference =
21+
isAsync &&
22+
return_info.cppClassName == "Number" &&
23+
isPointer(return_info.cType);
24+
return_info.parsedClassName =
25+
(return_info.cppClassName || "").toLowerCase() + "_t";
26+
return_info.returnNameOrName =
27+
return_info.returnName || return_info.name;
28+
return_info.jsOrCppClassName =
29+
return_info.jsClassName || return_info.cppClassName;
2330
return_info.isOutParam = true;
2431

2532
result.push(return_info);
2633
});
2734

28-
if (!result.length
29-
&& !argReturnsOnly
30-
&& fn.return
31-
&& !fn.return.isErrorCode
32-
&& fn.return.cType != "void") {
35+
if (!result.length &&
36+
!argReturnsOnly &&
37+
fn.return &&
38+
!fn.return.isErrorCode &&
39+
fn.return.cType != "void"
40+
) {
3341
var return_info = {};
3442

3543
return_info.__proto__ = fn.return;
36-
return_info.parsedName = return_info.name && isAsync ? "baton->" + return_info.name : "result";
37-
return_info.isCppClassIntType = ~['Uint32', 'Int32'].indexOf(return_info.cppClassName);
38-
return_info.parsedClassName = (return_info.cppClassName || '').toLowerCase() + "_t";
39-
return_info.returnNameOrName = return_info.returnName || return_info.name;
40-
return_info.jsOrCppClassName = return_info.jsClassName || return_info.cppClassName;
44+
return_info.parsedName =
45+
return_info.name && isAsync ? "baton->" + return_info.name : "result";
46+
return_info.isCppClassIntType =
47+
~["Uint32", "Int32"].indexOf(return_info.cppClassName);
48+
return_info.parsedClassName =
49+
(return_info.cppClassName || "").toLowerCase() + "_t";
50+
return_info.returnNameOrName =
51+
return_info.returnName || return_info.name;
52+
return_info.jsOrCppClassName =
53+
return_info.jsClassName || return_info.cppClassName;
4154

4255
result.push(return_info);
4356
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"generateNativeCode": "node generate/scripts/generateNativeCode",
8484
"install": "node lifecycleScripts/preinstall && node lifecycleScripts/install",
8585
"installDebug": "BUILD_DEBUG=true npm install",
86-
"lint": "jshint generate/scripts lib test/tests test/utils examples lifecycleScripts",
86+
"lint": "jshint generate/templates/filters/ generate/scripts lib test/tests test/utils examples lifecycleScripts",
8787
"mergecov": "lcov-result-merger 'test/**/*.info' 'test/coverage/merged.lcov' && ./lcov-1.10/bin/genhtml test/coverage/merged.lcov --output-directory test/coverage/report",
8888
"mocha": "mocha --expose-gc test/runner test/tests --timeout 15000",
8989
"mochaDebug": "mocha --expose-gc --debug-brk test/runner test/tests --timeout 15000",

0 commit comments

Comments
 (0)