Skip to content

Commit

Permalink
chore!: upgrade dev dependencies and fix eslint warnings/errors (#1063)
Browse files Browse the repository at this point in the history
* chore: upgrade dev dependencies and fix eslint errors
  • Loading branch information
eshanholtz authored Mar 19, 2020
1 parent 9867c9d commit 8075616
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 404 deletions.
409 changes: 74 additions & 335 deletions .eslintrc.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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\"",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/classes/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Client {

//Default headers
this.defaultHeaders = {
'Accept': 'application/json',
Accept: 'application/json',
'User-agent': 'sendgrid/' + pkg.version + ';nodejs',
};

Expand Down
3 changes: 1 addition & 2 deletions packages/contact-importer/src/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 2 additions & 3 deletions packages/helpers/classes/attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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."
);
}

Expand All @@ -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') {
Expand Down
21 changes: 7 additions & 14 deletions packages/helpers/classes/mail.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ class Mail {

if (this.isDynamic) {
this.setDynamicTemplateData(dynamicTemplateData);
}
else {
} else {
this.setSubstitutions(substitutions);
this.setSubstitutionWrappers(substitutionWrappers);
}
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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;
}

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

Expand Down
34 changes: 17 additions & 17 deletions packages/helpers/classes/mail.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 1 addition & 2 deletions packages/helpers/classes/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`');
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/helpers/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
6 changes: 2 additions & 4 deletions packages/helpers/helpers/merge-data-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] });
}
});
Expand Down
6 changes: 2 additions & 4 deletions packages/helpers/helpers/merge-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Expand Down
16 changes: 5 additions & 11 deletions packages/mail/src/classes/mail-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
});
Expand Down Expand Up @@ -179,13 +178,11 @@ function addUserToList(emailBody, callback) {

callback();
});
}
else {
} else {
return callback();
}
});
}
else {
} else {
return callback();
}
});
Expand Down Expand Up @@ -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' };

Expand Down

0 comments on commit 8075616

Please sign in to comment.