Skip to content

Commit 04d85a0

Browse files
committed
Fix some jslint errors in loader
1 parent c812d24 commit 04d85a0

11 files changed

+104
-81
lines changed

loader/dbloader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ function main() {
151151
}
152152

153153
// Set connection properties
154-
var connectionProperties = new jones.ConnectionProperties(cmdOptions.adapter, cmdOptions.deployment);
154+
var connectionProperties =
155+
new jones.ConnectionProperties(cmdOptions.adapter, cmdOptions.deployment);
155156

156157
if(cmdOptions.connect_string) {
157158
connectionProperties.ndb_connectstring = cmdOptions.connect_string;

loader/lib/BadRecordLogger.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2014, Oracle and/or its affiliates. All rights
2+
Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights
33
reserved.
44
55
This program is free software; you can redistribute it and/or
@@ -18,6 +18,9 @@
1818
02110-1301 USA
1919
*/
2020

21+
"use strict";
22+
23+
var fs = require("fs");
2124
var udebug = unified_debug.getLogger("BadRecordLogger.js");
2225

2326
var theController, theBadRecordLogger;
@@ -93,7 +96,7 @@ BadRecordLogger.prototype.logRecord = function(record) {
9396
runQueue();
9497
});
9598
}
96-
}
99+
};
97100

98101
BadRecordLogger.prototype.end = function() {
99102
udebug.log("end", this.fd);
@@ -105,7 +108,7 @@ BadRecordLogger.prototype.end = function() {
105108
/* You can't close STDERR, so just tell the controller we're done */
106109
theController.loggerFinished();
107110
}
108-
}
111+
};
109112

110113
exports.BadRecordLogger = BadRecordLogger;
111114

loader/lib/Controller.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2014, Oracle and/or its affiliates. All rights
2+
Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights
33
reserved.
44
55
This program is free software; you can redistribute it and/or
@@ -18,6 +18,8 @@
1818
02110-1301 USA
1919
*/
2020

