Skip to content
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

Merged
merged 20 commits into from Jan 18, 2017
Merged

Mongo package linting #8175

merged 20 commits into from Jan 18, 2017

Conversation

dr-dimitru
Copy link
Contributor

@dr-dimitru dr-dimitru commented Dec 21, 2016

mongo_driver.js:

  • Lines 66, 1011 and 1352: Linting
  • 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 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

polling_observe_driver.js

  • newResults defined inside try, and used in parent scope later

oplog_tailing.js

  • lastEntry defined on while loop (line 139), and used later at parent scope

oplog_observe_driver.js

  • Line 425 and 448: maxBuffered is defined twice in same scope (hoisting)

mongo_livedata_tests.js

  • Lines 481 - 498: val and x is defined twice (hoisting)
  • Lines 973 - 975 and 980 - 982: expectedRemoves and expectedAdds is already defined on lines 952 and 955

allow_tests.js

  • Line 16: No need to set variable to undefined

package.js

  • Beta version bump

Other files

  • Overall linting, missed semicolons

- 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
@benjamn
Copy link
Contributor

benjamn commented Jan 10, 2017

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.

@dr-dimitru
Copy link
Contributor Author

Hi @benjamn ,

I'm using SublimeLinter + Babel + eslint with very default setup.

From .eslintrc:

    "rules": {
        "indent": [
            "error",
            2
        ],
        "linebreak-style": [
            "error",
            "unix"
        ],
        "quotes": [
            "off",
            "single"
        ],
        "semi": [
            "error",
            "always"
        ],
        "no-console": [
            "off", 
            {
                "allow": ["warn", "error", "info", "log", "trace"]
            }
        ]
    }

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.

Copy link
Contributor

@abernix abernix left a 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; });
Copy link
Contributor

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");
Copy link
Contributor

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) {
Copy link
Contributor

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;
Copy link
Contributor

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);
Copy link
Contributor

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;
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

dr-dimitru added a commit to veliovgroup/meteor that referenced this pull request Jan 17, 2017
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
@dr-dimitru
Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@abernix
Copy link
Contributor

abernix commented Jan 17, 2017

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?

@dr-dimitru
Copy link
Contributor Author

veliovgroup@a513097 not really related to this PR.

It's popped-out as I tried to run meteor test-packages ./, of course including MONGO_URL and MONGO_OPLOG_URL. Anyways I'm able to run and pass most of tests only after changes at this commit, should I start separate ticket/PR?

@abernix
Copy link
Contributor

abernix commented Jan 18, 2017

@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: errmsg vs err) which we never resolved. The full test suite is a bit tricky at times – you may find solace in looking at scripts/ci.sh in the Meteor repo to see what the CI suite runs.

dr-dimitru added a commit to veliovgroup/meteor that referenced this pull request Jan 18, 2017
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 () {},
Copy link
Contributor

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() {},
  })

Copy link
Contributor Author

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?

@benjamn benjamn merged commit d93c021 into meteor:devel Jan 18, 2017
abernix pushed a commit that referenced this pull request Mar 9, 2017
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants