From 1531061fbae6d834279c697eb3eed82bedebea17 Mon Sep 17 00:00:00 2001 From: Sai Pc Date: Wed, 17 Jun 2015 11:37:01 -0700 Subject: [PATCH] chore(lint): add ESLint Fixes #274 Add ESLint Remove JSHint Lint the files and fix errors --- .eslintrc | 11 +++++++++++ .jshintrc | 28 ---------------------------- CONTRIBUTING.md | 4 ++-- Gruntfile.js | 2 +- lib/db/memory.js | 3 --- lib/db/mysql/index.js | 9 ++++----- lib/error.js | 2 -- lib/logging/summary.js | 1 - lib/routes/authorization.js | 2 -- lib/routes/client/delete.js | 1 - lib/routes/client/get.js | 1 - lib/routes/client/list.js | 2 -- lib/routes/client/register.js | 1 - lib/routes/client/update.js | 1 - lib/routes/developer/activate.js | 1 - lib/routes/token.js | 2 -- lib/routes/verify.js | 2 -- lib/server/internal.js | 2 -- lib/token.js | 2 -- package.json | 4 ++-- tasks/{jshint.js => eslint.js} | 5 ++--- tasks/lint.js | 2 +- test/api.js | 27 ++++++--------------------- test/db.js | 3 --- test/server.js | 2 +- 25 files changed, 30 insertions(+), 90 deletions(-) create mode 100644 .eslintrc delete mode 100644 .jshintrc rename tasks/{jshint.js => eslint.js} (77%) diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 000000000..cdb7bb48c --- /dev/null +++ b/.eslintrc @@ -0,0 +1,11 @@ +{ + "extends": "fxa", + "env": { + "mocha": true + }, + "rules": { + "handle-callback-err": 0, + "complexity": [2, 10], + "strict": 0 + } +} diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 22b7084c1..000000000 --- a/.jshintrc +++ /dev/null @@ -1,28 +0,0 @@ -{ - "bitwise": false, - "boss": true, - "browser": true, - "camelcase": true, - "curly": true, - "esnext": true, - "eqeqeq": true, - "eqnull": true, - "expr": true, - "forin": false, - "indent": 2, - "latedef": true, - "laxbreak": true, - "laxcomma": true, - "maxcomplexity": 10, - "maxlen": 80, - "maxerr": 100, - "node": true, - "noarg": true, - "passfail": false, - "shadow": true, - "strict": false, - "supernew": false, - "trailing": true, - "undef": true, - "unused": true -} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 75e17fd6e..d80b4b04e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,7 +18,7 @@ Patches should be submitted as pull requests (PR). Before submitting a PR: - Your code must run and pass all the automated tests before you submit your PR for review. "Work in progress" pull requests are allowed to be submitted, but should be clearly labeled as such and should not be merged until all tests pass and the code has been reviewed. - - Run `grunt jshint` to make sure your code passes linting. + - Run `grunt eslint` to make sure your code passes linting. - Run `npm test` to make sure all tests still pass. - Your patch should include new tests that cover your changes. It is your and your reviewer's responsibility to ensure your patch includes adequate tests. @@ -26,7 +26,7 @@ When submitting a PR: - You agree to license your code under the project's open source license ([MPL 2.0](/LICENSE)). - Base your branch off the current `master` (see below for an example workflow). - Add both your code and new tests if relevant. -- Run `grunt jshint` and `npm test` to make sure your code passes linting and tests. +- Run `grunt eslint` and `npm test` to make sure your code passes linting and tests. - Please do not include merge commits in pull requests; include only commits with the new relevant code. See the main [README.md](/README.md) for information on prerequisites, installing, running and testing. diff --git a/Gruntfile.js b/Gruntfile.js index dc7a3eaf0..7bd4ce3be 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -12,7 +12,7 @@ module.exports = function (grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('./package.json'), - // .js files for JSHint, JSCS, etc. + // .js files for ESLint, JSHint, JSCS, etc. mainJsFiles: '{,lib/**/,scripts/**/,test/**/,tasks/**/,bin/**/}*.js' }); diff --git a/lib/db/memory.js b/lib/db/memory.js index 01a1059f9..e7bef2145 100644 --- a/lib/db/memory.js +++ b/lib/db/memory.js @@ -180,7 +180,6 @@ MemoryStore.prototype = { return P.resolve(); }, generateCode: function generateCode(clientId, userId, email, scope, authAt) { - var code = {}; code.clientId = clientId; code.userId = userId; @@ -306,10 +305,8 @@ MemoryStore.prototype = { return self.getClientDevelopers(clientId); }) .then(function (developers) { - var result; function hasDeveloper(developer) { - result = developer; return unbuf(developer.developerId) === unbuf(developerId); } diff --git a/lib/db/mysql/index.js b/lib/db/mysql/index.js index 527a3ac34..7a7c35c64 100644 --- a/lib/db/mysql/index.js +++ b/lib/db/mysql/index.js @@ -354,9 +354,9 @@ MysqlStore.prototype = { type: 'bearer' }; var _token = unique.token(); - var me = this; + var self = this; var hash = encrypt.hash(_token); - return me._write(QUERY_TOKEN_INSERT, [ + return self._write(QUERY_TOKEN_INSERT, [ t.clientId, t.userId, t.email, @@ -385,16 +385,15 @@ MysqlStore.prototype = { getEncodingInfo: function getEncodingInfo() { var info = {}; - var me = this; + var self = this; var qry = 'SHOW VARIABLES LIKE "%character\\_set\\_%"'; return this._read(qry).then(function(rows) { - /*jshint camelcase:false*/ rows.forEach(function(row) { info[row.Variable_name] = row.Value; }); qry = 'SHOW VARIABLES LIKE "%collation\\_%"'; - return me._read(qry).then(function(rows) { + return self._read(qry).then(function(rows) { rows.forEach(function(row) { info[row.Variable_name] = row.Value; }); diff --git a/lib/error.js b/lib/error.js index 4b0bf58f8..50bbfc92c 100644 --- a/lib/error.js +++ b/lib/error.js @@ -8,9 +8,7 @@ const DEFAULTS = { code: 500, error: 'Internal Server Error', errno: 999, - /*jshint ignore:start,-W101*/ info: 'https://github.com/mozilla/fxa-oauth-server/blob/master/docs/api.md#errors', - /*jshint ignore:end,+W101*/ message: 'Unspecified error' }; diff --git a/lib/logging/summary.js b/lib/logging/summary.js index e5b7c44b1..b17da3579 100644 --- a/lib/logging/summary.js +++ b/lib/logging/summary.js @@ -24,7 +24,6 @@ module.exports = function summary(request, response) { path: request.path, agent: request.headers['user-agent'], t: Date.now() - request.info.received, - /*jshint camelcase: false*/ client_id: payload.client_id || query.client_id || params.client_id, auth: auth, payload: Object.keys(payload) diff --git a/lib/routes/authorization.js b/lib/routes/authorization.js index 494c2e6d3..e8a449d8a 100644 --- a/lib/routes/authorization.js +++ b/lib/routes/authorization.js @@ -24,8 +24,6 @@ const UNTRUSTED_CLIENT_ALLOWED_SCOPES = [ 'profile:display_name' ]; -/*jshint camelcase: false*/ - function set(arr) { var obj = {}; for (var i = 0; i < arr.length; i++) { diff --git a/lib/routes/client/delete.js b/lib/routes/client/delete.js index 49fcbb35e..481c9f419 100644 --- a/lib/routes/client/delete.js +++ b/lib/routes/client/delete.js @@ -7,7 +7,6 @@ const db = require('../../db'); const validators = require('../../validators'); const AppError = require('../../error'); -/*jshint camelcase: false*/ module.exports = { auth: { strategy: auth.AUTH_STRATEGY, diff --git a/lib/routes/client/get.js b/lib/routes/client/get.js index 1859bc482..bf27a22a1 100644 --- a/lib/routes/client/get.js +++ b/lib/routes/client/get.js @@ -10,7 +10,6 @@ const db = require('../../db'); const logger = require('../../logging')('routes.client.get'); const validators = require('../../validators'); -/*jshint camelcase: false*/ module.exports = { validate: { params: { diff --git a/lib/routes/client/list.js b/lib/routes/client/list.js index 40a8f43b5..70c469265 100644 --- a/lib/routes/client/list.js +++ b/lib/routes/client/list.js @@ -9,8 +9,6 @@ const auth = require('../../auth'); const db = require('../../db'); const validators = require('../../validators'); -/*jshint camelcase: false*/ - function serialize(client) { return { id: hex(client.id), diff --git a/lib/routes/client/register.js b/lib/routes/client/register.js index f5b2ebd33..c673988d1 100644 --- a/lib/routes/client/register.js +++ b/lib/routes/client/register.js @@ -12,7 +12,6 @@ const unique = require('../../unique'); const validators = require('../../validators'); const AppError = require('../../error'); -/*jshint camelcase: false*/ module.exports = { auth: { strategy: auth.AUTH_STRATEGY, diff --git a/lib/routes/client/update.js b/lib/routes/client/update.js index a275e5035..7ce4d42d5 100644 --- a/lib/routes/client/update.js +++ b/lib/routes/client/update.js @@ -10,7 +10,6 @@ const db = require('../../db'); const validators = require('../../validators'); const AppError = require('../../error'); -/*jshint camelcase: false*/ module.exports = { auth: { strategy: auth.AUTH_STRATEGY, diff --git a/lib/routes/developer/activate.js b/lib/routes/developer/activate.js index 353a49429..68e5bed76 100644 --- a/lib/routes/developer/activate.js +++ b/lib/routes/developer/activate.js @@ -14,7 +14,6 @@ function developerResponse(developer) { }; } -/*jshint camelcase: false*/ module.exports = { auth: { strategy: auth.AUTH_STRATEGY, diff --git a/lib/routes/token.js b/lib/routes/token.js index b240aeb0a..4ea6c3d32 100644 --- a/lib/routes/token.js +++ b/lib/routes/token.js @@ -19,7 +19,6 @@ function generateToken(code) { } function toToken(authAt, _, token) { - /*jshint camelcase: false*/ return { access_token: token.token.toString('hex'), token_type: token.type, @@ -30,7 +29,6 @@ function toToken(authAt, _, token) { var payloadSchema = Joi.object({ - /*jshint camelcase: false*/ client_id: validators.clientId, client_secret: validators.clientSecret, code: Joi.string() diff --git a/lib/routes/verify.js b/lib/routes/verify.js index 3097f28b8..37982a6f5 100644 --- a/lib/routes/verify.js +++ b/lib/routes/verify.js @@ -8,8 +8,6 @@ const config = require('../config'); const token = require('../token'); const validators = require('../validators'); -/*jshint camelcase: false*/ - module.exports = { validate: { payload: { diff --git a/lib/server/internal.js b/lib/server/internal.js index 701ed174c..c4dbe7f77 100644 --- a/lib/server/internal.js +++ b/lib/server/internal.js @@ -19,8 +19,6 @@ exports.create = function createServer() { require('./config') ); - - server.auth.scheme(auth.AUTH_SCHEME, auth.strategy); server.auth.strategy(auth.AUTH_STRATEGY, auth.AUTH_SCHEME); diff --git a/lib/token.js b/lib/token.js index ee1f3079c..06596b8b6 100644 --- a/lib/token.js +++ b/lib/token.js @@ -7,8 +7,6 @@ const auth = require('./auth'); const db = require('./db'); const encrypt = require('./encrypt'); -/*jshint camelcase: false*/ - exports.verify = function verify(token) { return db.getToken(encrypt.hash(token)) .then(function(token) { diff --git a/package.json b/package.json index 4a9373656..bacdcc3b8 100644 --- a/package.json +++ b/package.json @@ -39,17 +39,17 @@ "awsbox": "^0.7.0", "blanket": "^1.1.6", "browserid-crypto": "^0.7.0", + "eslint-config-fxa": "^1.4.0", "grunt": "^0.4.5", "grunt-cli": "^0.1.13", - "grunt-contrib-jshint": "^0.11.1", "grunt-conventional-changelog": "^1.1.0", "grunt-copyright": "^0.1.0", + "grunt-eslint": "^15.0.0", "grunt-jscs": "^1.5.0", "grunt-mocha-test": "^0.12.2", "grunt-nodemon": "^0.4.0", "grunt-nsp-shrinkwrap": "^0.0.3", "insist": "0.x", - "jshint-stylish": "^1.0.1", "load-grunt-tasks": "^3.1.0", "mocha-text-cov": "^0.1.0", "nock": "^1.2.1", diff --git a/tasks/jshint.js b/tasks/eslint.js similarity index 77% rename from tasks/jshint.js rename to tasks/eslint.js index c66189655..bb26669e2 100644 --- a/tasks/jshint.js +++ b/tasks/eslint.js @@ -5,10 +5,9 @@ module.exports = function (grunt) { 'use strict'; - grunt.config('jshint', { + grunt.config('eslint', { options: { - jshintrc: '.jshintrc', - reporter: require('jshint-stylish') + eslintrc: '.eslintrc' }, app: [ '<%= mainJsFiles %>' diff --git a/tasks/lint.js b/tasks/lint.js index d4677a8a3..8a029d009 100644 --- a/tasks/lint.js +++ b/tasks/lint.js @@ -8,7 +8,7 @@ module.exports = function (grunt) { 'use strict'; grunt.registerTask('lint', [ - 'jshint', + 'eslint', 'jscs' ]); }; diff --git a/test/api.js b/test/api.js index e03dd5c4e..b54238c7b 100644 --- a/test/api.js +++ b/test/api.js @@ -3,7 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ const url = require('url'); - const assert = require('insist'); const bidcrypto = require('browserid-crypto'); const nock = require('nock'); @@ -19,9 +18,6 @@ const unique = require('../lib/unique'); require('browserid-crypto/lib/algs/ds'); -/*global describe,it,before,beforeEach,afterEach*/ -/*jshint camelcase: false*/ - const USERID = unique(16).toString('hex'); const VEMAIL = unique(4).toString('hex') + '@mozilla.com'; const VERIFY_GOOD = JSON.stringify({ @@ -910,12 +906,11 @@ describe('/v1', function() { }); it('should return a list of clients for a developer', function() { - var uid, vemail, tok; + var vemail, tok; return getUniqueUserAndToken(clientId) .then(function(data) { tok = data.token; - uid = data.uid; vemail = data.email; // make this user a developer return db.activateDeveloper(vemail); @@ -942,8 +937,6 @@ describe('/v1', function() { }); describe('POST', function() { - var developer; - before(function() { return Server.internal.api.post({ url: '/developer/activate', @@ -951,7 +944,6 @@ describe('/v1', function() { authorization: 'Bearer ' + tok } }).then(function(res) { - developer = res.result; }); }); @@ -1050,7 +1042,7 @@ describe('/v1', function() { var id = unique.id(); it('should forbid update to unknown developers', function() { - var uid, vemail, tok, devId; + var vemail, tok; var id = unique.id(); var client = { name: 'test/api/update', @@ -1067,14 +1059,12 @@ describe('/v1', function() { }) .then(function(data) { tok = data.token; - uid = data.uid; vemail = data.email; return db.activateDeveloper(vemail); }).then(function () { return db.getDeveloper(vemail); }).then(function (developer) { - devId = developer.developerId; }).then(function () { return Server.internal.api.post({ url: '/client/' + id.toString('hex'), @@ -1092,7 +1082,7 @@ describe('/v1', function() { }); it('should allow client update', function() { - var uid, vemail, tok, devId; + var vemail, tok, devId; var id = unique.id(); var client = { name: 'test/api/update2', @@ -1111,7 +1101,6 @@ describe('/v1', function() { }) .then(function(data) { tok = data.token; - uid = data.uid; vemail = data.email; return db.activateDeveloper(vemail); @@ -1211,7 +1200,7 @@ describe('/v1', function() { describe('DELETE /:id', function() { it('should delete the client', function() { - var uid, vemail, tok, devId; + var vemail, tok, devId; var id = unique.id(); var client = { name: 'test/api/deleteOwner', @@ -1228,7 +1217,6 @@ describe('/v1', function() { }) .then(function(data) { tok = data.token; - uid = data.uid; vemail = data.email; return db.activateDeveloper(vemail); @@ -1257,7 +1245,7 @@ describe('/v1', function() { }); it('should not delete the client if not owner', function() { - var uid, vemail, tok, devId; + var vemail, tok; var id = unique.id(); var client = { name: 'test/api/deleteOwner', @@ -1274,14 +1262,12 @@ describe('/v1', function() { }) .then(function(data) { tok = data.token; - uid = data.uid; vemail = data.email; return db.activateDeveloper(vemail); }).then(function () { return db.getDeveloper(vemail); }).then(function (developer) { - devId = developer.developerId; }).then(function () { return Server.internal.api.delete({ url: '/client/' + id.toString('hex'), @@ -1330,12 +1316,11 @@ describe('/v1', function() { describe('/developer', function() { describe('POST /developer/activate', function() { it('should create a developer', function(done) { - var uid, vemail, tok; + var vemail, tok; return getUniqueUserAndToken(clientId) .then(function(data) { tok = data.token; - uid = data.uid; vemail = data.email; return db.getDeveloper(vemail); diff --git a/test/db.js b/test/db.js index 8c5a1c543..28b78e686 100644 --- a/test/db.js +++ b/test/db.js @@ -86,7 +86,6 @@ describe('db', function() { return db.getEncodingInfo() .then(function(info) { - /*jshint sub:true*/ assert.equal(info['character_set_connection'], 'utf8'); assert.equal(info['character_set_database'], 'utf8'); assert.equal(info['collation_connection'], 'utf8_unicode_ci'); @@ -232,7 +231,6 @@ describe('db', function() { var email = 'a@b.c'; var scope = ['no-scope']; var code = null; - var token = null; before(function() { return db.registerClient({ @@ -256,7 +254,6 @@ describe('db', function() { scope: scope }); }).then(function(t) { - token = t.token; assert.equal(hex(t.userId), hex(userId), 'token userId'); }); }); diff --git a/test/server.js b/test/server.js index 61c0a3631..d7a94cab2 100644 --- a/test/server.js +++ b/test/server.js @@ -18,7 +18,7 @@ describe('server', function() { assert.equal(res.result.version, require('../package.json').version); assert(res.result.commit); - // and must return an STS header + // and must return an STS header var stsHeader = res.headers['strict-transport-security']; assert.equal(stsHeader, 'max-age=15552000; includeSubdomains');