From 1da22c102944126e0891439b6fc7bc92a92659a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Obernd=C3=B6rfer?= Date: Wed, 6 Mar 2019 10:21:29 +0100 Subject: [PATCH] Update eslint rules --- .eslintrc => .eslintrc.json | 25 +++++++++++++++++-------- src/dao/papertrail.js | 1 - src/email/templates.js | 4 ++-- src/service/pgp.js | 1 + test/{.eslintrc => .eslintrc.json} | 5 ++++- test/integration/email-test.js | 6 +++--- test/integration/mongo-test.js | 12 ++++++------ test/unit/email-test.js | 4 ++-- 8 files changed, 35 insertions(+), 23 deletions(-) rename .eslintrc => .eslintrc.json (73%) rename test/{.eslintrc => .eslintrc.json} (78%) diff --git a/.eslintrc b/.eslintrc.json similarity index 73% rename from .eslintrc rename to .eslintrc.json index 36a19d3..d2d372b 100644 --- a/.eslintrc +++ b/.eslintrc.json @@ -1,12 +1,15 @@ { - "extends": "eslint:recommended", "parserOptions": { - "ecmaVersion": 2017 + "ecmaVersion": 2018 }, + + "extends": "eslint:recommended", + "env": { "node": true, "es6": true }, + "rules": { "strict": ["error", "global"], /* possible errors */ @@ -14,6 +17,7 @@ "no-empty": ["error", { "allowEmptyCatch": true }], // disallow empty block statements /* best practices */ "curly": 2, // enforce consistent brace style for all control statements + "no-return-await": 2, // disallows unnecessary return await "no-eval": 2, // disallow the use of eval() "no-extend-native": 2, // disallow extending native types "no-global-assign": 2, // disallow assignments to native objects or read-only global variables @@ -21,10 +25,13 @@ "no-implicit-globals": 2, // disallow var and named function declarations in the global scope "no-implied-eval": 2, // disallow the use of eval()-like methods "no-lone-blocks": 2, // disallow unnecessary nested blocks + "no-unused-vars": ["error", {"ignoreRestSiblings": true}], // disallow unused variables "no-useless-escape": 0, // disallow unnecessary escape characters /* Stylistic Issues */ + "array-bracket-newline": ["warn", "consistent"], // enforce consisten line breaks after opening and before closing array brackets "array-bracket-spacing": 1, // enforce consistent spacing inside array brackets "block-spacing": 1, // enforce consistent spacing inside single-line blocks + "brace-style": ["warn", "1tbs", { "allowSingleLine": true }], // enforce consistent brace style for blocks "comma-spacing": 1, // enforce consistent spacing before and after commas "computed-property-spacing": 1, // enforce consistent spacing inside computed property brackets "eol-last": 1, // enforce at least one newline at the end of files @@ -33,19 +40,20 @@ "key-spacing": ["warn", { "mode": "minimum" }], // enforce consistent spacing before and after keywords "keyword-spacing": 1, // enforce consistent spacing between keys and values in object literal properties "linebreak-style": 1, // enforce consistent linebreak style + "lines-between-class-members": 1, // require or disallow an empty line between class members + "no-multiple-empty-lines": ["warn", {"max": 1}], // disallow multiple empty lines "no-trailing-spaces": 1, // disallow trailing whitespace at the end of lines "no-var": 1, // require let or const instead of var + "object-curly-newline": ["warn", {"consistent": true}], // enforce consistent line breaks inside braces "object-curly-spacing": ["warn", "never"], // enforce consistent spacing inside braces "one-var": ["warn", "never"], // enforce variables to be declared either together or separately in functions "padded-blocks": ["warn", "never"], // require or disallow padding within blocks + "prefer-object-spread": 1, // disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead. + "quotes": ["warn", "single", {"avoidEscape": true}], // enforce the consistent use of single quotes "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", { - "anonymous": "never", - "named": "never", - "asyncArrow": "always" - }], // 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 */ @@ -55,9 +63,10 @@ "no-useless-constructor": 1, // disallow unnecessary constructors "object-shorthand": ["warn", "always", {"avoidQuotes": true}], // require or disallow method and property shorthand syntax for object literals "prefer-arrow-callback": ["warn", {"allowNamedFunctions": true}], // require arrow functions as callbacks - "prefer-const": 1, // require const declarations for variables that are never reassigned after declared + "prefer-const": ["warn", {"destructuring": "all"}], // require const declarations for variables that are never reassigned after declared "prefer-template": 1, // require template literals instead of string concatenation "template-curly-spacing": ["warn", "never"] // require or disallow spacing around embedded expressions of template strings }, + "root": true } diff --git a/src/dao/papertrail.js b/src/dao/papertrail.js index ed576cb..e28862b 100644 --- a/src/dao/papertrail.js +++ b/src/dao/papertrail.js @@ -25,7 +25,6 @@ require('winston-papertrail'); log.exitOnError = false; log.level = config.log.level; - // Reformat logging text, due to deprecated logger usage const formatLogs = log.format(info => { info.message = `${info.message} -> ${info[SPLAT].join(', ')}`; diff --git a/src/email/templates.js b/src/email/templates.js index 806aaa2..edea073 100644 --- a/src/email/templates.js +++ b/src/email/templates.js @@ -1,11 +1,11 @@ 'use strict'; exports.verifyKey = ({name, baseUrl, keyId, nonce}) => ({ - subject: `Verify Your Key`, + subject: 'Verify Your Key', text: `Hello ${name},\n\nplease click here to verify your email address:\n\n${baseUrl}/api/v1/key?op=verify&keyId=${keyId}&nonce=${nonce}`, }); exports.verifyRemove = ({name, baseUrl, keyId, nonce}) => ({ - subject: `Verify Key Removal`, + subject: 'Verify Key Removal', text: `Hello ${name},\n\nplease click here to verify the removal of your email address:\n\n${baseUrl}/api/v1/key?op=verifyRemove&keyId=${keyId}&nonce=${nonce}`, }); diff --git a/src/service/pgp.js b/src/service/pgp.js index 616d475..ef40005 100644 --- a/src/service/pgp.js +++ b/src/service/pgp.js @@ -33,6 +33,7 @@ class PGP { openpgp.config.show_version = false; openpgp.config.show_comment = false; } + /** * Parse an ascii armored pgp key block and get its parameters. * @param {String} publicKeyArmored ascii armored pgp key block diff --git a/test/.eslintrc b/test/.eslintrc.json similarity index 78% rename from test/.eslintrc rename to test/.eslintrc.json index 4623dd0..db58a51 100644 --- a/test/.eslintrc +++ b/test/.eslintrc.json @@ -1,12 +1,15 @@ { - "extends": "../.eslintrc", + "extends": "../.eslintrc.json", + "rules": { "no-shadow": 1 }, + "globals": { "expect": true, "sinon": true }, + "env": { "mocha": true } diff --git a/test/integration/email-test.js b/test/integration/email-test.js index 9540565..7d32efb 100644 --- a/test/integration/email-test.js +++ b/test/integration/email-test.js @@ -35,7 +35,7 @@ describe('Email Integration Tests', function() { }; }); - describe("_sendHelper", () => { + describe('_sendHelper', () => { it('should work', async () => { const mailOptions = { from: {name: email._sender.name, address: email._sender.email}, @@ -49,7 +49,7 @@ describe('Email Integration Tests', function() { }); }); - describe("send verifyKey template", () => { + describe('send verifyKey template', () => { it('should send plaintext email', async () => { delete userId.publicKeyArmored; await email.send({template: tpl.verifyKey, userId, keyId, origin}); @@ -60,7 +60,7 @@ describe('Email Integration Tests', function() { }); }); - describe("send verifyRemove template", () => { + describe('send verifyRemove template', () => { it('should send plaintext email', async () => { delete userId.publicKeyArmored; await email.send({template: tpl.verifyRemove, userId, keyId, origin}); diff --git a/test/integration/mongo-test.js b/test/integration/mongo-test.js index 0721b81..250fa31 100644 --- a/test/integration/mongo-test.js +++ b/test/integration/mongo-test.js @@ -28,7 +28,7 @@ describe('Mongo Integration Tests', function() { await mongo.disconnect(); }); - describe("create", () => { + describe('create', () => { it('should insert a document', async () => { const r = await mongo.create({_id: '0'}, DB_TYPE); expect(r.insertedCount).to.equal(1); @@ -45,7 +45,7 @@ describe('Mongo Integration Tests', function() { }); }); - describe("batch", () => { + describe('batch', () => { it('should insert a document', async () => { const r = await mongo.batch([{_id: '0'}, {_id: '1'}], DB_TYPE); expect(r.insertedCount).to.equal(2); @@ -62,7 +62,7 @@ describe('Mongo Integration Tests', function() { }); }); - describe("update", () => { + describe('update', () => { 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); @@ -72,7 +72,7 @@ describe('Mongo Integration Tests', function() { }); }); - describe("get", () => { + describe('get', () => { it('should get a document', async () => { let r = await mongo.create({_id: '0'}, DB_TYPE); r = await mongo.get({_id: '0'}, DB_TYPE); @@ -80,7 +80,7 @@ describe('Mongo Integration Tests', function() { }); }); - describe("list", () => { + describe('list', () => { 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); @@ -88,7 +88,7 @@ describe('Mongo Integration Tests', function() { }); }); - describe("remove", () => { + describe('remove', () => { it('should remove a document', async () => { let r = await mongo.create({_id: '0'}, DB_TYPE); r = await mongo.remove({_id: '0'}, DB_TYPE); diff --git a/test/unit/email-test.js b/test/unit/email-test.js index 9fc1134..487fb29 100644 --- a/test/unit/email-test.js +++ b/test/unit/email-test.js @@ -57,7 +57,7 @@ describe('Email Unit Tests', () => { sandbox.restore(); }); - describe("send", () => { + describe('send', () => { beforeEach(() => { sandbox.stub(email, '_sendHelper').returns(Promise.resolve({response: '250'})); }); @@ -69,7 +69,7 @@ describe('Email Unit Tests', () => { }); }); - describe("_sendHelper", () => { + describe('_sendHelper', () => { it('should work', async () => { sendFnStub.returns(Promise.resolve({response: '250'}));