diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..7f654b8 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,27 @@ +module.exports = { + "env": { + "commonjs": true, + "es6": true, + "node": true + }, + "extends": "eslint:recommended", + "rules": { + "no-console": 0, + "indent": [ + "error", + 2 + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "single" + ], + "semi": [ + "error", + "never" + ] + } +}; \ No newline at end of file diff --git a/mailjet-client.js b/mailjet-client.js index 576e498..6d0447c 100755 --- a/mailjet-client.js +++ b/mailjet-client.js @@ -28,8 +28,6 @@ const RESOURCE = 0 const ID = 1 const ACTION = 2 -const STRICT = false - /* * Imports. * @@ -47,7 +45,7 @@ const JSONb = require('json-bigint')({ storeAsString: true }) const version = require('./package.json').version /* Extend superagent request with proxy method */ -require('superagent-proxy')(request); +require('superagent-proxy')(request) /* * MailjetClient constructor. @@ -60,7 +58,7 @@ require('superagent-proxy')(request); * https://www.mailjet.com/ */ function MailjetClient (api_key, api_secret, options, perform_api_call) { - this.config = this.setConfig(options); + this.config = this.setConfig(options) this.perform_api_call = perform_api_call || false // To be updated according to the npm repo version this.version = version @@ -107,24 +105,24 @@ MailjetClient.prototype.connect = function (apiKey, apiSecret, options) { this.apiSecret = apiSecret this.options = options || {} if (options) { - this.config = this.setConfig(options); + this.config = this.setConfig(options) } return this } MailjetClient.prototype.setConfig = function (options) { - config = require('./config') + const config = require('./config') if (typeof options === 'object' && options != null && options.length != 0) { if (options.url) config.url = options.url if (options.version) config.version = options.version if (options.secured) config.secured = options.secured if (options.perform_api_call) config.perform_api_call = options.perform_api_call - } else if (options != undefined) { - throw "warning, your options variable is not a valid object." + } else if (options != null) { + throw new Error('warning, your options variable is not a valid object.') } return config -}; +} /* * path. @@ -144,8 +142,8 @@ MailjetClient.prototype.path = function (resource, sub, params, options) { console.log('filters =', params) } - url = (options && 'url' in options ? options.url : this.config.url) - api_version = (options && 'version' in options ? options.version : this.config.version) + const url = (options && 'url' in options ? options.url : this.config.url) + const api_version = (options && 'version' in options ? options.version : this.config.version) var base = _path.join(api_version, sub) if (Object.keys(params).length === 0) { @@ -222,7 +220,7 @@ MailjetClient.prototype.httpRequest = function (method, url, data, callback, per const error = new Error('Unsuccessful') error.ErrorMessage = body.ErrorMessage || err.message error.statusCode = err.status || null - error.response = result || null + error.response = result || null return ret(error) } @@ -294,17 +292,18 @@ function MailjetResource (method, func, options, context) { return {} } })(), that.options) - + + let secured = null if (that.options && 'secured' in that.options) { - secured = that.options.secured; + secured = that.options.secured } else { - secured = self.config.secured; + secured = self.config.secured } - + let perform_api_call = null if (that.options && 'perform_api_call' in that.options) { - perform_api_call = that.options.perform_api_call; + perform_api_call = that.options.perform_api_call } else { - perform_api_call = self.config.perform_api_call; + perform_api_call = self.config.perform_api_call } that.callUrl = that.base diff --git a/package.json b/package.json index 3b9e0f7..bc69a90 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ }, "dependencies": { "bluebird": "^3.3.5", + "eslint": "^3.19.0", "json-bigint": "^0.2.0", "qs": "^4.0.0", "superagent": "^2.0.0", diff --git a/test.js b/test.js deleted file mode 100644 index e69de29..0000000 diff --git a/test/test.js b/test/test.js index c23036a..da0b382 100644 --- a/test/test.js +++ b/test/test.js @@ -1,3 +1,4 @@ +/* global describe, it */ const FILE = 'FILE' const EMAIL = 'test@mailjet.com' const EMAIL2 = 'test2@mailjet.com' @@ -101,8 +102,10 @@ describe('Basic Usage', function () { describe('post', function () { var sender = client.post('sender') + // eslint-disable-next-line no-unused-vars var deletedErrorMessage = 'There is an already existing deleted sender with the same email. ' + 'You can use "validate" action in order to activate it.' + // eslint-disable-next-line no-unused-vars var inactiveErrorMessage = 'There is an already existing inactive sender with the same email. ' + 'You can use "validate" action in order to activate it.'