Skip to content

Commit

Permalink
chore(lint): switch from JSHint to ESLint
Browse files Browse the repository at this point in the history
Fixes mozilla#2550
Switch from JSHint to ESLint
Also have JSHint in parallel
  • Loading branch information
TDA committed Jun 10, 2015
1 parent 38ab1c0 commit 1bdea19
Show file tree
Hide file tree
Showing 23 changed files with 176 additions and 21 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.tmp/**
app/bower_components/**
app/scripts/vendor/**
dist/**
52 changes: 52 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"env": {
"amd": true,
"es6": true,
"jasmine": true,
"node": true,
"mocha": true,
"browser": true,
"builtin": true
},
"rules": {
"camelcase": 0,
"comma-dangle": 0,
"complexity": [2, 6],
"consistent-return": 0,
"curly": [2, "all"],
"dot-notation": 0,
"eqeqeq": [2, "allow-null"],
"global-strict": [0, "never"],
"globals": {
"define": true,
"Promise": true
},
"handle-callback-err": 0,
"key-spacing": 0,
"new-cap": 0,
"no-cond-assign": [2, "except-parens"],
"no-debugger": 2,
"no-empty": 0,
"no-eval": 2,
"no-irregular-whitespace": 2,
"no-loop-func": 0,
"no-multi-spaces": 0,
"no-new": 2,
"no-script-url": 2,
"no-sequences": 2,
"no-shadow": 0,
"no-spaced-func": 0,
"no-undef": 2,
"no-underscore-dangle": 0,
"no-unused-vars": [1, {vars: all, args: none}],
"no-use-before-define": true,
"no-with": 2,
"quotes": [2, "single"],
"semi": [2, "always"],
"space-unary-ops": 0,
"strict": 2,
"valid-typeof": 1,
"wrap-iife": 0,
"yoda": 0
}
}
58 changes: 58 additions & 0 deletions app/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"env": {
"amd": true,
"es6": true,
"jasmine": true,
"jquery": true,
"node": true,
"mocha": true,
"browser": true,
"builtin": true
},
"rules": {
"camelcase": 0,
"complexity": [2, 6],
"consistent-return": 0,
"curly": [2, "all"],
"dot-notation": 0,
"eqeqeq": [2, "allow-null"],
"globals": {
"console": false,
"define": true,
"require": false,
"router": false,
"afterEach": false,
"beforeEach": false,
"describe": false,
"it": false
},
"handle-callback-err": 0,
"key-spacing": 0,
"new-cap": 0,
"no-bitwise": 2,
"no-caller": 2,
"no-cond-assign": [2, "except-parens"],
"no-debugger": 2,
"no-empty": 2,
"no-eval": 2,
"no-extend-native": 2,
"no-irregular-whitespace": 2,
"no-loop-func": 0,
"no-multi-str": 2,
"no-new": 2,
"no-proto": 2,
"no-script-url": 2,
"no-sequences": 2,
"no-shadow": 0,
"no-spaced-func": 0,
"no-undef": 2,
"no-unused-vars": [1, {vars: all, args: none}],
"no-use-before-define": true,
"no-with": 2,
"quotes": [2, "single"],
"semi": [2, "always"],
"strict": [2, "global"],
"valid-typeof": 2,
"wrap-iife": 0
}
}
1 change: 1 addition & 0 deletions app/scripts/head/start.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*globals FxaHead */
'use strict';

