Skip to content

Commit

Permalink
introduce eslint and tried to find out your style
Browse files Browse the repository at this point in the history
  • Loading branch information
timaschew committed May 26, 2017
1 parent c3e3d58 commit 76a7ee9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 18 deletions.
27 changes: 27 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -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"
]
}
};
35 changes: 17 additions & 18 deletions mailjet-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ const RESOURCE = 0
const ID = 1
const ACTION = 2

const STRICT = false

/*
* Imports.
*
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Empty file removed test.js
Empty file.
3 changes: 3 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global describe, it */
const FILE = 'FILE'
const EMAIL = '[email protected]'
const EMAIL2 = '[email protected]'
Expand Down Expand Up @@ -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.'

Expand Down

0 comments on commit 76a7ee9

Please sign in to comment.