Skip to content
This repository has been archived by the owner. It is now read-only.

chore(lint): switch from JSHint to ESLint #2578

Merged
merged 1 commit into from Jun 15, 2015

Conversation

@TDA
Copy link
Contributor

@TDA TDA commented Jun 10, 2015

Fixes #2550
Switch from JSHint to ESLint
Also have JSHint in parallel
References #2558, runs into same problem
@zaach

@TDA
Copy link
Contributor Author

@TDA TDA commented Jun 10, 2015

The build should fail, seeing as this has the same problem in a file called run_locally.js , should I once again change 'const' to 'var' in that file?
@pdehaan
@vladikoff
@zaach
@shane-tomlinson

"valid-typeof": 2,
"wrap-iife": 0
}
}

This comment has been minimized.

@vladikoff

vladikoff Jun 10, 2015
Contributor

need new line at the end of file here

@@ -82,6 +82,7 @@
"grunt-contrib-watch": "0.6.1",
"grunt-conventional-changelog": "1.1.0",
"grunt-copyright": "0.1.0",
"grunt-eslint": "^14.0.0",

This comment has been minimized.

@vladikoff

vladikoff Jun 10, 2015
Contributor

lock this to 14.0.0 or highest released version , don't use ^

@@ -21,7 +22,7 @@ module.exports = function (done) {
if (done) {
done(code);
} else {
process.exit(code);
process.exit(code); //eslint-disable-line

This comment has been minimized.

@vladikoff

vladikoff Jun 10, 2015
Contributor

what is the warning here?

"mocha": true,
"browser": true,
"builtin": true
},

This comment has been minimized.

@vladikoff

vladikoff Jun 10, 2015
Contributor

does eslint support extending config, so we don't have to repeat this in two files? cc @pdehaan

This comment has been minimized.

@pdehaan

pdehaan Jun 11, 2015
Contributor

It does. By default too, if I recall correctly. So we'd probably only need to override whatever envs we need and any special rule overrides.

For example, since we're in "./app/", I think we should be setting node: false and es6: false.

nit: Plus maybe convert this to YAML too and A-Z sort the envs above.

This comment has been minimized.

This comment has been minimized.

@pdehaan

pdehaan Jun 11, 2015
Contributor

I think the "app/.eslintrc" can be reduced to:

{
  "env": {
    "browser": true,
    "jquery": true,
    "mocha": true,
    "node": false
  },
  "rules": {
    "globals": {
      "router": false
    }
  }
}

With the rest of the rules being inherited from the parent .eslintrc config. (see https://github.com/mozilla/fxa-content-server/pull/2578/files#r32183274)

This comment has been minimized.

@TDA

TDA Jun 11, 2015
Author Contributor

Will check this out :)

This comment has been minimized.

@TDA

TDA Jun 11, 2015
Author Contributor

Setting Node: false actually throws 21 errors of "no-console" in the app/ directory.. What should I do?
@pdehaan

This comment has been minimized.

@pdehaan

pdehaan Jun 11, 2015
Contributor

I added "no-console": 0, to the .eslintrc file.
https://github.com/mozilla/fxa-content-server/pull/2578/files#r32183274

This comment has been minimized.

@TDA

TDA Jun 11, 2015
Author Contributor

Setting no-console: 0 to remedy this.

@vladikoff
Copy link
Contributor

@vladikoff vladikoff commented Jun 10, 2015

@TDA I think @shane-tomlinson confirmed in irc that we should use var. does that answer your question?

@TDA TDA force-pushed the TDA:issue-2550-switch-to-ESLint branch 3 times, most recently from 3118ea8 to ccd2a56 Jun 10, 2015
@TDA
Copy link
Contributor Author

@TDA TDA commented Jun 10, 2015

@vladikoff: Was just confirming :) I guess it passes the tests now.

'use strict';

