Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6b8177a

Browse files
committed
chore: replace XO with eslint and prettier
Remove the XO tool with eslint and prettier, along with updating the linter rules.
1 parent 04440cb commit 6b8177a

18 files changed

Lines changed: 1698 additions & 2340 deletions

.eslintrc.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
extends:
2+
- es/2015/server
3+
- plugin:prettier/recommended
4+
- plugin:eslint-comments/recommended
5+
- plugin:node/recommended
6+
- plugin:security/recommended
7+
- plugin:promise/recommended
8+
plugins:
9+
- eslint-comments
10+
- node
11+
- security
12+
- promise
13+
- notice
14+
rules:
15+
prefer-reflect: off
16+
no-underscore-dangle:
17+
- error
18+
- allowAfterThis: true
19+
prefer-rest-params: off
20+
node/exports-style:
21+
- error
22+
- module.exports
23+
notice/notice:
24+
- error
25+
- 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 */"

.prettierrc.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
printWidth: 80
2+
tabWidth: 2
3+
useTabs: false
4+
semi: true
5+
singleQuote: true
6+
trailingComma: es5
7+
bracketSpacing: false
8+
parser: babylon

index.js

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1+
/*
2+
* Copyright (C) 2014-present Cloudflare, Inc.
3+
4+
* This software may be modified and distributed under the terms
5+
* of the MIT license. See the LICENSE file for details.
6+
*/
7+
18
'use strict';
2-
var prototypal = require('es-class');
3-
var auto = require('autocreate');
49

5-
var Client = require('./lib/Client');
10+
const prototypal = require('es-class');
11+
const auto = require('autocreate');
12+
13+
const Client = require('./lib/Client');
614

