Skip to content

Commit 6616031

Browse files
committed
Eslint fixes
1 parent 70fabe8 commit 6616031

24 files changed

+149
-256
lines changed

.eslintrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": ["eslint:recommended"],
3+
"env": {
4+
"node": true,
5+
"mocha": true
6+
},
7+
"ecmaFeatures": {
8+
"es6": true,
9+
},
10+
"plugins": [
11+
],
12+
"rules": {
13+
"no-console":0
14+
}
15+
}

lib/admin.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ var toError = require('./utils').toError,
3535
*/
3636
var Admin = function(db, topology, promiseLibrary) {
3737
if(!(this instanceof Admin)) return new Admin(db, topology);
38-
var self = this;
3938

4039
// Internal state
4140
this.s = {
@@ -193,8 +192,6 @@ Admin.prototype.profilingLevel = function(callback) {
193192

194193
var profilingLevel = function(self, callback) {
195194
self.s.db.executeDbAdminCommand({profile:-1}, function(err, doc) {
196-
doc = doc;
197-
198195
if(err == null && doc.ok === 1) {
199196
var was = doc.was;
200197
if(was == 0) return callback(null, "off");
@@ -276,7 +273,7 @@ Admin.prototype.logout = function(callback) {
276273

277274
// Return a Promise
278275
return new this.s.promiseLibrary(function(resolve, reject) {
279-
self.s.db.logout({dbName: 'admin'}, function(err, r) {
276+
self.s.db.logout({dbName: 'admin'}, function(err) {
280277
if(err) return reject(err);
281278
resolve(true);
282279
});
@@ -427,8 +424,6 @@ var setProfilingLevel = function(self, level, callback) {
427424
command['profile'] = profile;
428425

429426
self.s.db.executeDbAdminCommand(command, function(err, doc) {
430-
doc = doc;
431-
432427
if(err == null && doc.ok === 1)
433428
return callback(null, level);
434429
return err != null ? callback(err, null) : callback(new Error("Error with profile command"), null);

lib/aggregation_cursor.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
"use strict";
22

33
var inherits = require('util').inherits
4-
, f = require('util').format
5-
, toError = require('./utils').toError
6-
, getSingleProperty = require('./utils').getSingleProperty
7-
, formattedOrderClause = require('./utils').formattedOrderClause
8-
, handleCallback = require('./utils').handleCallback
9-
, Logger = require('mongodb-core').Logger
10-
, EventEmitter = require('events').EventEmitter
11-
, ReadPreference = require('./read_preference')
124
, MongoError = require('mongodb-core').MongoError
135
, Readable = require('stream').Readable || require('readable-stream').Readable
146
, Define = require('./metadata')
15-
, CoreCursor = require('./cursor')
16-
, Query = require('mongodb-core').Query;
7+
, CoreCursor = require('./cursor');
178

189
/**
1910
* @fileOverview The **AggregationCursor** class is an internal class that embodies an aggregation cursor on MongoDB
@@ -63,7 +54,6 @@ var inherits = require('util').inherits
6354
*/
6455
var AggregationCursor = function(bson, ns, cmd, options, topology, topologyOptions) {
6556
CoreCursor.apply(this, Array.prototype.slice.call(arguments, 0));
66-
var self = this;
6757
var state = AggregationCursor.INIT;
6858
var streamOptions = {};
6959

@@ -138,11 +128,6 @@ var AggregationCursor = function(bson, ns, cmd, options, topology, topologyOptio
138128
// Inherit from Readable
139129
inherits(AggregationCursor, Readable);
140130

141-
// Set the methods to inherit from prototype
142-
var methodsToInherit = ['_next', 'next', 'each', 'forEach', 'toArray'
143-
, 'rewind', 'bufferedCount', 'readBufferedDocuments', 'close', 'isClosed', 'kill'
144-
, '_find', '_getmore', '_killcursor', 'isDead', 'explain', 'isNotified'];
145-
146131
// Extend the Cursor
147132
for(var name in CoreCursor.prototype) {
148133
AggregationCursor.prototype[name] = CoreCursor.prototype[name];

lib/apm.js

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@ var AggregationCursor = require('./aggregation_cursor'),
77
OrderedBulkOperation = require('./bulk/ordered').OrderedBulkOperation,
88
UnorderedBulkOperation = require('./bulk/unordered').UnorderedBulkOperation,
99
GridStore = require('./gridfs/grid_store'),
10-
Server = require('./server'),
11-
ReplSet = require('./replset'),
12-
Mongos = require('./mongos'),
1310
Cursor = require('./cursor'),
1411
Collection = require('./collection'),
15-
Db = require('./db'),
16-
Admin = require('./admin');
12+
Db = require('./db');
1713

1814
var basicOperationIdGenerator = {
1915
operationId: 1,
@@ -109,13 +105,14 @@ var Instrumentation = function(core, options, callback) {
109105
var commandName = keys[0];
110106
var db = ns.split('.')[0];
111107

108+
// Get the collection
109+
var col = ns.split('.');
110+
col.shift();
111+
col = col.join('.');
112+
112113
// Do we have a legacy insert/update/remove command
113114
if(x == 'insert') { //} && !this.lastIsMaster().maxWireVersion) {
114115
commandName = 'insert';
115-
// Get the collection
116-
var col = ns.split('.');
117-
col.shift();
118-
col = col.join('.');
119116

120117
// Re-write the command
121118
commandObj = {
@@ -130,11 +127,6 @@ var Instrumentation = function(core, options, callback) {
130127
} else if(x == 'update') { // && !this.lastIsMaster().maxWireVersion) {
131128
commandName = 'update';
132129

133-
// Get the collection
134-
var col = ns.split('.');
135-
col.shift();
136-
col = col.join('.');
137-
138130
// Re-write the command
139131
commandObj = {
140132
update: col, updates: commandObj
@@ -148,11 +140,6 @@ var Instrumentation = function(core, options, callback) {
148140
} else if(x == 'remove') { //&& !this.lastIsMaster().maxWireVersion) {
149141
commandName = 'delete';
150142

151-
// Get the collection
152-
var col = ns.split('.');
153-
col.shift();
154-
col = col.join('.');
155-
156143
// Re-write the command
157144
commandObj = {
158145
delete: col, deletes: commandObj
@@ -163,24 +150,17 @@ var Instrumentation = function(core, options, callback) {
163150
}
164151

165152
commandObj.ordered = options.ordered != undefined ? options.ordered : true;
166-
// } else if(x == 'insert' || x == 'update' || x == 'remove' && this.lastIsMaster().maxWireVersion >= 2) {
167-
// // Skip the insert/update/remove commands as they are executed as actual write commands in 2.6 or higher
168-
// return func.apply(this, args);
169153
}
170154

171-
// console.log("=== APM 0")
172-
173155
// Get the callback
174156
var callback = args.pop();
175157
// Set current callback operation id from the current context or create
176158
// a new one
177159
var ourOpId = callback.operationId || operationIdGenerator.next();
178-
// console.log("=== APM 1")
179160

180161
// Get a connection reference for this server instance
181162
var connection = this.s.pool.get()
182163

183-
// console.log("=== APM 2")
184164
// Emit the start event for the command
185165
var command = {
186166
// Returns the command.
@@ -200,8 +180,6 @@ var Instrumentation = function(core, options, callback) {
200180
connectionId: connection
201181
};
202182

203-
// console.log("=== APM 3")
204-
205183
// Filter out any sensitive commands
206184
if(senstiveCommands.indexOf(commandName.toLowerCase())) {
207185
command.commandObj = {};
@@ -267,7 +245,7 @@ var Instrumentation = function(core, options, callback) {
267245
// ---------------------------------------------------------
268246

269247
// Inject ourselves into the Bulk methods
270-
var methods = ['execute'];
248+
methods = ['execute'];
271249
var prototypes = [
272250
require('./bulk/ordered').Bulk.prototype,
273251
require('./bulk/unordered').Bulk.prototype
@@ -283,7 +261,6 @@ var Instrumentation = function(core, options, callback) {
283261

284262
// The actual prototype
285263
proto[x] = function() {
286-
var bulk = this;
287264
// Get the aruments
288265
var args = Array.prototype.slice.call(arguments, 0);
289266
// Set an operation Id on the bulk object
@@ -314,8 +291,8 @@ var Instrumentation = function(core, options, callback) {
314291
// ---------------------------------------------------------
315292

316293
// Inject ourselves into the Cursor methods
317-
var methods = ['_find', '_getmore', '_killcursor'];
318-
var prototypes = [
294+
methods = ['_find', '_getmore', '_killcursor'];
295+
prototypes = [
319296
require('./cursor').prototype,
320297
require('./command_cursor').prototype,
321298
require('./aggregation_cursor').prototype
@@ -440,7 +417,7 @@ var Instrumentation = function(core, options, callback) {
440417
var commandName = x == '_find' ? Object.keys(command)[0] : commandTranslation[x];
441418

442419
// Emit the start event for the command
443-
var command = {
420+
command = {
444421
// Returns the command.
445422
command: command,
446423
// Returns the database name.
@@ -475,7 +452,7 @@ var Instrumentation = function(core, options, callback) {
475452
&& this.server.lastIsMaster()
476453
&& this.server.lastIsMaster().maxWireVersion < 4) {
477454
// Emit the succeeded command
478-
var command = {
455+
command = {
479456
duration: timestampGenerator.duration(startTime, timestampGenerator.current()),
480457
commandName: commandName,
481458
requestId: requestId,
@@ -528,7 +505,7 @@ var Instrumentation = function(core, options, callback) {
528505
}
529506

530507
// cursor id is zero, we can issue success command
531-
var command = {
508+
command = {
532509
duration: timestampGenerator.duration(startTime, timestampGenerator.current()),
533510
commandName: commandName,
534511
requestId: requestId,
@@ -561,7 +538,7 @@ var Instrumentation = function(core, options, callback) {
561538
// Emit the started event
562539
self.emit('started', command)
563540
// Execute the function
564-
promise.then(function(r) {
541+
promise.then(function() {
565542
// cursor id is zero, we can issue success command
566543
var command = {
567544
duration: timestampGenerator.duration(startTime, timestampGenerator.current()),

lib/bulk/common.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict";
22

3-
var utils = require('../utils'),
4-
Long = require('mongodb-core').BSON.Long,
3+
var Long = require('mongodb-core').BSON.Long,
54
Timestamp = require('mongodb-core').BSON.Timestamp;
65

76
// Error codes
@@ -393,9 +392,9 @@ var mergeBatchResults = function(ordered, batch, bulkResult, err, result) {
393392
}
394393

395394
if(Array.isArray(result.writeErrors)) {
396-
for(var i = 0; i < result.writeErrors.length; i++) {
395+
for(i = 0; i < result.writeErrors.length; i++) {
397396

398-
var writeError = {
397+
writeError = {
399398
index: batch.originalZeroIndex + result.writeErrors[i].index
400399
, code: result.writeErrors[i].code
401400
, errmsg: result.writeErrors[i].errmsg

lib/bulk/ordered.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
var common = require('./common')
44
, utils = require('../utils')
55
, toError = require('../utils').toError
6-
, f = require('util').format
76
, handleCallback = require('../utils').handleCallback
87
, shallowClone = utils.shallowClone
9-
, WriteError = common.WriteError
108
, BulkWriteResult = common.BulkWriteResult
11-
, LegacyOp = common.LegacyOp
129
, ObjectID = require('mongodb-core').BSON.ObjectID
1310
, Define = require('../metadata')
1411
, BSON = require('mongodb-core').BSON
@@ -207,7 +204,6 @@ var addToOperationsList = function(_self, docType, document) {
207204
function OrderedBulkOperation(topology, collection, options) {
208205
options = options == null ? {} : options;
209206
// TODO Bring from driver information in isMaster
210-
var self = this;
211207
var executed = false;
212208

213209
// Current item
@@ -237,16 +233,9 @@ function OrderedBulkOperation(topology, collection, options) {
237233
global.Promise : require('es6-promise').Promise;
238234
}
239235

240-
// Current batch
241-
var currentBatch = null;
242-
var currentIndex = 0;
243-
var currentBatchSize = 0;
244-
var currentBatchSizeBytes = 0;
245-
var batches = [];
246-
247236
// Final results
248237
var bulkResult = {
249-
ok: 1
238+
ok: 1
250239
, writeErrors: []
251240
, writeConcernErrors: []
252241
, insertedIds: []
@@ -331,7 +320,7 @@ OrderedBulkOperation.prototype.raw = function(op) {
331320
// Crud spec delete operations, less efficient
332321
if(op.deleteOne || op.deleteMany) {
333322
var limit = op.deleteOne ? 1 : 0;
334-
var operation = {q: op[key].filter, limit: limit}
323+
operation = {q: op[key].filter, limit: limit}
335324
if(op.collation) operation.collation = op.collation;
336325
return addToOperationsList(this, common.REMOVE, operation);
337326
}

lib/bulk/unordered.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
var common = require('./common')
44
, utils = require('../utils')
55
, toError = require('../utils').toError
6-
, f = require('util').format
76
, handleCallback = require('../utils').handleCallback
87
, shallowClone = utils.shallowClone
9-
, WriteError = common.WriteError
108
, BulkWriteResult = common.BulkWriteResult
11-
, LegacyOp = common.LegacyOp
129
, ObjectID = require('mongodb-core').BSON.ObjectID
1310
, BSON = require('mongodb-core').BSON
1411
, Define = require('../metadata')
@@ -211,8 +208,6 @@ var addToOperationsList = function(_self, docType, document) {
211208
var UnorderedBulkOperation = function(topology, collection, options) {
212209
options = options == null ? {} : options;
213210

214-
// Contains reference to self
215-
var self = this;
216211
// Get the namesspace for the write operations
217212
var namespace = collection.collectionName;
218213
// Used to mark operation as executed
@@ -221,13 +216,6 @@ var UnorderedBulkOperation = function(topology, collection, options) {
221216
// Current item
222217
// var currentBatch = null;
223218
var currentOp = null;
224-
var currentIndex = 0;
225-
var batches = [];
226-
227-
// The current Batches for the different operations
228-
var currentInsertBatch = null;
229-
var currentUpdateBatch = null;
230-
var currentRemoveBatch = null;
231219

232220
// Handle to the bson serializer, used to calculate running sizes
233221
var bson = topology.bson;
@@ -252,7 +240,7 @@ var UnorderedBulkOperation = function(topology, collection, options) {
252240

253241
// Final results
254242
var bulkResult = {
255-
ok: 1
243+
ok: 1
256244
, writeErrors: []
257245
, writeConcernErrors: []
258246
, insertedIds: []
@@ -375,7 +363,7 @@ UnorderedBulkOperation.prototype.raw = function(op) {
375363
// Crud spec delete operations, less efficient
376364
if(op.deleteOne || op.deleteMany) {
377365
var limit = op.deleteOne ? 1 : 0;
378-
var operation = {q: op[key].filter, limit: limit}
366+
operation = {q: op[key].filter, limit: limit}
379367
return addToOperationsList(this, common.REMOVE, operation);
380368
}
381369

@@ -455,10 +443,9 @@ var executeBatch = function(self, batch, callback) {
455443
// Execute all the commands
456444
var executeBatches = function(self, callback) {
457445
var numberOfCommandsToExecute = self.s.batches.length;
458-
var error = null;
459446
// Execute over all the batches
460447
for(var i = 0; i < self.s.batches.length; i++) {
461-
executeBatch(self, self.s.batches[i], function(err, result) {
448+
executeBatch(self, self.s.batches[i], function(err) {
462449
// Driver layer error capture it
463450
if(err) error = err;
464451
// Count down the number of commands left to execute

0 commit comments

Comments
 (0)