module.exports = function (grunt) {
grunt.config('eslint', {

This comment has been minimized.

@TDA

TDA Jun 10, 2015
Author Contributor

Ok, done, but guess that results in a merge conflict?
@vladikoff

This comment has been minimized.

@vladikoff

vladikoff Jun 10, 2015
Contributor

@TDA yea needs to be rebased against 'master' , we just removed concurrent

This comment has been minimized.

@TDA

TDA Jun 10, 2015
Author Contributor

Should be right now @vladikoff :)

@TDA TDA force-pushed the TDA:issue-2550-switch-to-ESLint branch 2 times, most recently from 1bdea19 to fdc1434 Jun 10, 2015
@@ -7,6 +7,10 @@

module.exports = function (grunt) {
grunt.registerTask('lint', 'lint all the things', [
'concurrent:lint'
'eslint',

This comment has been minimized.

@vladikoff

vladikoff Jun 10, 2015
Contributor

bad spacing / bad indent

@TDA TDA force-pushed the TDA:issue-2550-switch-to-ESLint branch 2 times, most recently from 261079e to 72c4463 Jun 10, 2015
@vladikoff
Copy link
Contributor

@vladikoff vladikoff commented Jun 10, 2015

app/tests/spec/views/base.js
  43:8  warning  relier is defined but never used  no-unused-vars
app/tests/spec/views/complete_account_unlock.js
  39:8  warning  account is defined but never used  no-unused-vars
app/tests/spec/views/complete_reset_password.js
  318:12  warning  account is defined but never used  no-unused-vars
app/tests/spec/views/mixins/loading-mixin.js
  28:8  warning  view is defined but never used  no-unused-vars
app/tests/spec/views/permissions.js
  30:8  warning  email is defined but never used  no-unused-vars
app/tests/spec/views/settings.js
  33:8  warning  windowMock is defined but never used  no-unused-vars
✖ 6 problems (0 errors, 6 warnings)
Running "eslint:tests" (eslint) task
tests/functional/oauth_iframe.js
  33:6  warning  user is defined but never used  no-unused-vars
tests/functional/oauth_preverified_sign_up.js
  19:6  warning  user is defined but never used  no-unused-vars
tests/functional/oauth_reset_password.js
  23:6  warning  user is defined but never used         no-unused-vars
  26:6  warning  accountData is defined but never used  no-unused-vars
tests/functional/oauth_sign_up.js
  24:6  warning  user is defined but never used  no-unused-vars
tests/functional/oauth_sync_sign_in.js
  25:6  warning  user is defined but never used  no-unused-vars
tests/functional/oauth_webchannel.js
  23:6  warning  user is defined but never used  no-unused-vars
tests/functional/oauth_webchannel_keys.js
  25:6  warning  user is defined but never used  no-unused-vars
tests/functional/sign_in.js
  20:6  warning  user is defined but never used  no-unused-vars
tests/functional/sign_in_cached.js
  38:6  warning  user is defined but never used   no-unused-vars
  39:6  warning  user2 is defined but never used  no-unused-vars
tests/functional/sync_reset_password.js
  27:6  warning  accountData is defined but never used  no-unused-vars
tests/functional/sync_sign_in.js
  24:6  warning  user is defined but never used  no-unused-vars
tests/functional/sync_v2_sign_up.js
  26:6  warning  client is defined but never used  no-unused-vars
✖ 14 problems (0 errors, 14 warnings)

@TDA
Copy link
Contributor Author

@TDA TDA commented Jun 10, 2015

@vladikoff So i remove those unused variables? or change the lint rule?

@vladikoff
Copy link
Contributor

@vladikoff vladikoff commented Jun 10, 2015

@TDA something is not correct with the linter, the first warning:

    var relier;
    var user;
    var screenName = 'screen';

    var View = BaseView.extend({
      template: Template
    });


    beforeEach(function () {
      translator = new Translator('en-US', ['en-US']);
      translator.set({
        'the error message': 'a translated error message',
        'the success message': 'a translated success message'
      });

      router = new RouterMock();
      windowMock = new WindowMock();
      ephemeralMessages = new EphemeralMessages();
      metrics = new Metrics();
      relier = new Relier();

Relier is defined below, we need to figure out why it thinks that it is defined but never used

app/tests/spec/views/base.js
  43:8  warning  relier is defined but never used  no-unused-vars
@TDA
Copy link
Contributor Author

@TDA TDA commented Jun 11, 2015

@vladikoff Well, it is defined but never used. I don't see the variable relier being used in any statement other than the definition statement.

@vladikoff
Copy link
Contributor

@vladikoff vladikoff commented Jun 11, 2015

@TDA , see #2578 (comment) last line

relier = new Relier();
@zaach
Copy link
Contributor

@zaach zaach commented Jun 11, 2015

@TDA @vladikoff I don't think an assignment counts as being used– the value has to be accessed at some point.

"eqeqeq": [2, "allow-null"],
"global-strict": [0, "never"],
"globals": {
"define": true,

This comment has been minimized.

@pdehaan

pdehaan Jun 11, 2015
Contributor

IIRC, we don't need to add define as a global here if we have the "amd" env.

"node": true,
"mocha": true,
"browser": true,
"builtin": true

This comment has been minimized.

@pdehaan

pdehaan Jun 11, 2015
Contributor

nit: Can we sort these A-Z.

This comment has been minimized.

@TDA

TDA Jun 11, 2015
Author Contributor

Yes, will do! :)

"no-spaced-func": 0,
"no-undef": 2,
"no-underscore-dangle": 0,
"no-unused-vars": [1, {vars: all, args: none}],

This comment has been minimized.

@pdehaan

pdehaan Jun 11, 2015
Contributor

Not sure if these are strictly valid JSON, or if they need quotes.
Alternatively, we could (should?) convert this file from JSON to YAML because YAML is super awesome.

This comment has been minimized.

@TDA

TDA Jun 11, 2015
Author Contributor

I will, once I figure out what valid YAML looks like :P :D But we did have the jshint ones in JSON didn't we?

This comment has been minimized.

@zaach

zaach Jun 11, 2015
Contributor

I'd say let's keep it JSON for consistency's sake. No need for yet another markup language at this point. ;)

This comment has been minimized.

@vladikoff

vladikoff Jun 11, 2015
Contributor

-1 on YAML

This comment has been minimized.

@pdehaan

pdehaan Jun 11, 2015
Contributor

Haters.

This comment has been minimized.

@pdehaan

pdehaan Jun 11, 2015
Contributor

@TDA: Please add .eslintrc (and .jscsrc while we're in there) to the /grunttasks/jsonlint.js:11 file.

This comment has been minimized.

@TDA

TDA Jun 11, 2015
Author Contributor

Ok will do :)

@@ -24,7 +24,7 @@ define([
var item;
try {
item = JSON.parse(this._backend.getItem(fullKey(key)));
} catch (e) {
} catch (e) {//eslint-disable-line no-empty

This comment has been minimized.

@pdehaan

pdehaan Jun 11, 2015
Contributor

nit: Add a space between { and the //eslint comment:

} catch (e) { //eslint-disable-line no-empty

This comment has been minimized.

@zaach

zaach Jun 11, 2015
Contributor

Is there a lint rule for this? ;)

This comment has been minimized.

@pdehaan

pdehaan Jun 11, 2015
Contributor

Yeah, I'm actually a bit surprised that JSCS wouldn't have complained.

This comment has been minimized.

@TDA

TDA Jun 11, 2015
Author Contributor

JSCS doesn't seem to complain about anything to be honest, but I guess that might be cause we haven't set "requireSpacesInsideObjectBrackets" to true.

@@ -39,7 +39,9 @@ function (chai, _, XSS, Constants) {
});

it('disallows javascript: href', function () {
expectEmpty('javascript:alert(1)'); // jshint ignore:line
/*eslint-disable */

This comment has been minimized.

@pdehaan

pdehaan Jun 11, 2015
Contributor

What about using // eslint-disable-line on line 43?

This comment has been minimized.

@TDA

TDA Jun 11, 2015
Author Contributor

That actually didn't work, it made either the jshint tests fail or the eslint tests fail. So I went for the block disable one.



const BIN_ROOT = path.join(__dirname, '..', 'server', 'bin');
var BIN_ROOT = path.join(__dirname, '..', 'server', 'bin');

This comment has been minimized.

@pdehaan

pdehaan Jun 11, 2015
Contributor

Curious, why couldn't these be const if we were using the es6 env in .eslintrc? I thought that worked (but I admittedly tested very quickly and have a very poor memory)

This comment has been minimized.

@TDA

TDA Jun 11, 2015
Author Contributor

Because the linter is ok with the const, but our node interpreter throws an error. Can't figure out why.

@@ -20,7 +20,6 @@ if (isMain) {
process.chdir(path.dirname(__dirname));
}

var config = require('../lib/configuration');

This comment has been minimized.

@pdehaan

pdehaan Jun 11, 2015
Contributor

Wait, why was this removed?

This comment has been minimized.

@jrgm

jrgm Jun 11, 2015
Contributor

redundant require. See line 12 above.

This comment has been minimized.

@TDA

TDA Jun 11, 2015
Author Contributor

what @jrgm said.

This comment has been minimized.

@zaach

zaach Jun 12, 2015
Contributor

Wat. Good thing the config is idempotent.

@@ -41,7 +40,8 @@ define([

beforeEach: function () {
email = TestHelpers.createEmail();
user = TestHelpers.emailToUser(email);
// removed variable user

This comment has been minimized.

@vladikoff

vladikoff Jun 12, 2015
Contributor

remove this comment

@@ -41,7 +40,8 @@ define([

beforeEach: function () {
email = TestHelpers.createEmail();
user = TestHelpers.emailToUser(email);
// removed variable user
TestHelpers.emailToUser(email);

This comment has been minimized.

@vladikoff

vladikoff Jun 12, 2015
Contributor

this is not used ?

email2 = TestHelpers.createEmail();
user2 = TestHelpers.emailToUser(email2);
// removed variable user2

This comment has been minimized.

@vladikoff

vladikoff Jun 12, 2015
Contributor

remove comment, also above.

email2 = TestHelpers.createEmail();
user2 = TestHelpers.emailToUser(email2);
// removed variable user2
TestHelpers.emailToUser(email2);

This comment has been minimized.

@vladikoff

vladikoff Jun 12, 2015
Contributor

is this used?

This comment has been minimized.

@TDA

TDA Jun 12, 2015
Author Contributor

You are right, again :D removed :)

@@ -39,12 +37,13 @@ define([

beforeEach: function () {
email = TestHelpers.createEmail();
user = TestHelpers.emailToUser(email);
// removed variable user

This comment has been minimized.

@vladikoff

vladikoff Jun 12, 2015
Contributor

see other notes about these

@@ -32,7 +31,8 @@ define([
beforeEach: function () {
email = TestHelpers.createEmail();
bouncedEmail = TestHelpers.createEmail();
user = TestHelpers.emailToUser(email);
// removed variable user

This comment has been minimized.

@vladikoff

vladikoff Jun 12, 2015
Contributor

see other notes about these

@TDA TDA force-pushed the TDA:issue-2550-switch-to-ESLint branch from 22352a1 to 0c73028 Jun 12, 2015
@TDA
Copy link
Contributor Author

@TDA TDA commented Jun 12, 2015

@vladikoff @pdehaan Removed the comments, and the unnecessary statements, switched EMAIL to email. Passes tests locally. :)

@pdehaan
Copy link
Contributor

@pdehaan pdehaan commented Jun 12, 2015

@TDA:

Running "eslint:tests" (eslint) task
tests/functional/oauth_webchannel.js
  61:6  error  Trailing spaces not allowed  no-trailing-spaces
tests/functional/oauth_webchannel_keys.js
  67:6  error  Trailing spaces not allowed  no-trailing-spaces
✖ 2 problems (2 errors, 0 warnings)
Warning: Task "eslint:tests" failed.� Use --force to continue.
Aborted due to warnings.

Those were the first/only errors I saw in the Travis logs. After fixing them you'll want to make sure you run $ grunt lint locally to make sure there weren't others.

@TDA TDA force-pushed the TDA:issue-2550-switch-to-ESLint branch from 0c73028 to 24b3e0e Jun 12, 2015
@TDA
Copy link
Contributor Author

@TDA TDA commented Jun 12, 2015

@pdehaan That was actually my stupid mistake. I have this habit of saving stuff before closing them, and sublimetext 3 has its weird way of autopushing to git when I save. And I didn't realize I had accidentally hit 'space' when pressing 'cmd' key. Oh well, fixed now.

@@ -12,7 +11,7 @@ define([
'lib/xhr',
'lib/promise'
],
function (chai, sinon, $, _, Xhr, p, undefined) {
function (chai, sinon, $, _, Xhr, p, undefined) { //eslint-disable-line no-shadow-restricted-names

This comment has been minimized.

@zaach

zaach Jun 12, 2015
Contributor

This convention of declaring undefined seems unnecessary. Let's just ditch it.

This comment has been minimized.

@TDA

TDA Jun 12, 2015
Author Contributor

Done!

@@ -23,7 +23,7 @@ define([
var TOO_YOUNG_YEAR = new Date().getFullYear() - 13;
var OLD_ENOUGH_YEAR = TOO_YOUNG_YEAR - 1;

var client;
var client; //eslint-disable-line no-unused-vars

This comment has been minimized.

@TDA

TDA Jun 12, 2015
Author Contributor

Ok, cool, this needed the XHR stuff to be removed as well.

@@ -40,7 +38,7 @@ function (chai, $, sinon, BaseView, p, Translator, EphemeralMessages, Metrics,
var translator;
var metrics;
var fxaClient;
var relier;
var relier; //eslint-disable-line no-unused-vars

This comment has been minimized.

@zaach

zaach Jun 12, 2015
Contributor

relier is not used in this file, so we can remove it and remove Relier from the module list so that amdcheck passes.

This comment has been minimized.

@TDA

TDA Jun 12, 2015
Author Contributor

Done, and I found why I couldn't do this yesterday. So if we remove the relier dependency, we need to remove the formal parameter Relier as well for the tests to pass :D I missed that yesterday, which is why the "firefox platform" error was thrown :D

@@ -36,7 +34,7 @@ function (chai, sinon, p, View, AuthErrors, Metrics, Constants, FxaClient,
var relier;
var broker;
var user;
var account;
var account; //eslint-disable-line no-unused-vars

This comment has been minimized.

@zaach

zaach Jun 12, 2015
Contributor

account is not used in this file, so we can remove all references to it.

This comment has been minimized.

@TDA

TDA Jun 12, 2015
Author Contributor

Okie, this one was straightforward.

@@ -273,7 +271,7 @@ function (chai, sinon, p, AuthErrors, Metrics, FxaClient, InterTabChannel,
});

it('non-direct-access signs the user in and redirects to `/reset_password_complete` if broker does not say halt', function () {
var account;
var account; //eslint-disable-line no-unused-vars

This comment has been minimized.

@zaach

zaach Jun 12, 2015
Contributor

This one is kind of legit– we need account so that we can make the assertion here. But we can refactor this to make it better!

We can remove account and it's usage here and just return newAccount directly. Then, for the test here we can use some of Sinon's reflection capabilities and do:

 assert.isTrue(broker.afterCompleteResetPassword.calledWith(user.setSignedInAccount.returnValues[0]));

This comment has been minimized.

@TDA

TDA Jun 12, 2015
Author Contributor

Changing the assertions to this results in the following assertionerrors being thrown:
screen shot 2015-06-12 at 1 11 03 pm
@zaach

This comment has been minimized.

@zaach

zaach Jun 12, 2015
Contributor

Oh right, it returns a Promise. You'll have to put something like this as the last assertion in the block instead:

return user.setSignedInAccount.returnValues[0].then(function (returnValue) {
  assert.isTrue(broker.afterCompleteResetPassword.calledWith(returnValue));
});

The return statement ensures that if the assertion fails and causes the promise to throw, the test will fail.

This comment has been minimized.

@TDA

TDA Jun 12, 2015
Author Contributor

Awesome! It runs now :) Just pushed.

P.s: Sinon is an anime character 💃

@@ -317,7 +315,7 @@ function (chai, sinon, p, AuthErrors, Metrics, FxaClient, InterTabChannel,
});

it('direct access signs the user in and redirects to `/settings` if broker does not say halt', function () {
var account;
var account; //eslint-disable-line no-unused-vars

This comment has been minimized.

@zaach

zaach Jun 12, 2015
Contributor

Same as before

@@ -33,7 +31,7 @@ define([

windowMock = new WindowMock();

view = new View({
void new View({

This comment has been minimized.

@zaach

zaach Jun 12, 2015
Contributor

👍 :D

@@ -30,7 +28,7 @@ function (chai, $, sinon, View, RouterMock, WindowMock, TestHelpers,
describe('views/settings', function () {
var view;
var routerMock;
var windowMock;
var windowMock; //eslint-disable-line no-unused-vars

This comment has been minimized.

@zaach

zaach Jun 12, 2015
Contributor

windowMock isn't used in this file, so let's remove it and the WindowMock module so that amdcheck passes.

@zaach
Copy link
Contributor

@zaach zaach commented Jun 12, 2015

I made some more comments. I think those should be the last things we have to fix.

239 files changed! Wow. It's like our codebase hadn't brushed its teeth in 2 years and finally went to the dentist.

@TDA
Copy link
Contributor Author

@TDA TDA commented Jun 12, 2015

Wow @zaach , ok let me fix these up :)

Fixes #2550
Switch from JSHint to ESLint
Add rules to ESLint
Also have JSHint in parallel
Remove old dependencies reported by amdcheck
Remove unused variables reported by ESLint
@TDA TDA force-pushed the TDA:issue-2550-switch-to-ESLint branch from 24b3e0e to 1e02332 Jun 12, 2015
@TDA
Copy link
Contributor Author

@TDA TDA commented Jun 12, 2015

@zaach Seems right?

@pdehaan
Copy link
Contributor

@pdehaan pdehaan commented Jun 15, 2015

@zaach @vladikoff @shane-tomlinson Anybody want to look at this one last time before merging?

vladikoff added a commit that referenced this pull request Jun 15, 2015
chore(lint): switch from JSHint to ESLint r=vladikoff
@vladikoff vladikoff merged commit c089ae6 into mozilla:master Jun 15, 2015
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage remained the same at 98.51%
Details
@TDA TDA mentioned this pull request Jun 16, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants