From 69ef77bcb6ec8f9982ec6d711fb6c5be997d00bd Mon Sep 17 00:00:00 2001 From: dr-dimitru Date: Wed, 21 Dec 2016 02:55:02 +0300 Subject: [PATCH] =?UTF-8?q?-=20Lines=2066,=201011=20and=201352:=20Linting?= =?UTF-8?q?=20-=20Line=20497:=20`return`=20after=20`throw`=20-=20Lines=205?= =?UTF-8?q?23=20-=20527:=20`e`=20already=20defined=20in=20same=20function?= =?UTF-8?q?=20scope=20(hoisting)=20-=20Line=20937:=20Missed=20semicolon=20?= =?UTF-8?q?-=20Line=201095:=20Very=20confused=20about=20ES6=20=E2=80=9Cdef?= =?UTF-8?q?ault=20parameter=E2=80=9D=20set=20via=20colon,=20which=20probab?= =?UTF-8?q?ly=20will=20be=20interpreted=20as=20Object=20-=20Babel=20failed?= =?UTF-8?q?=20to=20build=20on=20my=20end,=20regarding=20[this=20docs](http?= =?UTF-8?q?s://mongodb.github.io/node-mongodb-native/api-generated/cursor?= =?UTF-8?q?=20.html#count)=20it=20should=20be=20a=20Boolean,=20so=20we=20s?= =?UTF-8?q?et=20it=20to=20`false`=20by=20default=20-=20Line=201120:=20no?= =?UTF-8?q?=20need=20to=20set=20variable=20to=20`undefined`=20-=20Lines=20?= =?UTF-8?q?1122,=201128,=20and=201133:=20Define=20`doc`=20above=20while=20?= =?UTF-8?q?due=20to=20function=20scope=20and=20hoisting=20`doc`=20is=20alr?= =?UTF-8?q?eady=20allocated=20inside=20`while`=20and=20`try`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mongo/mongo_driver.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/mongo/mongo_driver.js b/packages/mongo/mongo_driver.js index d16b6a540f..d7f442cba7 100644 --- a/packages/mongo/mongo_driver.js +++ b/packages/mongo/mongo_driver.js @@ -63,8 +63,7 @@ var replaceMongoAtomWithMeteor = function (document) { if (document instanceof MongoDB.ObjectID) { return new Mongo.ObjectID(document.toHexString()); } - if (document["EJSON$type"] && document["EJSON$value"] - && _.size(document) === 2) { + if (document["EJSON$type"] && document["EJSON$value"] && _.size(document) === 2) { return EJSON.fromJSONValue(replaceNames(unmakeMongoLegal, document)); } if (document instanceof MongoDB.Timestamp) { @@ -494,7 +493,6 @@ MongoConnection.prototype._update = function (collection_name, selector, mod, throw new Error( "Only plain objects may be used as replacement" + " documents in MongoDB"); - return; } if (!options) options = {}; @@ -522,11 +520,11 @@ MongoConnection.prototype._update = function (collection_name, selector, mod, var knownId = selector._id || mod._id; if (options._forbidReplace && ! isModify) { - var e = new Error("Invalid modifier. Replacements are forbidden."); + var err = new Error("Invalid modifier. Replacements are forbidden."); if (callback) { - return callback(e); + return callback(err); } else { - throw e; + throw err; } } @@ -936,7 +934,7 @@ Cursor.prototype._publishCursor = function (sub) { Cursor.prototype._getCollectionName = function () { var self = this; return self._cursorDescription.collectionName; -} +}; Cursor.prototype.observe = function (callbacks) { var self = this; @@ -1092,7 +1090,7 @@ _.extend(SynchronousCursor.prototype, { return self.map(_.identity); }, - count: function (applySkipLimit: false) { + count: function (applySkipLimit = false) { var self = this; return self._synchronousCount(applySkipLimit).wait(); }, @@ -1120,18 +1118,19 @@ MongoConnection.prototype.tail = function (cursorDescription, docCallback) { var cursor = self._createSynchronousCursor(cursorDescription); var stopped = false; - var lastTS = undefined; + var lastTS; var loop = function () { + var doc = null; while (true) { if (stopped) return; try { - var doc = cursor._nextObject(); + doc = cursor._nextObject(); } catch (err) { // There's no good way to figure out if this was actually an error // from Mongo. Ah well. But either way, we need to retry the cursor // (unless the failure was because the observe got stopped). - doc = null; + // `doc` is already `null` here; } // Since cursor._nextObject can yield, we need to check again to see if // we've been stopped before calling the callback. @@ -1350,9 +1349,7 @@ MongoConnection.prototype._observeChangesTailable = function ( // error if you didn't provide them. if ((ordered && !callbacks.addedBefore) || (!ordered && !callbacks.added)) { - throw new Error("Can't observe an " + (ordered ? "ordered" : "unordered") - + " tailable cursor without a " - + (ordered ? "addedBefore" : "added") + " callback"); + throw new Error("Can't observe an " + (ordered ? "ordered" : "unordered") + " tailable cursor without a " + (ordered ? "addedBefore" : "added") + " callback"); } return self.tail(cursorDescription, function (doc) {