Skip to content

Update eslint infrastructure - #2632

Merged
bajtos merged 1 commit into
masterfrom
eslint2
Nov 22, 2016
Merged

bajtos merged 1 commit into
masterfrom
eslint2

Conversation

@loay

@loay loay commented Aug 15, 2016 •

Copy link
Copy Markdown
Contributor

No description provided.

@loay loay added the #review label Aug 15, 2016
Comment thread package.json Outdated
"cookie-parser": "^1.3.4",
"es5-shim": "^4.1.0",
"eslint-config-loopback": "^1.0.0",
"eslint-config-loopback": "^4.0.0",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should add:

"lint": "eslint .",
"posttest": "npm run lint"

But please do this in a separate PR, this one is huge as is already.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought we do not do that if the Gruntfile is taking care of it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For now it doesn't matter but I think we should move away from having a Gruntfile at all and doing it all via NPM scripts instead. As for your current PR, you don't need to do anything.

@superkhau superkhau self-assigned this Aug 16, 2016
@superkhau

Copy link
Copy Markdown
Contributor

LGTM, please check CI and make sure they are unrelated to your PR before merging.

@loay

loay commented Nov 15, 2016

Copy link
Copy Markdown
Contributor Author

@bajtos @superkhau
PTAL. There are some code changes in the actual code, in order to be conform with the upgrade, as well as the use strict.

The main files that included code change and not just style:

  • common/models/application.js
  • common/models/role.js
  • test/key-value-model.test.js --> replaced connector by adapter
  • Globalized variables in test/support.js

An interesting test case here:

in loopback.test.js:

  • expected properties are different in v6 and v4 than v0.10 and 0.12 !!!

@bajtos

bajtos commented Nov 15, 2016

Copy link
Copy Markdown
Member

