From 8075616e230eb94d289542384e58618194e8c3e6 Mon Sep 17 00:00:00 2001 From: Elise Shanholtz Date: Thu, 19 Mar 2020 11:12:11 -0700 Subject: [PATCH] chore!: upgrade dev dependencies and fix eslint warnings/errors (#1063) * chore: upgrade dev dependencies and fix eslint errors --- .eslintrc.yaml | 409 ++++-------------- package.json | 4 +- packages/client/src/classes/client.js | 2 +- packages/contact-importer/src/importer.js | 3 +- packages/helpers/classes/attachment.js | 5 +- packages/helpers/classes/mail.js | 21 +- packages/helpers/classes/mail.spec.js | 34 +- packages/helpers/classes/statistics.js | 3 +- packages/helpers/constants/index.js | 2 +- packages/helpers/helpers/merge-data-deep.js | 6 +- packages/helpers/helpers/merge-data.js | 6 +- packages/mail/src/classes/mail-service.js | 16 +- .../controllers/contact_list_controller.js | 12 +- 13 files changed, 119 insertions(+), 404 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 4e95dc763..c531f0416 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -1,349 +1,88 @@ -root: true -extends: eslint:recommended -parserOptions: - ecmaVersion: 6 - ecmaFeatures: - impliedStrict: true - sourceType: module env: es6: true node: true mocha: true jasmine: true rules: - linebreak-style: - - error - - unix - max-len: - - warn - - code: 80 - tabWidth: 2 - ignoreComments: true - ignoreUrls: true - indent: - - error - - 2 - - SwitchCase: 1 - VariableDeclarator: - let: 2 - const: 3 - semi: - - error - - always - consistent-this: - - error - - self - - $ctrl - quotes: - - error - - single - - allowTemplateLiterals: true - curly: - - error - - all - comma-dangle: - - error - - always-multiline - new-cap: - - error - - newIsCap: true - capIsNew: true - properties: false array-bracket-spacing: - - error - - never - arrow-spacing: - - error - - before: true - after: true - block-spacing: - - error - - always + - 2 + - never + - {} + brace-style: + - 2 + - 1tbs + - allowSingleLine: true + camelcase: 0 + comma-dangle: + - 2 + - always-multiline comma-spacing: - - error - - before: false - after: true - computed-property-spacing: - - error - - never - generator-star-spacing: - - error - - before: true - after: false + - 2 + - after: true + before: false + comma-style: + - 2 + - last + curly: + - 2 + - all + dot-notation: 0 + eol-last: 2 + indent: + - 2 + - 2 + - SwitchCase: 1 key-spacing: - - error - - beforeColon: false - afterColon: true - mode: minimum + - 2 + - afterColon: true + beforeColon: false keyword-spacing: - - error - - before: true + - 2 + - {} + linebreak-style: + - 2 + - unix + no-empty: + - 2 + - allowEmptyCatch: true + no-mixed-spaces-and-tabs: 2 + no-multi-str: 2 + no-multiple-empty-lines: 2 + no-spaced-func: 2 + no-trailing-spaces: 2 + no-with: 2 + one-var: + - 2 + - never + quote-props: + - 2 + - as-needed + quotes: + - 2 + - single + semi: + - 2 + - always semi-spacing: - - error - - before: false - after: true + - 2 + - after: true + before: false + space-before-blocks: + - 2 + - always + space-before-function-paren: + - 2 + - anonymous: ignore + named: never space-in-parens: - - error - - never + - 2 + - never + space-infix-ops: 2 space-unary-ops: - - error - - words: true - nonwords: false - space-before-function-paren: - - error - - never - space-before-blocks: - - error - - always + - 2 + - nonwords: false + words: false + wrap-iife: 2 yoda: - - error - - never - wrap-iife: - - error - - outside - eqeqeq: - - error - - always - newline-per-chained-call: - - error - - ignoreChainWithDepth: 3 - one-var-declaration-per-line: - - error - - initializations - brace-style: - - error - - stroustrup - no-implicit-coercion: - - error - - boolean: false - no-multiple-empty-lines: - - error - - max: 1 - eol-last: error - dot-notation: error - space-infix-ops: error - no-with: error - no-unreachable: error - no-redeclare: error - no-unexpected-multiline: error - no-multi-spaces: error - no-multi-str: error - no-trailing-spaces: error - no-mixed-spaces-and-tabs: error - no-spaced-func: error - no-whitespace-before-property: error - no-lonely-if: error - no-console: off - - # Possible Errors - no-await-in-loop: off - no-cond-assign: error - no-constant-condition: error - no-control-regex: error - no-debugger: error - no-dupe-args: error - no-dupe-keys: error - no-duplicate-case: error - no-empty-character-class: error - no-empty: error - no-ex-assign: error - no-extra-boolean-cast: error - no-extra-parens: off - no-extra-semi: error - no-func-assign: error - no-inner-declarations: - - error - - functions - no-invalid-regexp: error - no-irregular-whitespace: error - no-negated-in-lhs: error - no-obj-calls: error - no-prototype-builtins: off - no-regex-spaces: error - no-sparse-arrays: error - no-unsafe-finally: off - no-unsafe-negation: off - use-isnan: error - valid-jsdoc: off - valid-typeof: error - - # Best Practices - accessor-pairs: error - array-callback-return: off - block-scoped-var: off - class-methods-use-this: off - complexity: - - warn - - 6 - consistent-return: off - default-case: off - dot-location: off - guard-for-in: error - no-alert: error - no-caller: error - no-case-declarations: error - no-div-regex: error - no-else-return: off - no-empty-function: off - no-empty-pattern: error - no-eq-null: error - no-eval: error - no-extend-native: error - no-extra-bind: error - no-extra-label: off - no-fallthrough: error - no-floating-decimal: off - no-global-assign: off - no-implied-eval: error - no-invalid-this: off - no-iterator: error - no-labels: - - error - - allowLoop: true - allowSwitch: true - no-lone-blocks: error - no-loop-func: error - no-magic-number: off - no-native-reassign: error - no-new-func: error - no-new-wrappers: error - no-new: error - no-octal-escape: error - no-octal: error - no-param-reassign: off - no-proto: error - no-restricted-properties: off - no-return-assign: error - no-return-await: off - no-script-url: error - no-self-assign: off - no-self-compare: error - no-sequences: off - no-throw-literal: off - no-unmodified-loop-condition: off - no-unused-expressions: error - no-unused-labels: off - no-useless-call: error - no-useless-concat: error - no-useless-escape: off - no-useless-return: off - no-void: error - no-warning-comments: off - prefer-promise-reject-errors: off - radix: error - require-await: off - vars-on-top: off - - # Strict - strict: off - - # Variables - init-declarations: off - no-catch-shadow: error - no-delete-var: error - no-label-var: error - no-restricted-globals: off - no-shadow-restricted-names: error - no-shadow: off - no-undef-init: error - no-undef: off - no-undefined: off - no-unused-vars: off - no-use-before-define: off - - # Node.js and CommonJS - callback-return: error - global-require: off - handle-callback-err: error - no-mixed-requires: off - no-new-require: off - no-path-concat: error - no-process-env: off - no-process-exit: error - no-restricted-modules: off - no-sync: off - - # Stylistic Issues - camelcase: off - capitalized-comments: off - comma-style: off - func-call-spacing: off - func-name-matching: off - func-names: off - func-style: off - id-length: off - id-match: off - jsx-quotes: off - line-comment-position: off - lines-around-comment: off - lines-around-directive: off - max-depth: off - max-nested-callbacks: off - max-params: off - max-statements-per-line: off - max-statements: - - warn - - 30 - multiline-ternary: off - new-parens: off - newline-after-var: off - newline-before-return: off - no-array-constructor: off - no-bitwise: off - no-continue: off - no-inline-comments: off - no-mixed-operators: off - no-multi-assign: off - no-negated-condition: off - no-nested-ternary: off - no-new-object: off - no-plusplus: off - no-restricted-syntax: off - no-tabs: off - no-ternary: off - no-underscore-dangle: off - no-unneeded-ternary: off - object-property-newline: off - one-var: off - operator-assignment: off - operator-linebreak: off - padded-blocks: off - quote-props: off - require-jsdoc: off - sort-keys: off - sort-vars: off - spaced-comment: off - template-tag-spacing: off - unicode-bom: off - wrap-regex: off - - # ECMAScript 6 - arrow-body-style: off - arrow-parens: off - constructor-super: off - no-class-assign: off - no-confusing-arrow: off - no-const-assign: off - no-dupe-class-members: off - no-duplicate-imports: off - no-new-symbol: off - no-restricted-imports: off - no-this-before-super: off - no-useless-computed-key: off - no-useless-constructor: off - no-useless-rename: off - no-var: off - object-shorthand: off - prefer-arrow-callback: off - prefer-const: off - prefer-destructuring: off - prefer-numeric-literals: off - prefer-rest-params: off - prefer-reflect: off - prefer-spread: off - prefer-template: off - require-yield: off - rest-spread-spacing: off - sort-imports: off - symbol-description: off - yield-star-spacing: off + - 2 + - never diff --git a/package.json b/package.json index ca3d2224b..8619f964e 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "chai": "^4.0.1", "chai-as-promised": "^7.1.1", "dirty-chai": "^2.0.1", - "eslint": "^4.19.1", + "eslint": "^6.8.0", "istanbul": "^1.0.0-alpha.2", "lerna": "^3.19.0", "mocha": "^6.2.2", @@ -26,7 +26,7 @@ "typescript": "^3.7.4" }, "scripts": { - "lint": "eslint . --fix", + "lint": "if [ `node --version | cut -d'.' -f1 | cut -c 2` -ge \"8\" ]; then eslint . --fix; else echo \"eslint is not available for node < 8.0\"; fi", "test:all": "babel-node ./node_modules/istanbul/lib/cli cover ./node_modules/mocha/bin/_mocha \"**/*.spec.js\"", "test:helpers": "babel-node ./node_modules/istanbul/lib/cli cover ./node_modules/mocha/bin/_mocha \"packages/helpers/**/*.spec.js\"", "test:client": "babel-node ./node_modules/istanbul/lib/cli cover ./node_modules/mocha/bin/_mocha \"packages/client/**/*.spec.js\"", diff --git a/packages/client/src/classes/client.js b/packages/client/src/classes/client.js index a76cbbbdd..633d49352 100644 --- a/packages/client/src/classes/client.js +++ b/packages/client/src/classes/client.js @@ -29,7 +29,7 @@ class Client { //Default headers this.defaultHeaders = { - 'Accept': 'application/json', + Accept: 'application/json', 'User-agent': 'sendgrid/' + pkg.version + ';nodejs', }; diff --git a/packages/contact-importer/src/importer.js b/packages/contact-importer/src/importer.js index abae55f35..7ef0d08ed 100644 --- a/packages/contact-importer/src/importer.js +++ b/packages/contact-importer/src/importer.js @@ -51,9 +51,8 @@ class ContactImporter extends EventEmitter { // If this batch is full or the queue is empty queue it for processing. if (batch.length === this.batchSize || !this.queue.length()) { this._pushToQueue(batch); - } + } else { // Otherwise, it store it for later. - else { debug('the last batch with only %s item is deferred (partial batch)', batch.length); this.pendingItems = batch; } diff --git a/packages/helpers/classes/attachment.js b/packages/helpers/classes/attachment.js index ab64c9bed..46beed47b 100644 --- a/packages/helpers/classes/attachment.js +++ b/packages/helpers/classes/attachment.js @@ -52,7 +52,7 @@ class Attachment { if ((typeof content !== 'undefined') && (typeof filePath !== 'undefined')) { throw new Error( - `The props 'content' and 'filePath' cannot be used together.` + "The props 'content' and 'filePath' cannot be used together." ); } @@ -79,8 +79,7 @@ class Attachment { if (typeof content === 'string') { this.content = content; return; - } - else if (content instanceof Buffer && content.toString !== undefined) { + } else if (content instanceof Buffer && content.toString !== undefined) { this.content = content.toString(); if (this.disposition === 'attachment') { diff --git a/packages/helpers/classes/mail.js b/packages/helpers/classes/mail.js index 83d502bbb..e0531dd8a 100644 --- a/packages/helpers/classes/mail.js +++ b/packages/helpers/classes/mail.js @@ -92,8 +92,7 @@ class Mail { if (this.isDynamic) { this.setDynamicTemplateData(dynamicTemplateData); - } - else { + } else { this.setSubstitutions(substitutions); this.setSubstitutionWrappers(substitutionWrappers); } @@ -105,15 +104,11 @@ class Mail { //Using "to" property for personalizations if (personalizations) { this.setPersonalizations(personalizations); - } - - //Multiple individual emails - else if (isMultiple && Array.isArray(to)) { + } else if (isMultiple && Array.isArray(to)) { + //Multiple individual emails to.forEach(to => this.addTo(to, cc, bcc)); - } - - //Single email (possibly with multiple recipients in the to field) - else { + } else { + //Single email (possibly with multiple recipients in the to field) this.addTo(to, cc, bcc); } } @@ -247,8 +242,7 @@ class Mail { //depending on the templateId if (this.isDynamic && personalization.substitutions) { delete personalization.substitutions; - } - else if (!this.isDynamic && personalization.dynamicTemplateData) { + } else if (!this.isDynamic && personalization.dynamicTemplateData) { delete personalization.dynamicTemplateData; } @@ -260,8 +254,7 @@ class Mail { //If this is dynamic, set dynamicTemplateData, or set substitutions if (this.isDynamic) { this.applyDynamicTemplateData(personalization); - } - else { + } else { this.applySubstitutions(personalization); } diff --git a/packages/helpers/classes/mail.spec.js b/packages/helpers/classes/mail.spec.js index c1de9fcbc..37c1aab8a 100644 --- a/packages/helpers/classes/mail.spec.js +++ b/packages/helpers/classes/mail.spec.js @@ -122,42 +122,42 @@ describe('Mail', function() { expect(mail.personalizations[0].dynamicTemplateData).to.deep.equal({ test1: 'Test 1', test2: 'Testy 2', test3: 'Testy 3' }); expect(mail.toJSON()).to.deep.equal({ - 'content': [ + content: [ { - 'type': 'text/plain', - 'value': 'test', + type: 'text/plain', + value: 'test', }, ], - 'from': { - 'email': 'test@example.com', + from: { + email: 'test@example.com', }, - 'personalizations': [ + personalizations: [ { - 'dynamic_template_data': { - 'test1': 'Test 1', - 'test2': 'Testy 2', - 'test3': 'Testy 3', + dynamic_template_data: { + test1: 'Test 1', + test2: 'Testy 2', + test3: 'Testy 3', }, - 'headers': { + headers: { 'test-header': 'test', }, - 'to': [ + to: [ { - 'email': 'test@example.com', - 'name': '', + email: 'test@example.com', + name: '', }, ], }, ], - 'subject': 'test', - 'template_id': 'd-df80613cccc6441ea5cd7c95377bc1ef', + subject: 'test', + template_id: 'd-df80613cccc6441ea5cd7c95377bc1ef', }); }); }); describe('dynamic template handlebars substitutions', () => { - let logSpy, data; + let logSpy; let data; beforeEach(() => { logSpy = sinon.spy(console, 'warn'); diff --git a/packages/helpers/classes/statistics.js b/packages/helpers/classes/statistics.js index 260c949f7..86fa7b819 100644 --- a/packages/helpers/classes/statistics.js +++ b/packages/helpers/classes/statistics.js @@ -97,8 +97,7 @@ class Statistics { if (typeof aggregatedBy === 'string' && AggregatedByOptions.includes(aggregatedBy.toLowerCase())) { this.aggregatedBy = aggregatedBy; - } - else { + } else { throw new Error('Incorrect value for `aggregatedBy`'); } } diff --git a/packages/helpers/constants/index.js b/packages/helpers/constants/index.js index 3c74ba89e..3da830064 100644 --- a/packages/helpers/constants/index.js +++ b/packages/helpers/constants/index.js @@ -4,5 +4,5 @@ Content with characters ', " or & may need to be escaped with three brackets See https://sendgrid.com/docs/for-developers/sending-email/using-handlebars/ for more information.`; module.exports = { - DYNAMIC_TEMPLATE_CHAR_WARNING + DYNAMIC_TEMPLATE_CHAR_WARNING, }; diff --git a/packages/helpers/helpers/merge-data-deep.js b/packages/helpers/helpers/merge-data-deep.js index 65bfd4d6e..1bb2f5724 100644 --- a/packages/helpers/helpers/merge-data-deep.js +++ b/packages/helpers/helpers/merge-data-deep.js @@ -22,12 +22,10 @@ module.exports = function mergeDeep(base, data) { if (isObject(data[key])) { if (!(key in base)) { Object.assign(output, { [key]: data[key] }); - } - else { + } else { output[key] = mergeDeep(base[key], data[key]); } - } - else { + } else { Object.assign(output, { [key]: data[key] }); } }); diff --git a/packages/helpers/helpers/merge-data.js b/packages/helpers/helpers/merge-data.js index d284aaf80..c70c23e2b 100644 --- a/packages/helpers/helpers/merge-data.js +++ b/packages/helpers/helpers/merge-data.js @@ -22,11 +22,9 @@ module.exports = function mergeData(base, data) { if (data.hasOwnProperty(key)) { if (data[key] && Array.isArray(data[key])) { merged[key] = data[key]; - } - else if (data[key] && typeof data[key] === 'object') { + } else if (data[key] && typeof data[key] === 'object') { merged[key] = Object.assign({}, data[key]); - } - else { + } else { merged[key] = data[key]; } } diff --git a/packages/mail/src/classes/mail-service.js b/packages/mail/src/classes/mail-service.js index ec4e455e0..70a380b58 100644 --- a/packages/mail/src/classes/mail-service.js +++ b/packages/mail/src/classes/mail-service.js @@ -77,15 +77,13 @@ class MailService { return { pattern: new RegExp(rule), }; - } - else if (ruleType === 'object') { + } else if (ruleType === 'object') { // normalize rule object if (rule instanceof RegExp) { rule = { pattern: rule, }; - } - else if (rule.hasOwnProperty('pattern') + } else if (rule.hasOwnProperty('pattern') && (typeof rule.pattern === 'string') ) { rule.pattern = new RegExp(rule.pattern); @@ -95,8 +93,7 @@ class MailService { // test if rule.pattern is a valid regex rule.pattern.test(''); return rule; - } - catch (err) { + } catch (err) { // continue regardless of error } } @@ -131,7 +128,7 @@ class MailService { message += `identified by '${rule.name}'`; } - message += ` was found in the Mail content!`; + message += ' was found in the Mail content!'; throw new Error(message); }); @@ -197,10 +194,7 @@ class MailService { //Send return this.client.request(request, cb); - } - - //Catch sync errors - catch (error) { + } catch (error) { //Pass to callback if provided if (cb) { diff --git a/packages/subscription-widget/server/controllers/contact_list_controller.js b/packages/subscription-widget/server/controllers/contact_list_controller.js index a7e3cf81b..0fa356aff 100644 --- a/packages/subscription-widget/server/controllers/contact_list_controller.js +++ b/packages/subscription-widget/server/controllers/contact_list_controller.js @@ -100,8 +100,7 @@ exports.sendConfirmation = (req, res, next) => { if (response.statusCode >= 200 && response.statusCode < 300) { res.sendFile(path.join(__dirname, '../static/check-inbox.html')); - } - else { + } else { res.sendFile(path.join(__dirname, '../static/error.html')); } }); @@ -179,13 +178,11 @@ function addUserToList(emailBody, callback) { callback(); }); - } - else { + } else { return callback(); } }); - } - else { + } else { return callback(); } }); @@ -220,8 +217,7 @@ function checkAndAddCustomFields(submittedFields, callback) { if (fieldsToCreate.length === 0) { return callback(); - } - else { + } else { fieldsToCreate.map((fieldsToCreate) => { var body = { name: fieldsToCreate, type: 'text' };