Skip to content

Commit abb4265

Browse files
authored
Switched JSHint for ESLint with SparkPost config (#159)
* Switched JSHint for ESLint with SparkPost config * modified lint npm script to remove node_modules path
1 parent 23fdf26 commit abb4265

27 files changed

+277
-234
lines changed

.eslintrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "sparkpost/api",
3+
"globals": {
4+
"Promise": true
5+
}
6+
}

Gruntfile.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,6 @@ module.exports = function(grunt) {
1919
grunt.initConfig({
2020
config: config,
2121
pkg: grunt.file.readJSON('package.json'),
22-
jshint: {
23-
files: [
24-
'index.js',
25-
'lib/{,*/}*.js',
26-
'examples/{,*/}*.js'
27-
],
28-
options: {
29-
reporter: require('jshint-stylish'),
30-
jshintrc: './.jshintrc'
31-
}
32-
},
3322
bump: {
3423
options: {
3524
files: [ 'package.json' ]
@@ -46,6 +35,9 @@ module.exports = function(grunt) {
4635
}
4736
},
4837
shell: {
38+
lint: {
39+
command: 'npm run lint'
40+
},
4941
coverage: {
5042
command : path.join(config.binPath, 'istanbul') + ' cover --report lcov --dir test/reports/ node_modules/mocha/bin/_mocha test/spec -- --reporter ' + reporter,
5143
options : {
@@ -68,7 +60,7 @@ module.exports = function(grunt) {
6860
});
6961

7062
// grunt lint - leverages grunt-contrib-jshint command, lints our code
71-
grunt.registerTask('lint', [ 'jshint' ]);
63+
grunt.registerTask('lint', [ 'shell:lint' ]);
7264

7365
// grunt test - runs linting and then our unit tests
7466
grunt.registerTask('test', [

lib/SendGridCompatibility/Email.js

+27-26
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
*
66
* @param options object that contains initial values
77
*/
8-
function Email(options){
9-
for (var option in options) {
8+
function Email(options) {
9+
var option;
10+
for (option in options) {
1011
this[option] = options[option];
1112
}
1213
}
@@ -17,85 +18,85 @@ function Email(options){
1718
* @param Most have a single value to map
1819
* Add functions will often contain a key / value pair
1920
*/
20-
Email.prototype.addTo = function (address){
21-
if (this.to === undefined){
21+
Email.prototype.addTo = function(address) {
22+
if (this.to === undefined) {
2223
this.to = address;
23-
} else if (typeof this.to === 'string'){
24+
} else if (typeof this.to === 'string') {
2425
this.to = [this.to];
2526
this.to.push(address);
2627
} else {
2728
this.to.push(address);
2829
}
2930
};
30-
Email.prototype.setFrom = function (address){
31+
Email.prototype.setFrom = function(address) {
3132
this.from = address;
3233
};
33-
Email.prototype.setSubject = function (subject){
34+
Email.prototype.setSubject = function(subject) {
3435
this.subject = subject;
3536
};
36-
Email.prototype.setText = function (text){
37+
Email.prototype.setText = function(text) {
3738
this.text = text;
3839
};
39-
Email.prototype.setHtml = function (html){
40+
Email.prototype.setHtml = function(html) {
4041
this.html = html;
4142
};
42-
Email.prototype.addHeader = function (key, value){
43-
if (this.headers === undefined){
43+
Email.prototype.addHeader = function(key, value) {
44+
if (this.headers === undefined) {
4445
this.headers = {};
4546
}
4647
this.headers[key] = value;
4748
};
48-
Email.prototype.setHeaders = function (headers){
49+
Email.prototype.setHeaders = function(headers) {
4950
this.headers = headers;
5051
};
51-
Email.prototype.addSubstitution = function (key, value){
52-
if (this.sub === undefined){
52+
Email.prototype.addSubstitution = function(key, value) {
53+
if (this.sub === undefined) {
5354
this.sub = {};
5455
}
55-
if (typeof value === 'string'){
56+
if (typeof value === 'string') {
5657
this.sub[key] = [value];
5758
} else {
5859
this.sub[key] = value;
5960
}
6061
};
61-
Email.prototype.setSubstitutions = function (substitutions){
62+
Email.prototype.setSubstitutions = function(substitutions) {
6263
this.sub = substitutions;
6364
};
64-
Email.prototype.addSection = function (key, value){
65-
if (this.section === undefined){
65+
Email.prototype.addSection = function(key, value) {
66+
if (this.section === undefined) {
6667
this.section = {};
6768
}
6869
this.section[key] = value;
6970
};
70-
Email.prototype.setSections = function (sections){
71+
Email.prototype.setSections = function(sections) {
7172
this.section = sections;
7273
};
7374
// SparkPost doesn't currently support addUniqueArg, throw an error
74-
Email.prototype.addUniqueArg = function (){
75+
Email.prototype.addUniqueArg = function() {
7576
throw new Error('Unique Argument compatibility is not supported.');
7677
};
7778
// SparkPost doesn't currently support setUniqueArgs, throw an error
78-
Email.prototype.setUniqueArgs = function (){
79+
Email.prototype.setUniqueArgs = function() {
7980
throw new Error('Unique Argument compatibility is not supported.');
8081
};
8182
// SparkPost doesn't currently support addCategory, throw an error
82-
Email.prototype.addCategory = function (){
83+
Email.prototype.addCategory = function() {
8384
throw new Error('Category compatibility is not supported.');
8485
};
8586
// SparkPost doesn't currently support setCategories, throw an error
86-
Email.prototype.setCategories = function (){
87+
Email.prototype.setCategories = function() {
8788
throw new Error('Category compatibility is not supported.');
8889
};
8990
// SparkPost doesn't currently support addFilter, throw an error
90-
Email.prototype.addFilter = function (){
91+
Email.prototype.addFilter = function() {
9192
throw new Error('Filter compatibility is not supported.');
9293
};
9394
// SparkPost doesn't currently support setFilters, throw an error
94-
Email.prototype.setFilters = function (){
95+
Email.prototype.setFilters = function() {
9596
throw new Error('Filter compatibility is not supported.');
9697
};
9798
// SparkPost doesn't currently support addFile, throw an error
98-
Email.prototype.addFile = function (){
99+
Email.prototype.addFile = function() {
99100
throw new Error('File compatibility is not supported.');
100101
};
101102

lib/SendGridCompatibility/index.js

+28-26
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
2-
var _ = require('lodash');
3-
var url = require('url');
4-
var SparkPost = require('../sparkpost');
2+
var _ = require('lodash')
3+
, url = require('url')
4+
, SparkPost = require('../sparkpost')
5+
, sendgrid, consolidateSubstitutionData, parseTo, translatePayload;
56

67
/**
78
* SendGrid compatibility constructor
@@ -13,14 +14,15 @@ var SparkPost = require('../sparkpost');
1314
* @param apiKey: api key string
1415
* @param options: optional additional options object
1516
*/
16-
var sendgrid = function(username, apiKey, options) {
17+
sendgrid = function(username, apiKey, options) {
18+
var urlOpts, opts;
1719
options = options || {};
18-
var urlOpts = {
20+
urlOpts = {
1921
protocol: options.protocol
2022
, hostname: options.host
2123
, port: options.port
22-
}
23-
, opts = {
24+
};
25+
opts = {
2426
endpoint: url.format(urlOpts)
2527
};
2628

@@ -35,13 +37,13 @@ var sendgrid = function(username, apiKey, options) {
3537
* be translated into a SparkPost payload
3638
* @returns object: substitutionData object as per SparkPost payload format
3739
*/
38-
var consolidateSubstitutionData = function(payload) {
40+
consolidateSubstitutionData = function(payload) {
3941
var substitutionData = {};
40-
if (payload.sub !== undefined && payload.section !== undefined){
42+
if (payload.sub !== undefined && payload.section !== undefined) {
4143
substitutionData = _.merge(payload.sub, payload.section);
42-
} else if (payload.sub !== undefined){
44+
} else if (payload.sub !== undefined) {
4345
substitutionData = payload.sub;
44-
} else if (payload.section !== undefined){
46+
} else if (payload.section !== undefined) {
4547
substitutionData = payload.section;
4648
}
4749
return substitutionData;
@@ -55,18 +57,18 @@ var consolidateSubstitutionData = function(payload) {
5557
* be translated into a SparkPost payload
5658
* @returns array: recipients array as per SparkPost payload format
5759
*/
58-
var parseTo = function(payload){
59-
var recipients = [];
60-
if (typeof payload.to === 'string'){
60+
parseTo = function(payload) {
61+
var recipients = [], to, i;
62+
if (typeof payload.to === 'string') {
6163
payload.to = [payload.to];
6264
}
63-
for (var i = 0; payload.to.length > i; i++){
64-
var to = {
65+
for (i = 0; payload.to.length > i; i++) {
66+
to = {
6567
address: {
6668
email: payload.to[i]
6769
}
6870
};
69-
if (payload.toname !== undefined && payload.toname[i] !== undefined){
71+
if (payload.toname !== undefined && payload.toname[i] !== undefined) {
7072
to.address.name = payload.toname[i];
7173
}
7274
recipients.push(to);
@@ -82,21 +84,21 @@ var parseTo = function(payload){
8284
* be translated into a SparkPost payload
8385
* @returns object: translation from SendGrid payload to SparkPost payload
8486
*/
85-
var translatePayload = function(payload) {
87+
translatePayload = function(payload) {
8688
var sub = consolidateSubstitutionData(payload)
8789
, input = {
88-
recipients: [],
89-
from: '',
90-
html: '',
91-
text: '',
92-
subject: ''
93-
};
90+
recipients: [],
91+
from: '',
92+
html: '',
93+
text: '',
94+
subject: ''
95+
};
9496

95-
if (payload.to !== undefined){
97+
if (payload.to !== undefined) {
9698
input.recipients = parseTo(payload);
9799
}
98100
input.from = payload.from;
99-
if (payload.fromname !== undefined){
101+
if (payload.fromname !== undefined) {
100102
input.from = input.from + ' <' + payload.fromname + '>';
101103
}
102104
input.subject = payload.subject;

lib/inboundDomains.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
var api = 'inbound-domains'
4-
/* global -Promise */
54
, Promise = require('./Promise');
65

76
module.exports = function(client) {
@@ -13,6 +12,8 @@ module.exports = function(client) {
1312
return client.get(options).asCallback(callback);
1413
},
1514
find: function(domain, callback) {
15+
var options;
16+
1617
if(typeof domain === 'function') {
1718
callback = domain;
1819
domain = null;
@@ -22,12 +23,14 @@ module.exports = function(client) {
2223
return Promise.reject(new Error('domain is required')).asCallback(callback);
2324
}
2425

25-
var options = {
26+
options = {
2627
uri: api + '/' + domain
2728
};
2829
return client.get(options).asCallback(callback);
2930
},
3031
create: function(domain, callback) {
32+
var options;
33+
3134
if(typeof domain === 'function') {
3235
callback = domain;
3336
domain = null;
@@ -37,7 +40,7 @@ module.exports = function(client) {
3740
return Promise.reject(new Error('domain is required')).asCallback(callback);
3841
}
3942

40-
var options = {
43+
options = {
4144
uri: api
4245
, json: {
4346
domain: domain
@@ -46,6 +49,8 @@ module.exports = function(client) {
4649
return client.post(options, callback).asCallback(callback);
4750
},
4851
delete: function(domain, callback) {
52+
var options;
53+
4954
if (typeof domain === 'function') {
5055
callback = domain;
5156
domain = null;
@@ -55,7 +60,7 @@ module.exports = function(client) {
5560
return Promise.reject(new Error('domain is required')).asCallback(callback);
5661
}
5762

58-
var options = {
63+
options = {
5964
uri: api + '/' + domain
6065
};
6166
return client.delete(options).asCallback(callback);

lib/messageEvents.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ var api = 'message-events';
66
* "Class" declaration, Message Events API exposes one function:
77
* - search: retrieves list of message events according to given params
88
*/
9-
module.exports = function (client) {
9+
module.exports = function(client) {
1010
return {
1111
search: function(parameters, callback) {
1212
var arrayParams = [
13-
'bounce_classes',
14-
'campaign_ids',
15-
'events',
16-
'friendly_froms',
17-
'message_ids',
18-
'recipients',
19-
'template_ids',
20-
'transmission_ids'
21-
]
13+
'bounce_classes',
14+
'campaign_ids',
15+
'events',
16+
'friendly_froms',
17+
'message_ids',
18+
'recipients',
19+
'template_ids',
20+
'transmission_ids'
21+
]
2222
, options;
2323

2424
arrayParams.forEach(function(paramname) {

0 commit comments

Comments
 (0)