Fixes #274
Add ESLint
Remove JSHint
Lint the files and fix errors
This commit is contained in:
Sai Pc 2015-06-17 11:37:01 -07:00
Родитель fe7b0359e3
Коммит 1531061fba
25 изменённых файлов: 30 добавлений и 90 удалений

11
.eslintrc Normal file
Просмотреть файл

@ -0,0 +1,11 @@
{
"extends": "fxa",
"env": {
"mocha": true
},
"rules": {
"handle-callback-err": 0,
"complexity": [2, 10],
"strict": 0
}
}

Просмотреть файл

@ -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
}

Просмотреть файл

@ -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.

Просмотреть файл

@ -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'
});

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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;
});

Просмотреть файл

@ -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'
};

Просмотреть файл

@ -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)

Просмотреть файл

@ -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++) {

Просмотреть файл

@ -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,

Просмотреть файл

@ -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: {

Просмотреть файл

@ -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),

Просмотреть файл

@ -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,

Просмотреть файл

@ -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,

Просмотреть файл

@ -14,7 +14,6 @@ function developerResponse(developer) {
};
}
/*jshint camelcase: false*/
module.exports = {
auth: {
strategy: auth.AUTH_STRATEGY,

Просмотреть файл

@ -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()

Просмотреть файл

@ -8,8 +8,6 @@ const config = require('../config');
const token = require('../token');
const validators = require('../validators');
/*jshint camelcase: false*/
module.exports = {
validate: {
payload: {

Просмотреть файл

@ -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);

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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",

Просмотреть файл

@ -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 %>'

Просмотреть файл

@ -8,7 +8,7 @@ module.exports = function (grunt) {
'use strict';
grunt.registerTask('lint', [
'jshint',
'eslint',
'jscs'
]);
};

Просмотреть файл

@ -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);

Просмотреть файл

@ -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');
});
});

Просмотреть файл

@ -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');