From a52cef2771c7070a7ec842b6f1e9953806c8ea96 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Thu, 17 Aug 2017 17:44:26 +0800 Subject: [PATCH] Add space after async in `async () =>` --- .eslintrc | 6 ++- src/app.js | 6 +-- test/integration/app-test.js | 6 +-- test/integration/email-test.js | 10 ++-- test/integration/mongo-test.js | 22 ++++---- test/integration/public-key-test.js | 78 ++++++++++++++--------------- test/unit/email-test.js | 8 +-- 7 files changed, 70 insertions(+), 66 deletions(-) diff --git a/.eslintrc b/.eslintrc index 54caf24..36a19d3 100644 --- a/.eslintrc +++ b/.eslintrc @@ -41,7 +41,11 @@ "semi": ["warn", "always"], // require or disallow semicolons instead of ASI "semi-spacing": 1, // enforce consistent spacing before and after semicolons "space-before-blocks": 1, // enforce consistent spacing before blocks - "space-before-function-paren": ["warn", "never"], // enforce consistent spacing before function definition opening parenthesis + "space-before-function-paren": ["warn", { + "anonymous": "never", + "named": "never", + "asyncArrow": "always" + }], // enforce consistent spacing before function definition opening parenthesis "space-in-parens": ["warn", "never"], // enforce consistent spacing inside parentheses "space-infix-ops": 1, // require spacing around operators /* ES6 */ diff --git a/src/app.js b/src/app.js index 1121ac6..b4f7eb5 100644 --- a/src/app.js +++ b/src/app.js @@ -54,7 +54,7 @@ router.get('/api/v1/key', ctx => rest.query(ctx)); router.del('/api/v1/key', ctx => rest.remove(ctx)); // Redirect all http traffic to https -app.use(async(ctx, next) => { +app.use(async (ctx, next) => { if (util.isTrue(config.server.httpsUpgrade) && util.checkHTTP(ctx)) { ctx.redirect(`https://${ctx.hostname}${ctx.url}`); } else { @@ -63,7 +63,7 @@ app.use(async(ctx, next) => { }); // Set HTTP response headers -app.use(async(ctx, next) => { +app.use(async (ctx, next) => { // HSTS if (util.isTrue(config.server.httpsUpgrade)) { ctx.set('Strict-Transport-Security', 'max-age=16070400'); @@ -121,7 +121,7 @@ function injectDependencies() { // if (!global.testing) { // don't automatically start server in tests - (async() => { + (async () => { try { const app = await init(); app.listen(config.server.port); diff --git a/test/integration/app-test.js b/test/integration/app-test.js index 3271646..ae5445e 100644 --- a/test/integration/app-test.js +++ b/test/integration/app-test.js @@ -22,7 +22,7 @@ describe('Koa App (HTTP Server) Integration Tests', function() { const primaryEmail = 'safewithme.testuser@gmail.com'; const fingerprint = '4277257930867231CE393FB8DBC0B3D92B1B86E9'; - before(async() => { + before(async () => { sandbox = sinon.sandbox.create(); publicKeyArmored = fs.readFileSync(`${__dirname}/../key1.asc`, 'utf8'); @@ -46,13 +46,13 @@ describe('Koa App (HTTP Server) Integration Tests', function() { app = await init(); }); - beforeEach(async() => { + beforeEach(async () => { await mongo.clear(DB_TYPE_PUB_KEY); await mongo.clear(DB_TYPE_USER_ID); emailParams = null; }); - after(async() => { + after(async () => { sandbox.restore(); await mongo.clear(DB_TYPE_PUB_KEY); await mongo.clear(DB_TYPE_USER_ID); diff --git a/test/integration/email-test.js b/test/integration/email-test.js index cf4eaa3..e3afc2d 100644 --- a/test/integration/email-test.js +++ b/test/integration/email-test.js @@ -36,7 +36,7 @@ describe('Email Integration Tests', function() { }); describe("_sendHelper", () => { - it('should work', async() => { + it('should work', async () => { const mailOptions = { from: email._sender, to: recipient, @@ -50,23 +50,23 @@ describe('Email Integration Tests', function() { }); describe("send verifyKey template", () => { - it('should send plaintext email', async() => { + it('should send plaintext email', async () => { delete userId.publicKeyArmored; await email.send({template: tpl.verifyKey, userId, keyId, origin}); }); - it('should send pgp encrypted email', async() => { + it('should send pgp encrypted email', async () => { await email.send({template: tpl.verifyKey, userId, keyId, origin}); }); }); describe("send verifyRemove template", () => { - it('should send plaintext email', async() => { + it('should send plaintext email', async () => { delete userId.publicKeyArmored; await email.send({template: tpl.verifyRemove, userId, keyId, origin}); }); - it('should send pgp encrypted email', async() => { + it('should send pgp encrypted email', async () => { await email.send({template: tpl.verifyRemove, userId, keyId, origin}); }); }); diff --git a/test/integration/mongo-test.js b/test/integration/mongo-test.js index 4f74d07..9a9f9bb 100644 --- a/test/integration/mongo-test.js +++ b/test/integration/mongo-test.js @@ -9,27 +9,27 @@ describe('Mongo Integration Tests', function() { const DB_TYPE = 'apple'; let mongo; - before(async() => { + before(async () => { mongo = new Mongo(); await mongo.init(config.mongo); }); - beforeEach(async() => { + beforeEach(async () => { await mongo.clear(DB_TYPE); }); - after(async() => { + after(async () => { await mongo.clear(DB_TYPE); await mongo.disconnect(); }); describe("create", () => { - it('should insert a document', async() => { + it('should insert a document', async () => { const r = await mongo.create({_id: '0'}, DB_TYPE); expect(r.insertedCount).to.equal(1); }); - it('should fail if two with the same ID are inserted', async() => { + it('should fail if two with the same ID are inserted', async () => { let r = await mongo.create({_id: '0'}, DB_TYPE); expect(r.insertedCount).to.equal(1); try { @@ -41,12 +41,12 @@ describe('Mongo Integration Tests', function() { }); describe("batch", () => { - it('should insert a document', async() => { + it('should insert a document', async () => { const r = await mongo.batch([{_id: '0'}, {_id: '1'}], DB_TYPE); expect(r.insertedCount).to.equal(2); }); - it('should fail if docs with the same ID are inserted', async() => { + it('should fail if docs with the same ID are inserted', async () => { let r = await mongo.batch([{_id: '0'}, {_id: '1'}], DB_TYPE); expect(r.insertedCount).to.equal(2); try { @@ -58,7 +58,7 @@ describe('Mongo Integration Tests', function() { }); describe("update", () => { - it('should update a document', async() => { + it('should update a document', async () => { let r = await mongo.create({_id: '0'}, DB_TYPE); r = await mongo.update({_id: '0'}, {foo: 'bar'}, DB_TYPE); expect(r.modifiedCount).to.equal(1); @@ -68,7 +68,7 @@ describe('Mongo Integration Tests', function() { }); describe("get", () => { - it('should get a document', async() => { + it('should get a document', async () => { let r = await mongo.create({_id: '0'}, DB_TYPE); r = await mongo.get({_id: '0'}, DB_TYPE); expect(r).to.exist; @@ -76,7 +76,7 @@ describe('Mongo Integration Tests', function() { }); describe("list", () => { - it('should list documents', async() => { + it('should list documents', async () => { let r = await mongo.batch([{_id: '0', foo: 'bar'}, {_id: '1', foo: 'bar'}], DB_TYPE); r = await mongo.list({foo: 'bar'}, DB_TYPE); expect(r).to.deep.equal([{_id: '0', foo: 'bar'}, {_id: '1', foo: 'bar'}], DB_TYPE); @@ -84,7 +84,7 @@ describe('Mongo Integration Tests', function() { }); describe("remove", () => { - it('should remove a document', async() => { + it('should remove a document', async () => { let r = await mongo.create({_id: '0'}, DB_TYPE); r = await mongo.remove({_id: '0'}, DB_TYPE); r = await mongo.get({_id: '0'}, DB_TYPE); diff --git a/test/integration/public-key-test.js b/test/integration/public-key-test.js index b889870..24a26a7 100644 --- a/test/integration/public-key-test.js +++ b/test/integration/public-key-test.js @@ -25,14 +25,14 @@ describe('Public Key Integration Tests', function() { const primaryEmail2 = 'test2@example.com'; const origin = {host: 'localhost', protocol: 'http'}; - before(async() => { + before(async () => { publicKeyArmored = require('fs').readFileSync(`${__dirname}/../key3.asc`, 'utf8'); publicKeyArmored2 = require('fs').readFileSync(`${__dirname}/../key4.asc`, 'utf8'); mongo = new Mongo(); await mongo.init(config.mongo); }); - beforeEach(async() => { + beforeEach(async () => { sandbox = sinon.sandbox.create(); await mongo.clear(DB_TYPE); @@ -64,32 +64,32 @@ describe('Public Key Integration Tests', function() { sandbox.restore(); }); - after(async() => { + after(async () => { await mongo.clear(DB_TYPE); await mongo.disconnect(); }); describe('put', () => { - it('should persist key and send verification email with primaryEmail', async() => { + it('should persist key and send verification email with primaryEmail', async () => { await publicKey.put({publicKeyArmored, primaryEmail, origin}); expect(mailsSent.length).to.equal(1); expect(mailsSent[0].to).to.equal(primaryEmail); expect(mailsSent[0].params.keyId).to.exist; expect(mailsSent[0].params.nonce).to.exist; }); - it('should persist key and send verification email without primaryEmail', async() => { + it('should persist key and send verification email without primaryEmail', async () => { await publicKey.put({publicKeyArmored, origin}); expect(mailsSent.length).to.equal(4); }); - it('should work twice if not yet verified', async() => { + it('should work twice if not yet verified', async () => { await publicKey.put({publicKeyArmored, primaryEmail, origin}); expect(mailsSent.length).to.equal(1); await publicKey.put({publicKeyArmored, primaryEmail, origin}); expect(mailsSent.length).to.equal(2); }); - it('should throw 304 if key already exists', async() => { + it('should throw 304 if key already exists', async () => { await publicKey.put({publicKeyArmored, primaryEmail, origin}); await publicKey.verify(mailsSent[0].params); try { @@ -102,7 +102,7 @@ describe('Public Key Integration Tests', function() { }); describe('verify', () => { - it('should update the document', async() => { + it('should update the document', async () => { await publicKey.put({publicKeyArmored, primaryEmail, origin}); const emailParams = mailsSent[0].params; await publicKey.verify(emailParams); @@ -113,7 +113,7 @@ describe('Public Key Integration Tests', function() { expect(gotten.userIds[1].nonce).to.exist; }); - it('should not find the document', async() => { + it('should not find the document', async () => { await publicKey.put({publicKeyArmored, primaryEmail, origin}); const emailParams = mailsSent[0].params; try { @@ -129,7 +129,7 @@ describe('Public Key Integration Tests', function() { expect(gotten.userIds[1].nonce).to.exist; }); - it('should not verify a second key for already verified user id of another key', async() => { + it('should not verify a second key for already verified user id of another key', async () => { await publicKey.put({publicKeyArmored, primaryEmail: primaryEmail2, origin}); expect(mailsSent.length).to.equal(1); await publicKey.put({publicKeyArmored: publicKeyArmored2, primaryEmail: primaryEmail2, origin}); @@ -148,7 +148,7 @@ describe('Public Key Integration Tests', function() { expect(gotten.userIds[1].nonce).to.equal(mailsSent[0].params.nonce); }); - it('should be able to verify multiple user ids', async() => { + it('should be able to verify multiple user ids', async () => { await publicKey.put({publicKeyArmored, origin}); expect(mailsSent.length).to.equal(4); await publicKey.verify(mailsSent[0].params); @@ -167,66 +167,66 @@ describe('Public Key Integration Tests', function() { let key; describe('should find a verified key', () => { - beforeEach(async() => { + beforeEach(async () => { key = pgp.parseKey(publicKeyArmored); await publicKey.put({publicKeyArmored, primaryEmail, origin}); await publicKey.verify(mailsSent[0].params); }); - it('by fingerprint', async() => { + it('by fingerprint', async () => { const verified = await publicKey.getVerified({fingerprint: key.fingerprint}); expect(verified).to.exist; }); - it('by all userIds', async() => { + it('by all userIds', async () => { const verified = await publicKey.getVerified({userIds: key.userIds}); expect(verified).to.exist; }); - it('by verified userId', async() => { + it('by verified userId', async () => { const verified = await publicKey.getVerified({userIds: [key.userIds[0]]}); expect(verified).to.exist; }); - it('by unverified userId', async() => { + it('by unverified userId', async () => { const verified = await publicKey.getVerified({userIds: [key.userIds[1]]}); expect(verified).to.not.exist; }); - it('by keyId', async() => { + it('by keyId', async () => { const verified = await publicKey.getVerified({keyId: key.keyId}); expect(verified).to.exist; }); - it('by all params', async() => { + it('by all params', async () => { const verified = await publicKey.getVerified(key); expect(verified).to.exist; }); }); describe('should not find an unverified key', () => { - beforeEach(async() => { + beforeEach(async () => { key = pgp.parseKey(publicKeyArmored); key.userIds[0].verified = false; await mongo.create(key, DB_TYPE); }); - it('by fingerprint', async() => { + it('by fingerprint', async () => { const verified = await publicKey.getVerified({fingerprint: key.fingerprint}); expect(verified).to.not.exist; }); - it('by userIds', async() => { + it('by userIds', async () => { const verified = await publicKey.getVerified({userIds: key.userIds}); expect(verified).to.not.exist; }); - it('by keyId', async() => { + it('by keyId', async () => { const verified = await publicKey.getVerified({keyId: key.keyId}); expect(verified).to.not.exist; }); - it('by all params', async() => { + it('by all params', async () => { const verified = await publicKey.getVerified(key); expect(verified).to.not.exist; }); @@ -236,50 +236,50 @@ describe('Public Key Integration Tests', function() { describe('get', () => { let emailParams; - beforeEach(async() => { + beforeEach(async () => { await publicKey.put({publicKeyArmored, primaryEmail, origin}); emailParams = mailsSent[0].params; }); - it('should return verified key by key id', async() => { + it('should return verified key by key id', async () => { await publicKey.verify(emailParams); const key = await publicKey.get({keyId: emailParams.keyId}); expect(key.publicKeyArmored).to.exist; }); - it('should return verified key by key id (uppercase)', async() => { + it('should return verified key by key id (uppercase)', async () => { await publicKey.verify(emailParams); const key = await publicKey.get({keyId: emailParams.keyId.toUpperCase()}); expect(key.publicKeyArmored).to.exist; }); - it('should return verified key by fingerprint', async() => { + it('should return verified key by fingerprint', async () => { await publicKey.verify(emailParams); const fingerprint = pgp.parseKey(publicKeyArmored).fingerprint; const key = await publicKey.get({fingerprint}); expect(key.publicKeyArmored).to.exist; }); - it('should return verified key by fingerprint (uppercase)', async() => { + it('should return verified key by fingerprint (uppercase)', async () => { await publicKey.verify(emailParams); const fingerprint = pgp.parseKey(publicKeyArmored).fingerprint.toUpperCase(); const key = await publicKey.get({fingerprint}); expect(key.publicKeyArmored).to.exist; }); - it('should return verified key by email address', async() => { + it('should return verified key by email address', async () => { await publicKey.verify(emailParams); const key = await publicKey.get({email: primaryEmail}); expect(key.publicKeyArmored).to.exist; }); - it('should return verified key by email address (uppercase)', async() => { + it('should return verified key by email address (uppercase)', async () => { await publicKey.verify(emailParams); const key = await publicKey.get({email: primaryEmail.toUpperCase()}); expect(key.publicKeyArmored).to.exist; }); - it('should throw 404 for unverified key', async() => { + it('should throw 404 for unverified key', async () => { try { await publicKey.get({keyId: emailParams.keyId}); expect(false).to.be.true; @@ -292,28 +292,28 @@ describe('Public Key Integration Tests', function() { describe('requestRemove', () => { let keyId; - beforeEach(async() => { + beforeEach(async () => { await publicKey.put({publicKeyArmored, primaryEmail, origin}); keyId = mailsSent[0].params.keyId; }); - it('should work for verified key', async() => { + it('should work for verified key', async () => { await publicKey.verify(mailsSent[0].params); await publicKey.requestRemove({keyId, origin}); expect(mailsSent.length).to.equal(5); }); - it('should work for unverified key', async() => { + it('should work for unverified key', async () => { await publicKey.requestRemove({keyId, origin}); expect(mailsSent.length).to.equal(5); }); - it('should work by email address', async() => { + it('should work by email address', async () => { await publicKey.requestRemove({email: primaryEmail, origin}); expect(mailsSent.length).to.equal(2); }); - it('should throw 404 for no key', async() => { + it('should throw 404 for no key', async () => { await mongo.remove({keyId}, DB_TYPE); try { await publicKey.requestRemove({keyId, origin}); @@ -327,19 +327,19 @@ describe('Public Key Integration Tests', function() { describe('verifyRemove', () => { let keyId; - beforeEach(async() => { + beforeEach(async () => { await publicKey.put({publicKeyArmored, primaryEmail, origin}); keyId = mailsSent[0].params.keyId; await publicKey.requestRemove({keyId, origin}); }); - it('should remove key', async() => { + it('should remove key', async () => { await publicKey.verifyRemove(mailsSent[1].params); const key = await mongo.get({keyId}, DB_TYPE); expect(key).to.not.exist; }); - it('should throw 404 for no key', async() => { + it('should throw 404 for no key', async () => { await mongo.remove({keyId}, DB_TYPE); try { await publicKey.verifyRemove(mailsSent[1].params); diff --git a/test/unit/email-test.js b/test/unit/email-test.js index 294eca2..68375a9 100644 --- a/test/unit/email-test.js +++ b/test/unit/email-test.js @@ -64,7 +64,7 @@ describe('Email Unit Tests', () => { sandbox.stub(email, '_sendHelper').returns(Promise.resolve({response: '250'})); }); - it('should work', async() => { + it('should work', async () => { const info = await email.send({template, userId: userId1, keyId, origin}); expect(info.response).to.match(/^250/); @@ -72,7 +72,7 @@ describe('Email Unit Tests', () => { }); describe("_sendHelper", () => { - it('should work', async() => { + it('should work', async () => { sendFnStub.returns(Promise.resolve({response: '250'})); const info = await email._sendHelper(mailOptions); @@ -80,7 +80,7 @@ describe('Email Unit Tests', () => { expect(info.response).to.match(/^250/); }); - it('should log warning for reponse error', async() => { + it('should log warning for reponse error', async () => { sendFnStub.returns(Promise.resolve({response: '554'})); const info = await email._sendHelper(mailOptions); @@ -89,7 +89,7 @@ describe('Email Unit Tests', () => { expect(log.warn.calledOnce).to.be.true; }); - it('should fail', async() => { + it('should fail', async () => { sendFnStub.returns(Promise.reject(new Error('boom'))); try {