New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mongo package linting #8175
Mongo package linting #8175
Conversation
- Line 497: `return` after `throw` - Lines 523 - 527: `e` already defined in same function scope (hoisting) - Line 937: Missed semicolon - Line 1095: Very confused about ES6 “default parameter” set via colon, which probably will be interpreted as Object - Babel failed to build on my end, regarding [this docs](https://mongodb.github.io/node-mongodb-native/api-generated/cursor .html#count) it should be a Boolean, so we set it to `false` by default - Line 1120: no need to set variable to `undefined` - Lines 1122, 1128, and 1133: Define `doc` above while due to function scope and hoisting `doc` is already allocated inside `while` and `try`
- Lines 481 - 498: `val` and `x` is defined twice (hoisting) - Lines 973 - 975 and 980 - 982: `expectedRemoves` and `expectedAdds` is defined on lines 952 and 955
- Line 425 and 448: `maxBuffered` is defined twice in same scope (hoisting)
- `lastEntry` defined on while loop (line 139), and used later at parent scope
- `newResults` defined inside try, and used in parent scope later
What linter ruleset are you using here? The long lines from compound conditions seem like a step backwards for readability, though other changes seem like good ideas. |
Hi @benjamn , I'm using SublimeLinter + Babel + eslint with very default setup. From
I can change it back on your demand, changed because even on my 15" screen it has space for those lines, and looks different to me. I guess it depends from developer to developer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for trying to fix these details, @dr-dimitru. Your linter configuration is a bit bare to use as a lint config for Meteor and would conflict with some of the "official" rules, but I think there are some reasonable changes in here. I've made suggestions that I think would make this mergeable.
For future reference, the most recently prescribed Meteor linter rules were https://github.com/meteor/javascript (a fork of https://github.com/airbnb/javascript), although it is arguably a bit out of date and needs some merging with some of the more recent additions to the Airbnb version. I'll try to address that soon, but you might want to check out the .eslintrc
for Meteor which is supposed to match that guide. (Though you should also see the .eslintignore
which excludes many files, intentionally. 😉
Thanks again for this. I do think cleanup like this is valuable in incremental amounts.
@@ -89,7 +89,7 @@ Tinytest.add('collection - call native find with sort function', | |||
if (Meteor.isServer) { | |||
test.throws( | |||
function () { | |||
nativeCollection.find({}, {sort: function(){}}).map(function (doc) { return doc.a; }) | |||
nativeCollection.find({}, {sort: function(){}}).map(function (doc) { return doc.a; }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also go ahead and wrap/indent this while we're at it?
nativeCollection
.find({}, {
sort: function () {},
})
.map( doc => doc.a );
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preference to revert this. Previous readability was better and lines over 100 characters are too much. While there may be room with your IDE maximized, not everyone does this.
+ (forceOrdered ? " force ordered" : ""), | ||
function (test, onComplete) { | ||
|
||
Tinytest.addAsync("observeChanges - single id - basics " + added + (forceOrdered ? " force ordered" : ""), function (test, onComplete) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer to revert.
var maxBuffered = (limit && self._unpublishedBuffer.size() > 0) | ||
? self._unpublishedBuffer.get(self._unpublishedBuffer.maxElementId()) | ||
: null; | ||
var maxBuffered = (limit && self._unpublishedBuffer.size() > 0) ? self._unpublishedBuffer.get(self._unpublishedBuffer.maxElementId()) : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer to revert.
return other instanceof TestCustomType | ||
&& EJSON.equals(this.myHead, other.myHead) | ||
&& EJSON.equals(this.myTail, other.myTail); | ||
return other instanceof TestCustomType && EJSON.equals(this.myHead, other.myHead) && EJSON.equals(this.myTail, other.myTail); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preference to revert.
var maxBuffered = (limit && self._unpublishedBuffer.size() > 0) | ||
? self._unpublishedBuffer.get(self._unpublishedBuffer.maxElementId()) | ||
: null; | ||
var maxBuffered = (limit && self._unpublishedBuffer.size() > 0) ? self._unpublishedBuffer.get(self._unpublishedBuffer.maxElementId()) : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert. 🙂
@@ -1092,7 +1090,7 @@ _.extend(SynchronousCursor.prototype, { | |||
return self.map(_.identity); | |||
}, | |||
|
|||
count: function (applySkipLimit: false) { | |||
count: function (applySkipLimit = false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
- Changes according to PR request - Apply rule [meteor#16.1](https://github.com/meteor/javascript#16.1) to if/else blocks
- Changes according to PR request - Apply rule [meteor#16.1](https://github.com/meteor/javascript#16.1) to if/else blocks
- Line 88: `selector` variable defined but never used - Apply rule [meteor#16.1](https://github.com/meteor/javascript#16.1) to if/else blocks
- Apply rule [meteor#16.1](https://github.com/meteor/javascript#16.1) to if/else blocks
mongo_driver.js: - Line 609: Argument `driverResult` in `transformResult` is always a number - Line 639: `errmsg` property is not exists on `err` object - Line 735 & 758: `result` argument of `bindEnvironmentForWrite` is always a *Number* oplog_tailing.js: - Line 217: `setName` property of `isMasterDoc` is not exists - Line 218: Error message is not correct, as it’s not same as on line 185 remote_collection_driver.js: - No need to define `self` variable here
Hi @abernix , Thank you for detailed review. Required changes is pushed. For some reason I can not run tests for this package unless changes is made, please take a look on this commit. What do you think? |
} 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this change is safe or just a "linting" change – at least not without further consideration or explanation.
This is in a loop. While doc
is null
the first time around, if cursor._nextObject
throws an error, it would be left as the previous doc
that was processed on this cursor (loop). A tailable cursor remains open until additional documents arrive.
Do you disagree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abernix you're right. My bad.
I don't see how veliovgroup@a513097 is related to this PR. Is there an actual issue that you're trying to fix with that commit? |
veliovgroup@a513097 not really related to this PR. It's popped-out as I tried to run |
@dr-dimitru Ok, this LGTM now. Hopefully someone else can take a look over it too and 👍 it. Regarding veliovgroup@a513097: yes, let's make that a separate issue which shows the problem you're encountering, including specifically which tests are failing. Also, try to keep each commit/PR to one logical change. That being said, the "fix" reminds me of something that turned up in #7758 (comment) (re: |
Older error objects is: ```js {name: String, code: Number, errmsg: String} ``` Newer mongo return error Object as: ```js {name: String, code: Number, err: String} ``` This commit adds support for new error Object without dropping support for older. - Mentioned as confirmed bug at: meteor#7758 - Partly discussed at: meteor#8175 - Originally fixed [at this commit](a5130970bc6f79af683 ba2fd10dd4402ef2cdb6c)
nativeCollection.find({}, {sort: function(){}}).map(function (doc) { return doc.a; }) | ||
nativeCollection | ||
.find({}, { | ||
sort: function () {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I'm not going to request changes, in the future you should know you can write methods like this using method syntax:
nativeCollection
.find({}, {
sort() {},
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @benjamn ,
Thank you for merge.
I wish to use ES7 syntax, but most of file seems to be ES5. Am I wrong?
The Mongo error property, `errmsg`, has been changed to `err` on newer versions of Mongo. This commit adds support for the new property without dropping support for older Mongo versions. Partially addresses #7758 (comment) Discussed in #8175 (comment)
mongo_driver.js:
return
afterthrow
e
already defined in same function scope (hoisting)false
by defaultundefined
doc
above while due to function scope and hoistingdoc
is already allocated insidewhile
andtry
polling_observe_driver.js
newResults
defined inside try, and used in parent scope lateroplog_tailing.js
lastEntry
defined on while loop (line 139), and used later at parent scopeoplog_observe_driver.js
maxBuffered
is defined twice in same scope (hoisting)mongo_livedata_tests.js
val
andx
is defined twice (hoisting)expectedRemoves
andexpectedAdds
is already defined on lines 952 and 955allow_tests.js
undefined
package.js
Other files