Skip to content

Commit 7e66042

Browse files
committed
lint generate/scripts
1 parent 4cc8301 commit 7e66042

File tree

6 files changed

+162
-83
lines changed

6 files changed

+162
-83
lines changed

generate/scripts/generateJson.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ module.exports = function generateJson() {
7676
enums = _(enums).sortBy("name").reduce(function(enumMemo, enumerable) {
7777
if (previous == enumerable.typeName) {
7878
if (process.env.BUILD_ONLY) {
79-
console.warn('Duplicate definition for enum ' + enumerable.typeName +
79+
console.warn("Duplicate definition for enum " + enumerable.typeName +
8080
". skipped.");
8181
}
8282
}
8383
else if (!enumerable.fields) {
8484
if (process.env.BUILD_ONLY) {
85-
console.warn('Incomplete definition for enum ' + enumerable.typeName +
85+
console.warn("Incomplete definition for enum " + enumerable.typeName +
8686
". skipped.");
8787
}
8888
}
@@ -96,7 +96,7 @@ module.exports = function generateJson() {
9696
return {
9797
name: field.name,
9898
value: field.value
99-
}
99+
};
100100
})
101101
};
102102
}
@@ -123,7 +123,8 @@ module.exports = function generateJson() {
123123
output.push(typeDef);
124124
});
125125