Hey @loay, great stuff! Thank you for going through the pain of fixing linting. Could you please use recently released eslint-config-loopback@5.0.0 (loopbackio/eslint-config-loopback#12) while you are at this?

@bajtos bajtos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Uff 💦 , that was a long patch to review! @loay see my comments below. Please don't rewrite history and only add incremental commits from now on, so that I can review individual commits in the future and don't have to re-read the whole patch again.


module.exports = function(Application) {
// Workaround for https://github.com/strongloop/loopback/issues/292
Application.definition.rawProperties.created.default =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change looks suspicious to me, could you please explain which eslint rule is violated by this line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it was giving this error:

>> Mocha exploded!
>> TypeError: Cannot create property 'default' on string 'date'
>>   at module.exports (/Users/loay/Desktop/NodeEE/loopback/common/models/application.js:75:56)

As you see, I removed the first line in application.js and role.js but I think the proper solution is in application.json and role.json

    "created": {
      "default": "date"
    },
    "modified": {
      "default": "date"
    }

I will update that in the next commit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

> Mocha exploded!
> TypeError: Cannot create property 'default' on string 'date'
>   at module.exports (/Users/loay/Desktop/NodeEE/loopback/common/models/application.js:75:56)

Ah, makes sense now.

 "created": {
      "default": "date"
    },
    "modified": {
      "default": "date"
    }

The correct solution is to use "defaultFn": "now", see loopbackio/loopback-datasource-juggler#458

};

// Workaround for https://github.com/strongloop/loopback/issues/292
Application.definition.rawProperties.modified.default =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change looks suspicious to me, could you please explain which eslint rule is violated by this line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same answer as above #2632 (comment)

Comment thread common/models/email.js Outdated
var g = require('../../lib/globalize');

module.exports = function(Email) {
module.exports = function(Email) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The indentation changes in this file are suspicious. Why do we need to indent lines by one (!) more character? AFAIK, we are not doing that in any other file. PTAL.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct .. The whole file was having one extra indentation and not caught by the auto fix.
Fixing in the next commit.

Comment thread common/models/key-value-model.js Outdated
var g = require('../../lib/globalize');

module.exports = function(KeyValueModel) {
module.exports = function(KeyValueModel) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The indentation changes in this file are suspicious. Why do we need to indent lines by one (!) more character? AFAIK, we are not doing that in any other file. PTAL.

Comment thread common/models/email.js Outdated

var g = require('../../lib/globalize');
'use strict';
var g = require('../../lib/globalize');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, I think the order of jsdoc, use-strict, require() and module.exports is wrong here. The correct order is:

'use strict';

var g = require('../../lib/globalize');

/** 
 * Email model. etc.
 */

module.exports = function(Email) {
  // ...
};

Comment thread package.json Outdated
"cookie-parser": "^1.3.4",
"es5-shim": "^4.1.0",
"eslint-config-loopback": "^1.0.0",
"eslint": "^2.13.1",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove, we are using grunt-eslint instead.


'use strict';
var g = require('../../lib/globalize');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please keep the empty line serving as a visual delimiter.

Comment thread test/remoting.integration.js Outdated
}

function getFormattedMethodsExcludingRelations(methods) {
var result;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just remove result = from the next line.

return methods.filter(function(m) {
  // ...
});

Comment thread test/remoting.integration.js Outdated
}

function getFormattedScopeMethods(methods) {
var result;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto, result is not used and should be removed.

Comment thread test/remoting.integration.js Outdated
}

function getFormattedPrototypeMethods(methods) {
var result;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto, result is not used and should be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread test/key-value-model.test.js Outdated

app.dataSource('kv', { connector: 'kv-memory' });
app.model(CacheItem, { dataSource: 'kv' });
app.dataSource('kv', {adapter: 'kv-memory'});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't understand why is this change necessary, could you please explain?

The connector option is the canonical way of configuring data-source connector, I am not sure if adapter is even documented.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would get the following error:

  3) KeyValueModel "before each" hook: setupAppAndCacheItem for "provides "get(key)" at "GET /key"":
     TypeError: Cannot create data source "kv": Cannot create property 'name' on string 'kv-memory'
    at dataSourcesFromConfig (lib/application.js:427:29)
    at EventEmitter.app.dataSource (lib/application.js:226:14)
    at Context.setupAppAndCacheItem (test/key-value-model.test.js:150:9)

I did some research and it seems to be adapter is the equivalent and it passes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The problem is that every code out there will be setting connector, not adapter. This failing test is showing a problem in the underlying implementation we need to fix.

It turns out loopback does not automatically add all connectors bundled in juggler, we need to explicitly register them. I fixed the problem in 4a895bb and reverted this changed line back to original.

@bajtos

bajtos commented Nov 16, 2016

Copy link
Copy Markdown
Member

Could you please use recently released eslint-config-loopback@5.0.0 (loopbackio/eslint-config-loopback#12) while you are at this?

It turns out that we are using a lot of undeclared global variables in our tests, therefore upgrading to config@5 requires quite a lot of work.

In that light, let's stick with v4 of our eslint config, so that we can land this pull request soon and avoid painful merge conflicts.

@loay

loay commented Nov 16, 2016 •

Copy link
Copy Markdown
Contributor Author

@bajtos That was too late. I used already eslint@5 on Tuesday night but I didn't commit as I had few other changes to do.

  • I declared all required variables, and resolved conflicts .. That was the longest thing I had to ever do :)
  • removed test/support.js since it is not needed anymore. global declaration was not working.
  • Some of my changes got merged with yours. Sorry about that !!
  • Your changes are still there as far as I can tell. Can you double check? .. just in case, but I made sure they are already there few times.
  • There was a node version conflict in loopback.test.js. I used semver.
  • test cases finally pass

@superkhau

Copy link
Copy Markdown
Contributor

@slnode test please

@bajtos bajtos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I reviewed the new commits you added. Looks like there are still merge conflicts, please rebase your branch again.

Comment thread common/models/application.js Outdated
Application.definition.rawProperties.created.default =
Application.definition.properties.created.default = function() {
return new Date();
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These five lines (starting with the "workaround" comment) should be removed, since the default property values is already configured via JSON, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct .. Removed.

Comment thread common/models/application.js Outdated
Application.definition.rawProperties.modified.default =
Application.definition.properties.modified.default = function() {
return new Date();
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto - These five lines (starting with the "workaround" comment) should be removed, since the default property values is already configured via JSON, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct .. Removed.
Also removed in models/role.js as well.

Comment thread test/access-token.test.js Outdated
function(done) {
var token = this.token;

var app = loopback({localRegistry: true, loadBuiltinModels: true});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks rather confusing to me, as this line is creating a local model registry but the test itself uses token in the global registry.

The correct solution is to rework the infrastructure in this test file to use a local per-app registry for everything and drop global AccessToken (see lines 18-21).

As a short-term fix to unblock your eslint work, I am proposing to change this line to var app = loopback(); and if that does not work, then var app = express();.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

var app = loopback(); was not working but it is working now for some reason, maybe because of the globak AccessToken thing.

Comment thread test/access-token.test.js Outdated
var token = this.token;
var tokenStub = {id: 'stub id'};

var app = loopback({localRegistry: true, loadBuiltinModels: true});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto - var app = loopback(); or var app = express();

Comment thread test/loopback.test.js Outdated
'version',
];

var EXPECTED_GTNODE4 = [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This makes it very difficult to understand what's the difference between EXPECTED_GTNODE4 and EXPECTED. Please rework the definition of these two arrays in such way, that one contains the shared items and the second adds/removes only what's different.

I find it also very surprising that this test was passing before you started fixing eslint stuff. I want you to investigate this more and find out what is causing the different set of loopback properties. I suspect this change may have been caused by enabling "strict mode".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also note that the master branch does not support pre-4.0 versions of Node anymore, therefore there is no need for EXPECTED_GTNODE4

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

correct .. I didn't realize that we shouldn't worry anymore about pre4.0 so I fixed that.
arguments and caller properties are removed though! Possibly because of the use strict.

@loay

loay commented Nov 21, 2016

Copy link
Copy Markdown
Contributor Author

@bajtos I hope there will be no merge conflicts till your next review :)

@bajtos

bajtos commented Nov 22, 2016

Copy link
Copy Markdown
Member

@loay I have pushed two commits - the first one fixes remaining details (e511235), the second one brings back saltWorkFactor:4 to speed up tests (8213148).

Unfortunately the patch is out of date again, I'll rebase it myself so that we can get this landed ASAP.

Notable side-effects:
 - loopback no longer exports "caller" and "arguments" properties
 - kv-memory connector is now properly added to the connector registry
 - the file "test/support.js" was finally removed
@bajtos

bajtos commented Nov 22, 2016

Copy link
Copy Markdown
Member

CI failures are caused by unreachable npm registry, let's ignore them and land this pull request to avoid further merge conflicts.

@bajtos
bajtos merged commit c3ab932 into master Nov 22, 2016
@bajtos
bajtos deleted the eslint2 branch November 22, 2016 13:20
@bajtos bajtos removed the #review label Nov 22, 2016
@ebarault

ebarault commented Nov 23, 2016 •

Copy link
Copy Markdown
Contributor

@bajtos, @loay, @superkhau It seems this PR breaks support for db connectors. I'm not able to run a basic app like "loopback-access-control-example" since this merge. I'm installing with
npm install "https://github.com/strongloop/loopback.git#06cb481c3fbf467ee11ace5c186238840699e225"

I'm defining a simple mongodb db with this datasources.json:

{
	"db": {
		"name": "db",
		"connector": "mongodb",
		"host": "localhost",
		"port": 27017,
		"database": "loopback"
	}
}

and get the following error:

/Users/Eric/carbip/loopback_tests/loopback-example-access-control/node_modules/loopback/lib/application.js:237
    throw err;
    ^

TypeError: Cannot create data source "db": Cannot create property 'name' on string 'mongodb'
    at dataSourcesFromConfig (/Users/Eric/carbip/loopback_tests/loopback-example-access-control/node_modules/loopback/lib/application.js:427:29)

everything's fine if working with versions before this merge


edit:

ok this this pretty simple to fix, without 'use strict' the following error was not thrown whereas config.connector is of type 'string' (https://github.com/strongloop/loopback/blob/master/lib/application.js#L427)

if (!config.connector.name)
      config.connector.name = name;

Now, with use strict the code should to be updated this way

    if (typeof config.connector !== 'string' && !config.connector.name)
      config.connector.name = name; 

adding a PR,
i'm afraid other errors of this kind might pop after adding 'use strict' on all files

ebarault added a commit to ebarault/loopback that referenced this pull request Nov 23, 2016
ebarault added a commit to ebarault/loopback that referenced this pull request Nov 23, 2016
ebarault added a commit to ebarault/loopback that referenced this pull request Nov 23, 2016
ebarault added a commit to ebarault/loopback that referenced this pull request Nov 29, 2016
loay added a commit to ebarault/loopback that referenced this pull request Nov 30, 2016
loay added a commit to ebarault/loopback that referenced this pull request Nov 30, 2016
…ue-post-merge-strongloop#2632"

This reverts commit 476f6ce, reversing
changes made to d239476.
loay added a commit to ebarault/loopback that referenced this pull request Nov 30, 2016
loay added a commit that referenced this pull request Nov 30, 2016
fixing use-strict issue with connectors after merge #2632
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants