chore(lint): switch from JSHint to ESLint #2578
Conversation
|
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? |
| "valid-typeof": 2, | ||
| "wrap-iife": 0 | ||
| } | ||
| } |
vladikoff
Jun 10, 2015
Contributor
need new line at the end of file here
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", | |||
vladikoff
Jun 10, 2015
Contributor
lock this to 14.0.0 or highest released version , don't use ^
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 | |||
vladikoff
Jun 10, 2015
Contributor
what is the warning here?
what is the warning here?
| "mocha": true, | ||
| "browser": true, | ||
| "builtin": true | ||
| }, |
vladikoff
Jun 10, 2015
Contributor
does eslint support extending config, so we don't have to repeat this in two files? cc @pdehaan
does eslint support extending config, so we don't have to repeat this in two files? cc @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.
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.
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)
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)
TDA
Jun 11, 2015
Author
Contributor
Will check this out :)
Will check this out :)
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
Setting Node: false actually throws 21 errors of "no-console" in the app/ directory.. What should I do?
@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
I added "no-console": 0, to the .eslintrc file.
https://github.com/mozilla/fxa-content-server/pull/2578/files#r32183274
TDA
Jun 11, 2015
Author
Contributor
Setting no-console: 0 to remedy this.
Setting no-console: 0 to remedy this.
|
@TDA I think @shane-tomlinson confirmed in irc that we should use |
3118ea8
to
ccd2a56
|
@vladikoff: Was just confirming :) I guess it passes the tests now. |
| 'use strict'; | ||
|
|
||
| module.exports = function (grunt) { | ||
| grunt.config('eslint', { |
vladikoff
Jun 10, 2015
Contributor
@TDA we need to run this task in https://github.com/mozilla/fxa-content-server/blob/master/grunttasks/lint.js#L10
@TDA we need to run this task in https://github.com/mozilla/fxa-content-server/blob/master/grunttasks/lint.js#L10
1bdea19
to
fdc1434
| @@ -7,6 +7,10 @@ | |||
|
|
|||
| module.exports = function (grunt) { | |||
| grunt.registerTask('lint', 'lint all the things', [ | |||
| 'concurrent:lint' | |||
| 'eslint', | |||
vladikoff
Jun 10, 2015
Contributor
bad spacing / bad indent
bad spacing / bad indent
261079e
to
72c4463
|
|
@vladikoff So i remove those unused variables? or change the lint rule? |
|
@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 |
|
@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. |
|
@TDA , see #2578 (comment) last line |
|
@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, |
pdehaan
Jun 11, 2015
Contributor
IIRC, we don't need to add define as a global here if we have the "amd" env.
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 |
pdehaan
Jun 11, 2015
Contributor
nit: Can we sort these A-Z.
nit: Can we sort these A-Z.
TDA
Jun 11, 2015
Author
Contributor
Yes, will do! :)
Yes, will do! :)
| "no-spaced-func": 0, | ||
| "no-undef": 2, | ||
| "no-underscore-dangle": 0, | ||
| "no-unused-vars": [1, {vars: all, args: none}], |
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.
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.
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?
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?
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. ;)
I'd say let's keep it JSON for consistency's sake. No need for yet another markup language at this point. ;)
vladikoff
Jun 11, 2015
Contributor
-1 on YAML
-1 on YAML
pdehaan
Jun 11, 2015
Contributor
Haters.
Haters.
pdehaan
Jun 11, 2015
Contributor
@TDA: Please add .eslintrc (and .jscsrc while we're in there) to the /grunttasks/jsonlint.js:11 file.
@TDA: Please add .eslintrc (and .jscsrc while we're in there) to the /grunttasks/jsonlint.js:11 file.
TDA
Jun 11, 2015
Author
Contributor
Ok will do :)
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 | |||
pdehaan
Jun 11, 2015
Contributor
nit: Add a space between { and the //eslint comment:
} catch (e) { //eslint-disable-line no-empty
nit: Add a space between { and the //eslint comment:
} catch (e) { //eslint-disable-line no-empty
zaach
Jun 11, 2015
Contributor
Is there a lint rule for this? ;)
Is there a lint rule for this? ;)
pdehaan
Jun 11, 2015
Contributor
Yeah, I'm actually a bit surprised that JSCS wouldn't have complained.
Yeah, I'm actually a bit surprised that JSCS wouldn't have complained.
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.
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 */ | |||
pdehaan
Jun 11, 2015
Contributor
What about using // eslint-disable-line on line 43?
What about using // eslint-disable-line on line 43?
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.
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'); |
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)
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)
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.
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'); | |||
pdehaan
Jun 11, 2015
Contributor
Wait, why was this removed?
Wait, why was this removed?
jrgm
Jun 11, 2015
Contributor
redundant require. See line 12 above.
redundant require. See line 12 above.
zaach
Jun 12, 2015
Contributor
Wat. Good thing the config is idempotent.
Wat. Good thing the config is idempotent.
| @@ -41,7 +40,8 @@ define([ | |||
|
|
|||
| beforeEach: function () { | |||
| email = TestHelpers.createEmail(); | |||
| user = TestHelpers.emailToUser(email); | |||
| // removed variable user | |||
vladikoff
Jun 12, 2015
Contributor
remove this comment
remove this comment
| @@ -41,7 +40,8 @@ define([ | |||
|
|
|||
| beforeEach: function () { | |||
| email = TestHelpers.createEmail(); | |||
| user = TestHelpers.emailToUser(email); | |||
| // removed variable user | |||
| TestHelpers.emailToUser(email); | |||
vladikoff
Jun 12, 2015
Contributor
this is not used ?
this is not used ?
| email2 = TestHelpers.createEmail(); | ||
| user2 = TestHelpers.emailToUser(email2); | ||
| // removed variable user2 |
vladikoff
Jun 12, 2015
Contributor
remove comment, also above.
remove comment, also above.
| email2 = TestHelpers.createEmail(); | ||
| user2 = TestHelpers.emailToUser(email2); | ||
| // removed variable user2 | ||
| TestHelpers.emailToUser(email2); |
vladikoff
Jun 12, 2015
Contributor
is this used?
is this used?
TDA
Jun 12, 2015
Author
Contributor
You are right, again :D removed :)
You are right, again :D removed :)
| @@ -39,12 +37,13 @@ define([ | |||
|
|
|||
| beforeEach: function () { | |||
| email = TestHelpers.createEmail(); | |||
| user = TestHelpers.emailToUser(email); | |||
| // removed variable user | |||
vladikoff
Jun 12, 2015
Contributor
see other notes about these
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 | |||
vladikoff
Jun 12, 2015
Contributor
see other notes about these
see other notes about these
|
@vladikoff @pdehaan Removed the comments, and the unnecessary statements, switched EMAIL to email. Passes tests locally. :) |
|
@TDA: Those were the first/only errors I saw in the Travis logs. After fixing them you'll want to make sure you run |
|
@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 | |||
|
|
|||
zaach
Jun 12, 2015
Contributor
This convention of declaring undefined seems unnecessary. Let's just ditch it.
This convention of declaring undefined seems unnecessary. Let's just ditch it.
TDA
Jun 12, 2015
Author
Contributor
Done!
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 | |||
zaach
Jun 12, 2015
Contributor
client doesn't seem to be used. Can we remove it and the lines here: https://github.com/mozilla/fxa-content-server/pull/2578/files#diff-420999c0bd8fd929634bff4b02e76788R67
We also no longer need the FxaClient module, so it can be removed from the module list: https://github.com/mozilla/fxa-content-server/pull/2578/files#diff-420999c0bd8fd929634bff4b02e76788R12, https://github.com/mozilla/fxa-content-server/pull/2578/files#diff-420999c0bd8fd929634bff4b02e76788R16
client doesn't seem to be used. Can we remove it and the lines here: https://github.com/mozilla/fxa-content-server/pull/2578/files#diff-420999c0bd8fd929634bff4b02e76788R67
We also no longer need the FxaClient module, so it can be removed from the module list: https://github.com/mozilla/fxa-content-server/pull/2578/files#diff-420999c0bd8fd929634bff4b02e76788R12, https://github.com/mozilla/fxa-content-server/pull/2578/files#diff-420999c0bd8fd929634bff4b02e76788R16
TDA
Jun 12, 2015
Author
Contributor
Ok, cool, this needed the XHR stuff to be removed as well.
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 | |||
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.
relier is not used in this file, so we can remove it and remove Relier from the module list so that amdcheck passes.
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
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 | |||
zaach
Jun 12, 2015
Contributor
account is not used in this file, so we can remove all references to it.
account is not used in this file, so we can remove all references to it.
TDA
Jun 12, 2015
Author
Contributor
Okie, this one was straightforward.
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 | |||
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 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]));
TDA
Jun 12, 2015
Author
Contributor
Changing the assertions to this results in the following assertionerrors being thrown:

@zaach
Changing the assertions to this results in the following assertionerrors being thrown:

@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.
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.
TDA
Jun 12, 2015
Author
Contributor
Awesome! It runs now :) Just pushed.
P.s: Sinon is an anime character 💃
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 | |||
| @@ -33,7 +31,7 @@ define([ | |||
|
|
|||
| windowMock = new WindowMock(); | |||
|
|
|||
| view = new View({ | |||
| void new View({ | |||
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 | |||
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.
windowMock isn't used in this file, so let's remove it and the WindowMock module so that amdcheck passes.
|
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. |
|
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
|
@zaach Seems right? |
|
@zaach @vladikoff @shane-tomlinson Anybody want to look at this one last time before merging? |
chore(lint): switch from JSHint to ESLint r=vladikoff
Fixes #2550
Switch from JSHint to ESLint
Also have JSHint in parallel
References #2558, runs into same problem
@zaach