21+
"use strict";
22+
2123
var udebug = unified_debug.getLogger("Controller.js"),
2224
DbWriter = require("./DbWriter.js").DbWriter,
2325
BadRecordLogger = require("./BadRecordLogger.js").BadRecordLogger,
@@ -99,6 +101,8 @@ Controller.prototype.run = function() {
99101
Controller.prototype.dsNewItem = function(record) {
100102
var handlerReturnCode;
101103

104+
udebug.log("dsNewItem", record);
105+
102106
/* Count all rows processed */
103107
this.stats.rowsProcessed++;
104108

@@ -179,7 +183,7 @@ Controller.prototype.commitIfComplete = function() {
179183

180184
Controller.prototype.loaderTransactionDidCommit = function() {
181185
this.badRecordLogger.end();
182-
}
186+
};
183187

184188
Controller.prototype.loaderTransactionDidRollback = function() {
185189
this.fatalError = new Error("Transaction rolled back. No records loaded.");

loader/lib/DataSource.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ FileDataSource.prototype.onFileOpen = function(err, fd) {
232232
this.fd = fd;
233233
this.read();
234234
}
235-
}
235+
};
236236

237237
// TODO: Handle the case of a single record that is larger than the buffer
238238
// OR document this limitation and let the user select the buffer size
@@ -242,7 +242,7 @@ FileDataSource.prototype.read = function() {
242242
buffer = new Buffer(this.bufferSize);
243243

244244
/* Rewrite partial last record into new buffer */
245-
if(this.bufferDesc && ! this.bufferDesc.lineEnd < this.bufferDesc.lineStart) {
245+
if(this.bufferDesc && ! (this.bufferDesc.lineEnd < this.bufferDesc.lineStart)) {
246246
this.recopied = buffer.write(this.bufferDesc.source.substring(this.bufferDesc.lineStart));
247247
} else {
248248
this.recopied = 0;
@@ -299,6 +299,7 @@ FileDataSource.prototype.run = function() {
299299
extraLines = this.lineScanner.scan(desc); // Scan the line
300300
this.physLineNo += (extraLines + 1);
301301
if(this.options.columnsInHeader) {
302+
udebug.log("Setting columns from header");
302303
if(desc.lineHasFields) {
303304
this.options.columnsInHeader = null; // reset from true to null
304305
fields = this.fieldScanner.scan(desc); // Extract the data fields

loader/lib/DbWriter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ DbWriter.prototype._store = function(record) {
125125
theWriter.abort(error);
126126
return;
127127
}
128-
else if(error.ndb_error.status === "TemporaryError") {
128+
if(error.ndb_error.status === "TemporaryError") {
129129
this.batchManager.batchSizeDown();
130130
theWriter.loadItem(record); // retry
131131
return; // Do not set record.error or register as complete
@@ -148,7 +148,7 @@ DbWriter.prototype._store = function(record) {
148148
} else {
149149
this.batch.persist(record.class, record.row, rowCallback);
150150
}
151-
}
151+
};
152152

153153
DbWriter.prototype.executeBatch = function() {
154154
this.batch.execute(function(err) {

loader/lib/LoaderJob.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"use strict";
2222

2323
var assert = require("assert"),
24+
fs = require("fs"),
2425
jones = require("database-jones"),
2526
udebug = require("unified_debug").getLogger("LoaderJob.js"),
2627
machine = require("./control_file.js"),
@@ -35,15 +36,15 @@ function ColumnDefinition(columnName) {
3536
this.name = columnName;
3637
this.startPos = null; // For fixed-width input
3738
this.endPos = null;
38-
};
39+
}
3940

4041
// Define a destination: Database, Table, columns, and mapped class
4142
function LoaderJobDestination() {
4243
this.database = null;
4344
this.table = "";
4445
this.columnDefinitions = [];
4546
this.rowConstructor = null;
46-
};
47+
}
4748

4849
LoaderJobDestination.prototype.addColumnDefinition = function(name) {
4950
assert(typeof name === 'string');
@@ -66,7 +67,7 @@ LoaderJobDestination.prototype.createTableMapping = function() {
6667
mapping = new jones.TableMapping(literalMapping);
6768

6869
/* A ``function() {}'' for constructing mapped objects */
69-
this.rowConstructor = new Function();
70+
this.rowConstructor = function() {};
7071

7172
this.columnDefinitions.forEach(function(column) {
7273
mapping.mapField(column.name);
@@ -226,7 +227,7 @@ LoaderJob.prototype.dataSourceIsCSV = function() {
226227
227228
APPEND allows the table to have existing data. This is the default behavior.
228229
229-
INSERT requires the table to empty before loading.
230+
INSERT requires the table to be empty before loading.
230231
231232
TRUNCATE instructs the loader to delete all rows before loading data.
232233

loader/lib/LoaderModule.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2014, Oracle and/or its affiliates. All rights
2+
Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights
33
reserved.
44
55
This program is free software; you can redistribute it and/or
@@ -18,6 +18,7 @@
1818
02110-1301 USA
1919
*/
2020

21+
"use strict";
2122

2223
/* LoaderModule is constructed with an optionHandler so that a module
2324
plugged into dbLoader can handle command-line options.
@@ -26,7 +27,7 @@
2627
*/
2728
function LoaderModule(optionHandler) {
2829
this.optionHandler = optionHandler;
29-
};
30+
}
3031

3132

3233
/* addOption(shortForm, longForm, helpText, callback).

loader/lib/Parser.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights
2+
Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights
33
reserved.
44
55
This program is free software; you can redistribute it and/or
@@ -18,6 +18,7 @@
1818
02110-1301 USA
1919
*/
2020

21+
/*jslint sloppy: true */
2122

2223
/*
2324
This is a simple top-down recursive descent parser.
@@ -50,7 +51,7 @@ NonTerminal.prototype = {
5051
innerEval : null,
5152
isRepeat : null,
5253
visitorFunc : null,
53-
eval : function unset() { throw { message : "UNDEF EVAL" }; }
54+
evaluate : function unset() { throw new Error("UNDEF EVAL"); }
5455
};
5556

5657
NonTerminal.prototype.set = function(that) {
@@ -59,7 +60,7 @@ NonTerminal.prototype.set = function(that) {
5960
this.members = that.members;
6061
this.innerEval = that.innerEval;
6162
this.isRepeat = that.isRepeat;
62-
this.eval = that.eval;
63+
this.evaluate = that.evaluate;
6364
};
6465

6566
NonTerminal.prototype.describe = function() {
@@ -93,7 +94,6 @@ Node.prototype.isNode = true;
9394
otherwise call the generic visitor.
9495
*/
9596
Node.prototype.visit = function(visitor, transform) {
96-
var i;
9797
if(typeof visitor[this.nonTerminal.visitorFunc] === 'function') {
9898
visitor[this.nonTerminal.visitorFunc](this, transform);
9999
} else {
@@ -187,9 +187,9 @@ Parser.prototype.fail = function(msg) {
187187
start_line = (token.line > 2 ? token.line-1 : 1);
188188
lines = this.text.split('\n');
189189
ctx += lines[start_line-1] + "\n";
190-
if(token.line > start_line) ctx += lines[token.line-1] + "\n";
190+
if(token.line > start_line) { ctx += lines[token.line-1] + "\n"; }
191191
/* Now indent up to a caret at the errant token */
192-
while(++i < token.column) ctx += ' ';
192+
while(++i < token.column) { ctx += ' '; }
193193
ctx += "^^^\n";
194194
}
195195
var err = new Error("\n" + ctx + msg);
@@ -219,14 +219,14 @@ Parser.prototype.defineProductions = function() {
219219
for(i = 0 ; i < arguments.length ; i += 2) {
220220
this.def(arguments[i], arguments[ i+1 ]);
221221
}
222-
}
222+
};
223223

224224

225225
/* Describe Terminals, and let NonTerminals describe themselves
226226
*/
227227
Parser.prototype.describe = function(sym) {
228228
if(typeof sym === 'string') { return sym; }
229-
if(typeof sym === 'undefined') { return "undefined"; }
229+
if(sym === undefined) { return "undefined"; }
230230
if(sym === null) { return "null"; }
231231
if(sym.isNonTerminal) { return sym.describe(); }
232232
};
@@ -250,7 +250,7 @@ function evalSeries() {
250250
sym = this.members[i];
251251
strict_sym = sym.isNonTerminal ? sym.strict : true;
252252
node.children[i] = r =
253-
this.parser.eval(sym, (this.strict && strict_sym && (s > 0) ));
253+
this.parser.evaluate(sym, (this.strict && strict_sym && (s > 0) ));
254254
if(r !== null) { s += 1; } // Enable strictness
255255
i += 1;
256256
} while(i < this.members.length && (! (r === null && strict_sym)));
@@ -266,7 +266,7 @@ function evalAlternates() {
266266
var r, i, node ;
267267
node = new Node(this);
268268
for(i = 0 ; i < this.members.length ; i++) {
269-
r = this.parser.eval(this.members[i]);
269+
r = this.parser.evaluate(this.members[i]);
270270
if(r !== null) {
271271
node.children[0] = r;
272272
return node;
@@ -290,7 +290,7 @@ function evalSeveral() {
290290
}
291291
}
292292
return a;
293-
};
293+
}
294294

295295

296296
/////// NonTerminal Factories: Series, Several, Alts, Option ///////
@@ -301,7 +301,7 @@ Parser.prototype.Series = function() {
301301
var nt = new NonTerminal(this, arguments);
302302
nt.strict = true;
303303
nt.ebnf = [ '','','' ];
304-
nt.eval = evalSeries;
304+
nt.evaluate = evalSeries;
305305
return nt;
306306
};
307307

@@ -311,7 +311,7 @@ Parser.prototype.Alts = function() {
311311
var nt = new NonTerminal(this, arguments);
312312
nt.strict = true;
313313
nt.ebnf = [ '(' , '| ' , ')' ];
314-
nt.eval = evalAlternates;
314+
nt.evaluate = evalAlternates;
315315
return nt;
316316
};
317317

@@ -321,7 +321,7 @@ Parser.prototype.Alts = function() {
321321
Parser.prototype.Option = function() {
322322
var nt = new NonTerminal(this, arguments);
323323
nt.ebnf = [ '[' , '', ']' ];
324-
nt.eval = evalSeries;
324+
nt.evaluate = evalSeries;
325325
return nt;
326326
};
327327

@@ -332,21 +332,21 @@ Parser.prototype.Several = function() {
332332
nt.ebnf = [ '{', '', '}' ];
333333
nt.isRepeat = true;
334334
nt.innerEval = evalSeries;
335-
nt.eval = evalSeveral;
335+
nt.evaluate = evalSeveral;
336336
return nt;
337337
};
338338

339339

340-
/* Parser.eval()
340+
/* Parser.evaluate()
341341
Evaluate the current token against a parser symbol.
342342
If the token matches and is a Terminal, advance the token stream,
343343
and return the matching token.
344-
If the symbol is a NonTerminal, delegate to its own eval() method.
344+
If the symbol is a NonTerminal, delegate to its own evaluate() method.
345345
Return null if no match.
346346
If strict mode is set, and no match, fail the parser.
347347
*/
348-
Parser.prototype.eval = function(sym, strict) {
349-
if(debug) console.log("Parser eval", this.describe(sym));
348+
Parser.prototype.evaluate = function(sym, strict) {
349+
if(debug) { console.log("Parser evaluate", this.describe(sym)); }
350350
var r = null;
351351
var t = this.tokens[this.index];
352352
if(t) {
@@ -357,12 +357,12 @@ Parser.prototype.eval = function(sym, strict) {
357357
(t.value.toUpperCase() === sym.toUpperCase()))) { r = t; }
358358

359359
if(r !== null) {
360-
if(debug) console.log("Parser Advance", t.value);
360+
if(debug) { console.log("Parser Advance", t.value); }
361361
this.index += 1; // advance to the next token
362362
}
363363
}
364364
else if(sym.isNonTerminal) {
365-
r = sym.eval();
365+
r = sym.evaluate();
366366
}
367367
if(strict === true && r === null) {
368368
this.fail("Expected " + this.describe(sym));

0 commit comments

Comments
 (0)