Skip to content

Commit

Permalink
chore: replace XO with eslint and prettier
Browse files Browse the repository at this point in the history
Remove the XO tool with eslint and prettier, along with updating the
linter rules.
  • Loading branch information
terinjokes committed Jan 8, 2018
1 parent 04440cb commit 6b8177a
Show file tree
Hide file tree
Showing 18 changed files with 1,698 additions and 2,340 deletions.
25 changes: 25 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
extends:
- es/2015/server
- plugin:prettier/recommended
- plugin:eslint-comments/recommended
- plugin:node/recommended
- plugin:security/recommended
- plugin:promise/recommended
plugins:
- eslint-comments
- node
- security
- promise
- notice
rules:
prefer-reflect: off
no-underscore-dangle:
- error
- allowAfterThis: true
prefer-rest-params: off
node/exports-style:
- error
- module.exports
notice/notice:
- error
- template: "/*\n * Copyright (C) 2014-present Cloudflare, Inc.\n\n * This software may be modified and distributed under the terms\n * of the MIT license. See the LICENSE file for details.\n */"
8 changes: 8 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
printWidth: 80
tabWidth: 2
useTabs: false
semi: true
singleQuote: true
trailingComma: es5
bracketSpacing: false
parser: babylon
66 changes: 39 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
/*
* Copyright (C) 2014-present Cloudflare, Inc.
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

'use strict';
var prototypal = require('es-class');
var auto = require('autocreate');

var Client = require('./lib/Client');
const prototypal = require('es-class');
const auto = require('autocreate');

const Client = require('./lib/Client');

var resources = {
/* eslint-disable global-require */
const resources = {
dnsRecords: require('./lib/resources/DNSRecords'),
ips: require('./lib/resources/IPs'),
zones: require('./lib/resources/Zones'),
zoneSettings: require('./lib/resources/ZoneSettings'),
zoneCustomHostNames: require('./lib/resources/ZoneCustomHostNames'),
user: require('./lib/resources/User')
user: require('./lib/resources/User'),
};
/* eslint-enable global-require */