7-
var resources = {
15+
/* eslint-disable global-require */
16+
const resources = {
817
dnsRecords: require('./lib/resources/DNSRecords'),
918
ips: require('./lib/resources/IPs'),
1019
zones: require('./lib/resources/Zones'),
1120
zoneSettings: require('./lib/resources/ZoneSettings'),
1221
zoneCustomHostNames: require('./lib/resources/ZoneCustomHostNames'),
13-
user: require('./lib/resources/User')
22+
user: require('./lib/resources/User'),
1423
};
24+
/* eslint-enable global-require */
1525

1626
/**
1727
* Constructs and returns a new Cloudflare API client with the specified authentication.
@@ -28,29 +38,31 @@ var resources = {
2838
* @property {ZoneCustomHostNames} zoneCustomHostNames - Zone Custom Host Names instance
2939
* @property {User} user - User instance
3040
*/
31-
var Cloudflare = auto(prototypal({
32-
constructor: function (auth) {
33-
var client = new Client({
34-
email: auth && auth.email,
35-
key: auth && auth.key
36-
});
37-
38-
Object.defineProperty(this, '_client', {
39-
value: client,
40-
writable: false,
41-
enumerable: false,
42-
configurable: false
43-
});
44-
45-
Object.keys(resources).forEach(function (resource) {
46-
Object.defineProperty(this, resource, {
47-
value: resources[resource](this._client),
48-
writable: true,
41+
const Cloudflare = auto(
42+
prototypal({
43+
constructor: function constructor(auth) {
44+
const client = new Client({
45+
email: auth && auth.email,
46+
key: auth && auth.key,
47+
});
48+
49+
Object.defineProperty(this, '_client', {
50+
value: client,
51+
writable: false,
4952
enumerable: false,
50-
configurable: true
53+
configurable: false,
5154
});
52-
}, this);
53-
}
54-
}));
55+
56+
Object.keys(resources).forEach(function(resource) {
57+
Object.defineProperty(this, resource, {
58+
value: resources[resource](this._client), // eslint-disable-line security/detect-object-injection
59+
writable: true,
60+
enumerable: false,
61+
configurable: true,
62+
});
63+
}, this);
64+
},
65+
})
66+
);
5567

5668
module.exports = Cloudflare;

lib/Client.js

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,59 @@
1+
/*
2+
* Copyright (C) 2014-present Cloudflare, Inc.
3+
4+
* This software may be modified and distributed under the terms
5+
* of the MIT license. See the LICENSE file for details.
6+
*/
7+
18
'use strict';
2-
var prototypal = require('es-class');
3-
var pkg = require('../package.json');
4-
var Getter = require('./Getter');
59

6-
var USER_AGENT = JSON.stringify({
10+
const prototypal = require('es-class');
11+
const pkg = require('../package.json');
12+
const Getter = require('./Getter');
13+
14+
const USER_AGENT = JSON.stringify({
715
bindings_version: pkg.version, // eslint-disable-line camelcase
816
lang: 'node',
917
lang_version: process.version, // eslint-disable-line camelcase
1018
platform: process.platform,
1119
arch: process.arch,
12-
publisher: 'cloudflare'
20+
publisher: 'cloudflare',
1321
});
1422

15-
function isPlainObject(x) {
16-
var prototype = Object.getPrototypeOf(x);
17-
var toString = Object.prototype.toString;
23+
const isPlainObject = function isPlainObject(x) {
24+
const prototype = Object.getPrototypeOf(x);
25+
const toString = Object.prototype.toString;
1826

19-
return toString.call(x) === '[object Object]' &&
20-
(prototype === null || prototype === Object.getPrototypeOf({}));
21-
}
27+
return (
28+
toString.call(x) === '[object Object]' &&
29+
(prototype === null || prototype === Object.getPrototypeOf({}))
30+
);
31+
};
2232

23-
function isUserServiceKey(x) {
33+
const isUserServiceKey = function isUserServiceKey(x) {
2434
return x && x.substring(0, 5) === 'v1.0-';
25-
}
35+
};
2636

2737
module.exports = prototypal({
28-
constructor: function (options) {
38+
constructor: function constructor(options) {
2939
this.email = options.email;
3040
this.key = options.key;
3141
this.getter = new Getter(options);
3242
},
33-
request: function (requestMethod, requestPath, data, opts) {
34-
var uri = 'https://api.cloudflare.com/client/v4/' + requestPath;
43+
request(requestMethod, requestPath, data, opts) {
44+
const uri = `https://api.cloudflare.com/client/v4/${requestPath}`;
3545

36-
var options = {
46+
const options = {
3747
json: true,
38-
timeout: opts.timeout || 1E4,
48+
timeout: opts.timeout || 1e4,
3949
retries: opts.retries,
4050
method: requestMethod,
4151
headers: {
42-
'user-agent': 'cloudflare/' + pkg.version + ' node/' + process.versions.node,
52+
'user-agent': `cloudflare/${pkg.version} node/${process.versions.node}`,
4353
'Content-Type': 'application/json',
4454
Accept: 'application/json',
45-
'X-Cloudflare-Client-User-Agent': USER_AGENT
46-
}
55+
'X-Cloudflare-Client-User-Agent': USER_AGENT,
56+
},
4757
};
4858

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

66-
return this.getter.got(uri, options).then(function (res) {
67-
return res.body;
68-
});
69-
}
76+
return this.getter.got(uri, options).then(res => res.body);
77+
},
7078
});

lib/Getter.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
/*
2+
* Copyright (C) 2014-present Cloudflare, Inc.
3+
4+
* This software may be modified and distributed under the terms
5+
* of the MIT license. See the LICENSE file for details.
6+
*/
7+
18
'use strict';
2-
var prototypal = require('es-class');
3-
var assign = require('object-assign');
4-
var got = require('got');
9+
10+
const prototypal = require('es-class');
11+
const assign = require('object-assign');
12+
const got = require('got');
513

614
module.exports = prototypal({
7-
got: function (uri, options) {
15+
got(uri, options) {
816
options = assign({}, options);
917

1018
return got(uri, options);
11-
}
19+
},
1220
});

lib/Resource.js

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1+
/*
2+
* Copyright (C) 2014-present Cloudflare, Inc.
3+
4+
* This software may be modified and distributed under the terms
5+
* of the MIT license. See the LICENSE file for details.
6+
*/
7+
18
'use strict';
2-
var prototypal = require('es-class');
3-
var method = require('./method');
49

5-
var BASIC_METHODS = {
10+
const prototypal = require('es-class');
11+
const method = require('./method');
12+
13+
const BASIC_METHODS = {
614
browse: method({
7-
method: 'GET'
15+
method: 'GET',
816
}),
917
read: method({
1018
method: 'GET',
11-
path: '/:id'
19+
path: '/:id',
1220
}),
1321
edit: method({
1422
method: 'PATCH',
15-
path: '/:id'
23+
path: '/:id',
1624
}),
1725
add: method({
18-
method: 'POST'
26+
method: 'POST',
1927
}),
2028
del: method({
2129
method: 'DELETE',
22-
path: '/:id'
23-
})
30+
path: '/:id',
31+
}),
2432
};
2533

2634
/**
@@ -33,33 +41,33 @@ var BASIC_METHODS = {
3341
module.exports = prototypal(
3442
/** @lends Resource.prototype */
3543
{
36-
constructor: function (client) {
44+
constructor: function constructor(client) {
3745
Object.defineProperty(this, '_client', {
3846
value: client,
3947
writable: false,
4048
enumerable: false,
41-
configurable: false
49+
configurable: false,
4250
});
4351

4452
if (Array.isArray(this.includeBasic)) {
45-
this.includeBasic.forEach(function (m) {
46-
Object.defineProperty(this, m, {
47-
value: BASIC_METHODS[m],
53+
this.includeBasic.forEach(function(basicMethod) {
54+
Object.defineProperty(this, basicMethod, {
55+
value: BASIC_METHODS[basicMethod], // eslint-disable-line security/detect-object-injection
4856
writable: true,
4957
enumberable: false,
50-
configurable: true
58+
configurable: true,
5159
});
5260
}, this);
5361
}
5462
},
55-
/**
56-
* @param {string} methodPath - The path from the {@link method} that should be
57-
* joined with the resource's path.
58-
*/
59-
createFullPath: function (methodPath) {
63+
/**
64+
* @param {string} methodPath - The path from the {@link method} that should be
65+
* joined with the resource's path.
66+
*/
67+
createFullPath(methodPath) {
6068
return (methodPath && [this.path, methodPath].join('/')) || this.path;
6169
},
6270
path: '',
63-
hasBrokenPatch: false
71+
hasBrokenPatch: false,
6472
}
6573
);

0 commit comments

Comments
 (0)