(function () {
Expand Down
3 changes: 2 additions & 1 deletion app/scripts/lib/app-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ function (
},

initializeAuthenticationBroker: function () {
//jshint maxcomplexity: 7
/*jshint maxcomplexity: 7 */
/*eslint complexity: [2, 7] */
if (! this._authenticationBroker) {
if (this._isFxDesktopV2()) {
this._authenticationBroker = new FxDesktopV2AuthenticationBroker({
Expand Down
3 changes: 2 additions & 1 deletion app/scripts/lib/metrics.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
'use strict';

/*
* A metrics module!
Expand All @@ -14,6 +13,7 @@
* Metrics are automatically sent to the server on window.unload
* but can also be sent by calling metrics.flush();
*/
'use strict';

define([
'underscore',
Expand Down Expand Up @@ -62,6 +62,7 @@ define([

function Metrics (options) {
/*jshint maxcomplexity:18 */
/*eslint complexity: [2, 18] */
options = options || {};

// by default, send the metrics to the content server.
Expand Down
1 change: 1 addition & 0 deletions app/scripts/lib/screen-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ define([

function ScreenInfo(win) {
/*jshint maxcomplexity:8 */
/*eslint complexity: [2, 8] */
var documentElement = win.document.documentElement || {};
var screen = win.screen || {};

Expand Down
2 changes: 1 addition & 1 deletion app/scripts/lib/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
return item;
};
Expand Down
1 change: 1 addition & 0 deletions app/scripts/require_config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
'use strict';

require.config({
baseUrl: '/scripts',
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/views/base.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict';

define([
Expand Down Expand Up @@ -88,6 +87,7 @@ function (Cocktail, _, Backbone, $, p, AuthErrors,
var BaseView = Backbone.View.extend({
constructor: function (options) {
/*jshint maxcomplexity:10 */
/*eslint complexity: [2, 10] */
options = options || {};

this.subviews = [];
Expand Down
4 changes: 1 addition & 3 deletions app/tests/spec/lib/channels/web.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict';


define([
'chai',
'sinon',
Expand All @@ -31,7 +29,7 @@ function (chai, sinon, WebChannel, WindowMock) {

it('requires an id', function () {
assert.throws(function () {
new WebChannel();
new WebChannel();//eslint-disable-line no-new
}, 'WebChannel must have an id');
});

Expand Down
3 changes: 1 addition & 2 deletions app/tests/spec/lib/xhr.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict';

define([
Expand All @@ -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

var assert = chai.assert;

Expand Down
4 changes: 3 additions & 1 deletion app/tests/spec/lib/xss.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ function (chai, _, XSS, Constants) {
});

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

it('disallows href without a scheme', function () {
Expand Down
3 changes: 1 addition & 2 deletions app/tests/spec/views/sign_up.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*global translator */
'use strict';


define([
'chai',
'jquery',
Expand Down
32 changes: 32 additions & 0 deletions grunttasks/eslint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
'use strict';

module.exports = function (grunt) {
grunt.config('eslint', {
options: {
eslintrc: '.eslintrc'
},
grunt: [
'Gruntfile.js',
'grunttasks/*.js'
],
app: {
options: {
eslintrc: '<%= yeoman.app %>/.eslintrc'
},
src: [
'<%= yeoman.app %>/**/*.js',
'!<%= yeoman.app %>/bower_components/**',
'!<%= yeoman.app %>/scripts/vendor/**'
]
},
tests: [
'<%= yeoman.tests %>/**/*.js'
],
server: [
'<%= yeoman.server %>/**/*.js',
]
});
};
6 changes: 5 additions & 1 deletion grunttasks/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

module.exports = function (grunt) {
grunt.registerTask('lint', 'lint all the things', [
'concurrent:lint'
'eslint',
'jshint',
'jsonlint:app',
'jscs',
'amdcheck'
]);
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"grunt-jscs": "1.8.0",
"grunt-jsonlint": "1.0.4",
"grunt-nsp-shrinkwrap": "0.0.3",
Expand Down
9 changes: 5 additions & 4 deletions scripts/run_locally.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
'use strict';

const path = require('path');
const spawn = require('child_process').spawn;
var path = require('path');
var spawn = require('child_process').spawn;


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

module.exports = function (done) {
process.chdir(path.dirname(__dirname));
Expand All @@ -21,7 +22,7 @@ module.exports = function (done) {
if (done) {
done(code);
} else {
process.exit(code);
process.exit(code); //eslint-disable-line no-process-exit
}
});
};
Expand Down
1 change: 0 additions & 1 deletion server/bin/fxa-content-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ if (isMain) {
process.chdir(path.dirname(__dirname));
}

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

var logger = require('mozlog')('server.main');
Expand Down
1 change: 0 additions & 1 deletion server/lib/404.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict';

// It's a 404 not found response.
Expand Down
4 changes: 2 additions & 2 deletions server/lib/csp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
// option 'csp.enabled' is set (default true in development), with a special
// exception for the /tests/index.html path, which are the frontend unit
// tests.

'use strict';

var helmet = require('helmet');
var config = require('./configuration');
var url = require('url');

/*eslint-disable */
var SELF = "'self'"; //jshint ignore: line
/*eslint-enable */
var DATA = 'data:';
var GRAVATAR = 'https://secure.gravatar.com';

Expand Down
1 change: 1 addition & 0 deletions server/lib/statsd-collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var STATSD_PREFIX = 'fxa.content.';

function getGenericTags(body) {
/*jshint maxcomplexity:7 */
/*eslint complexity: [2, 7] */
// see more about tags here: http://docs.datadoghq.com/guides/metrics/
var tags = [
'campaign:' + body.campaign,
Expand Down
1 change: 1 addition & 0 deletions tests/intern.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ define([
],
function (args, topic, firefoxProfile) {
/*jshint maxcomplexity:11 */
/*eslint complexity: [2, 11] */
var fxaAuthRoot = args.fxaAuthRoot || 'http://127.0.0.1:9000/v1';
var fxaContentRoot = args.fxaContentRoot || 'http://127.0.0.1:3030/';
var fxaEmailRoot = args.fxaEmailRoot || 'http://127.0.0.1:9001';
Expand Down

0 comments on commit 1bdea19

Please sign in to comment.