/**
* Constructs and returns a new Cloudflare API client with the specified authentication.
Expand All @@ -28,29 +38,31 @@ var resources = {
* @property {ZoneCustomHostNames} zoneCustomHostNames - Zone Custom Host Names instance
* @property {User} user - User instance
*/
var Cloudflare = auto(prototypal({
constructor: function (auth) {
var client = new Client({
email: auth && auth.email,
key: auth && auth.key
});

Object.defineProperty(this, '_client', {
value: client,
writable: false,
enumerable: false,
configurable: false
});

Object.keys(resources).forEach(function (resource) {
Object.defineProperty(this, resource, {
value: resources[resource](this._client),
writable: true,
const Cloudflare = auto(
prototypal({
constructor: function constructor(auth) {
const client = new Client({
email: auth && auth.email,
key: auth && auth.key,
});

Object.defineProperty(this, '_client', {
value: client,
writable: false,
enumerable: false,
configurable: true
configurable: false,
});
}, this);
}
}));

Object.keys(resources).forEach(function(resource) {
Object.defineProperty(this, resource, {
value: resources[resource](this._client), // eslint-disable-line security/detect-object-injection
writable: true,
enumerable: false,
configurable: true,
});
}, this);
},
})
);

module.exports = Cloudflare;
58 changes: 33 additions & 25 deletions lib/Client.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,59 @@
/*
* Copyright (C) 2014-present Cloudflare, Inc.
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

'use strict';
var prototypal = require('es-class');
var pkg = require('../package.json');
var Getter = require('./Getter');

var USER_AGENT = JSON.stringify({
const prototypal = require('es-class');
const pkg = require('../package.json');
const Getter = require('./Getter');

const USER_AGENT = JSON.stringify({
bindings_version: pkg.version, // eslint-disable-line camelcase
lang: 'node',
lang_version: process.version, // eslint-disable-line camelcase
platform: process.platform,
arch: process.arch,
publisher: 'cloudflare'
publisher: 'cloudflare',
});

function isPlainObject(x) {
var prototype = Object.getPrototypeOf(x);
var toString = Object.prototype.toString;
const isPlainObject = function isPlainObject(x) {
const prototype = Object.getPrototypeOf(x);
const toString = Object.prototype.toString;

return toString.call(x) === '[object Object]' &&
(prototype === null || prototype === Object.getPrototypeOf({}));
}
return (
toString.call(x) === '[object Object]' &&
(prototype === null || prototype === Object.getPrototypeOf({}))
);
};

function isUserServiceKey(x) {
const isUserServiceKey = function isUserServiceKey(x) {
return x && x.substring(0, 5) === 'v1.0-';
}
};

module.exports = prototypal({
constructor: function (options) {
constructor: function constructor(options) {
this.email = options.email;
this.key = options.key;
this.getter = new Getter(options);
},
request: function (requestMethod, requestPath, data, opts) {
var uri = 'https://api.cloudflare.com/client/v4/' + requestPath;
request(requestMethod, requestPath, data, opts) {
const uri = `https://api.cloudflare.com/client/v4/${requestPath}`;

var options = {
const options = {
json: true,
timeout: opts.timeout || 1E4,
timeout: opts.timeout || 1e4,
retries: opts.retries,
method: requestMethod,
headers: {
'user-agent': 'cloudflare/' + pkg.version + ' node/' + process.versions.node,
'user-agent': `cloudflare/${pkg.version} node/${process.versions.node}`,
'Content-Type': 'application/json',
Accept: 'application/json',
'X-Cloudflare-Client-User-Agent': USER_AGENT
}
'X-Cloudflare-Client-User-Agent': USER_AGENT,
},
};

if (isUserServiceKey(opts.auth.key || this.key)) {
Expand All @@ -63,8 +73,6 @@ module.exports = prototypal({
options.body = JSON.stringify(options.body);
}

return this.getter.got(uri, options).then(function (res) {
return res.body;
});
}
return this.getter.got(uri, options).then(res => res.body);
},
});
18 changes: 13 additions & 5 deletions lib/Getter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
/*
* Copyright (C) 2014-present Cloudflare, Inc.
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

'use strict';
var prototypal = require('es-class');
var assign = require('object-assign');
var got = require('got');

const prototypal = require('es-class');
const assign = require('object-assign');
const got = require('got');

module.exports = prototypal({
got: function (uri, options) {
got(uri, options) {
options = assign({}, options);

return got(uri, options);
}
},
});
50 changes: 29 additions & 21 deletions lib/Resource.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
/*
* Copyright (C) 2014-present Cloudflare, Inc.
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

'use strict';
var prototypal = require('es-class');
var method = require('./method');

var BASIC_METHODS = {
const prototypal = require('es-class');
const method = require('./method');

const BASIC_METHODS = {
browse: method({
method: 'GET'
method: 'GET',
}),
read: method({
method: 'GET',
path: '/:id'
path: '/:id',
}),
edit: method({
method: 'PATCH',
path: '/:id'
path: '/:id',
}),
add: method({
method: 'POST'
method: 'POST',
}),
del: method({
method: 'DELETE',
path: '/:id'
})
path: '/:id',
}),
};

/**
Expand All @@ -33,33 +41,33 @@ var BASIC_METHODS = {
module.exports = prototypal(
/** @lends Resource.prototype */
{
constructor: function (client) {
constructor: function constructor(client) {
Object.defineProperty(this, '_client', {
value: client,
writable: false,
enumerable: false,
configurable: false
configurable: false,
});

if (Array.isArray(this.includeBasic)) {
this.includeBasic.forEach(function (m) {
Object.defineProperty(this, m, {
value: BASIC_METHODS[m],
this.includeBasic.forEach(function(basicMethod) {
Object.defineProperty(this, basicMethod, {
value: BASIC_METHODS[basicMethod], // eslint-disable-line security/detect-object-injection
writable: true,
enumberable: false,
configurable: true
configurable: true,
});
}, this);
}
},
/**
* @param {string} methodPath - The path from the {@link method} that should be
* joined with the resource's path.
*/
createFullPath: function (methodPath) {
/**
* @param {string} methodPath - The path from the {@link method} that should be
* joined with the resource's path.
*/
createFullPath(methodPath) {
return (methodPath && [this.path, methodPath].join('/')) || this.path;
},
path: '',
hasBrokenPatch: false
hasBrokenPatch: false,
}
);
Loading

0 comments on commit 6b8177a

Please sign in to comment.