126-
// Loop over the groups in case we missed anything (eg the types are missing in the docs);
126+
// Loop over the groups in case we missed anything
127+
// (eg the types are missing in the docs);
127128
for (var groupName in groups) {
128129
var groupDef = groups[groupName];
129130
if (groupDef === false) {
@@ -135,7 +136,8 @@ module.exports = function generateJson() {
135136
};
136137

137138
groupDef.type = "class";
138-
groupDef.cType = (descriptor.types[groupName] || {}).cType || groupDef.cType;
139+
groupDef.cType = (descriptor.types[groupName] || {}).cType ||
140+
groupDef.cType;
139141

140142
groupDef.typeName = groupName;
141143
dependencyLookup[groupName] = groupName;
@@ -155,7 +157,9 @@ module.exports = function generateJson() {
155157
return;
156158
}
157159

158-
var type = helpers.normalizeCtype(prop.type || prop.cType).replace("git_", "");
160+
var type = helpers
161+
.normalizeCtype(prop.type || prop.cType)
162+
.replace("git_", "");
159163
var dependencyFilename = dependencyLookup[type];
160164

161165
if (dependencyFilename && dependencyFilename !== def.filename) {

generate/scripts/generateMissingTests.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,27 @@ module.exports = function generateMissingTests() {
1717
var fieldsResult = [];
1818
var functionsResult = [];
1919
var fieldIgnores = (missingFileIgnores[idef.filename] || {}).fields;
20-
var functionIgnores = (missingFileIgnores[idef.filename] || {}).functions;
20+
var functionIgnores = (missingFileIgnores[idef.filename] || {})
21+
.functions;
2122

2223
fieldIgnores = fieldIgnores || [];
2324
functionIgnores = functionIgnores || [];
2425
file = file || "";
2526

2627
idef.fields.forEach(function(field) {
27-
if (file.indexOf(field.jsFunctionName) < 0
28-
&& fieldIgnores.indexOf(field.jsFunctionName < 0)) {
29-
fieldsResult.push(field.jsFunctionName);
30-
}
28+
if (file.indexOf(field.jsFunctionName) < 0 &&
29+
fieldIgnores.indexOf(field.jsFunctionName < 0)) {
30+
fieldsResult.push(field.jsFunctionName);
31+
}
3132
});
3233

3334
result.fields = fieldsResult;
3435

3536
idef.functions.forEach(function(fn) {
36-
if (file.indexOf(fn.jsFunctionName) < 0
37-
&& functionIgnores.indexOf(fn.jsFunctionName) < 0) {
38-
functionsResult.push(fn.jsFunctionName);
39-
}
37+
if (file.indexOf(fn.jsFunctionName) < 0 &&
38+
functionIgnores.indexOf(fn.jsFunctionName) < 0) {
39+
functionsResult.push(fn.jsFunctionName);
40+
}
4041
});
4142

4243
result.functions = functionsResult;
@@ -49,7 +50,7 @@ module.exports = function generateMissingTests() {
4950
output[idef.filename] = result;
5051
resolve();
5152
});
52-
};
53+
}
5354

5455
const idefs = require("../output/idefs");
5556
var promises = idefs.map(function(idef) {

generate/scripts/generateNativeCode.js

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require("path");
22
const fse = require("fs-extra");
3-
const os = require('os');
4-
const exec = require('../../utils/execPromise');
3+
const os = require("os");
4+
const exec = require("../../utils/execPromise");
55
const utils = require("./utils");
66

77
module.exports = function generateNativeCode() {
@@ -25,20 +25,24 @@ module.exports = function generateNativeCode() {
2525

2626
var partials = {
2727
asyncFunction: utils.readLocalFile("templates/partials/async_function.cc"),
28-
callbackHelpers: utils.readLocalFile("templates/partials/callback_helpers.cc"),
28+
callbackHelpers:
29+
utils.readLocalFile("templates/partials/callback_helpers.cc"),
2930
convertFromV8: utils.readLocalFile("templates/partials/convert_from_v8.cc"),
3031
convertToV8: utils.readLocalFile("templates/partials/convert_to_v8.cc"),
3132
doc: utils.readLocalFile("templates/partials/doc.cc"),
3233
fields: utils.readLocalFile("templates/partials/fields.cc"),
33-
guardArguments: utils.readLocalFile("templates/partials/guard_arguments.cc"),
34+
guardArguments:
35+
utils.readLocalFile("templates/partials/guard_arguments.cc"),
3436
syncFunction: utils.readLocalFile("templates/partials/sync_function.cc"),
35-
fieldAccessors: utils.readLocalFile("templates/partials/field_accessors.cc"),
37+
fieldAccessors:
38+
utils.readLocalFile("templates/partials/field_accessors.cc"),
3639
traits: utils.readLocalFile("templates/partials/traits.h")
3740
};
3841

3942
var templates = {
4043
class_content: utils.readLocalFile("templates/templates/class_content.cc"),
41-
struct_content: utils.readLocalFile("templates/templates/struct_content.cc"),
44+
struct_content:
45+
utils.readLocalFile("templates/templates/struct_content.cc"),
4246
class_header: utils.readLocalFile("templates/templates/class_header.h"),
4347
struct_header: utils.readLocalFile("templates/templates/struct_header.h"),
4448
binding: utils.readLocalFile("templates/templates/binding.gyp"),
@@ -69,7 +73,7 @@ module.exports = function generateNativeCode() {
6973
returnsInfo: require("../templates/filters/returns_info"),
7074
subtract: require("../templates/filters/subtract"),
7175
titleCase: require("../templates/filters/title_case"),
72-
toBool: require('../templates/filters/to_bool'),
76+
toBool: require("../templates/filters/to_bool"),
7377
unPointer: require("../templates/filters/un_pointer"),
7478
setUnsigned: require("../templates/filters/unsigned"),
7579
upper: require("../templates/filters/upper")
@@ -88,9 +92,12 @@ module.exports = function generateNativeCode() {
8892
// Attach all partials to select templates.
8993
Object.keys(partials).forEach(function(partial) {
9094
templates.class_header.registerPartial(partial, combyne(partials[partial]));
91-
templates.class_content.registerPartial(partial, combyne(partials[partial]));
92-
templates.struct_header.registerPartial(partial, combyne(partials[partial]));
93-
templates.struct_content.registerPartial(partial, combyne(partials[partial]));
95+
templates.class_content
96+
.registerPartial(partial, combyne(partials[partial]));
97+
templates.struct_header
98+
.registerPartial(partial, combyne(partials[partial]));
99+
templates.struct_content
100+
.registerPartial(partial, combyne(partials[partial]));
94101
});
95102

96103

@@ -101,22 +108,41 @@ module.exports = function generateNativeCode() {
101108
return !idef.ignore;
102109
});
103110

104-
const tempDirPath = path.join(os.tmpdir(), 'nodegit_build');
111+
const tempDirPath = path.join(os.tmpdir(), "nodegit_build");
105112
const tempSrcDirPath = path.join(tempDirPath, "src");
106113
const tempIncludeDirPath = path.join(tempDirPath, "include");
107114

108-
const finalSrcDirPath = path.join(__dirname, '../../src');
109-
const finalIncludeDirPath = path.join(__dirname, '../../include');
110-
111-
fse.remove(tempDirPath).then(function() {
112-
return fse.copy(path.resolve(__dirname, "../templates/manual/include"), tempIncludeDirPath);
113-
}).then(function() {
114-
return fse.copy(path.resolve(__dirname, "../templates/manual/src"), tempSrcDirPath);
115+
const finalSrcDirPath = path.join(__dirname, "../../src");
116+
const finalIncludeDirPath = path.join(__dirname, "../../include");
117+
118+
fse.remove(tempDirPath)
119+
.then(function() {
120+
return fse.copy(
121+
path.resolve(__dirname, "../templates/manual/include"),
122+
tempIncludeDirPath
123+
);
124+
}).then(function() {
125+
return fse.copy(
126+
path.resolve(__dirname, "../templates/manual/src"),
127+
tempSrcDirPath
128+
);
115129
}).then(function() {
116130
// Write out single purpose templates.
117-
utils.writeLocalFile("../binding.gyp", beautify(templates.binding.render(enabled)), "binding.gyp");
118-
utils.writeFile(path.join(tempSrcDirPath, "nodegit.cc"), templates.nodegitCC.render(enabled), "nodegit.cc");
119-
utils.writeLocalFile("../lib/nodegit.js", beautify(templates.nodegitJS.render(enabled)), "nodegit.js");
131+
utils.writeLocalFile(
132+
"../binding.gyp",
133+
beautify(templates.binding.render(enabled)),
134+
"binding.gyp"
135+
);
136+
utils.writeFile(
137+
path.join(tempSrcDirPath, "nodegit.cc"),
138+
templates.nodegitCC.render(enabled),
139+
"nodegit.cc"
140+
);
141+
utils.writeLocalFile(
142+
"../lib/nodegit.js",
143+
beautify(templates.nodegitJS.render(enabled)),
144+
"nodegit.js"
145+
);
120146
// Write out all the classes.
121147
enabled.forEach(function(idef) {
122148
if (idef.type && idef.type != "enum") {
@@ -134,7 +160,11 @@ module.exports = function generateNativeCode() {
134160
}
135161
});
136162

137-
utils.writeLocalFile("../lib/enums.js", beautify(templates.enums.render(enabled)), "enums.js");
163+
utils.writeLocalFile(
164+
"../lib/enums.js",
165+
beautify(templates.enums.render(enabled)),
166+
"enums.js"
167+
);
138168
}).then(function() {
139169
return exec("command -v astyle").then(function(astyle) {
140170
if (astyle) {
@@ -159,7 +189,6 @@ module.exports = function generateNativeCode() {
159189
}).then(function() {
160190
return fse.remove(tempDirPath);
161191
}).catch(console.log);
162-
163192
};
164193

165194
if (require.main === module) {

0 commit comments

Comments
 (0)