Skip to content

Commit 5c560b2

Browse files
committed
Upgrade codebase with safe es6 features
1 parent 36cecde commit 5c560b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2550
-2721
lines changed

.eslintrc.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
env:
2+
node: true
3+
4+
parserOptions:
5+
ecmaVersion: 6
6+
7+
extends:
8+
- eslint:recommended
9+
- plugin:node/recommended
10+
11+
rules:
12+
valid-jsdoc: 0
13+
func-style: 0
14+
no-use-before-define: 0
15+
camelcase: 1
16+
no-unused-vars: 2
17+
no-alert: 2
18+
no-console: [2, { allow: ['warn', 'error'] }]
19+
no-underscore-dangle: 0
20+
21+
strict: [2, 'global']
22+
no-var: 2
23+
prefer-arrow-callback: 2
24+
prefer-const: 2
25+
no-inner-declarations: 0
26+
object-shorthand: [2, 'consistent-as-needed']
27+
newline-per-chained-call: 2
28+
29+
node/no-deprecated-api: 0

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
tmp
3+
test

lib/backoffs.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
var _ = require('lodash');
1+
'use strict';
22

3-
var builtinStrategies = {
4-
fixed: function(delay) {
3+
const _ = require('lodash');
4+
5+
const builtinStrategies = {
6+
fixed(delay) {
57
return function() {
68
return delay;
79
};
810
},
911

10-
exponential: function(delay) {
12+
exponential(delay) {
1113
return function(attemptsMade) {
1214
return Math.round((Math.pow(2, attemptsMade) - 1) * delay);
1315
};
@@ -29,7 +31,7 @@ function lookupStrategy(backoff, customStrategies) {
2931
}
3032

3133
module.exports = {
32-
normalize: function(backoff) {
34+
normalize(backoff) {
3335
if (_.isFinite(backoff)) {
3436
return {
3537
type: 'fixed',
@@ -40,9 +42,9 @@ module.exports = {
4042
}
4143
},
4244

43-
calculate: function(backoff, attemptsMade, customStrategies, err) {
45+
calculate(backoff, attemptsMade, customStrategies, err) {
4446
if (backoff) {
45-
var strategy = lookupStrategy(backoff, customStrategies);
47+
const strategy = lookupStrategy(backoff, customStrategies);
4648

4749
return strategy(attemptsMade, err);
4850
}

lib/commands/index.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@
1212
*/
1313
'use strict';
1414

15-
var fs = require('fs');
16-
var path = require('path');
17-
var promisify = require('util.promisify'); //TODO in node >= 8 could be removed
15+
const fs = require('fs');
16+
const path = require('path');
17+
const promisify = require('util.promisify'); //TODO in node >= 8 could be removed
1818

19-
var utils = require('../utils');
19+
const utils = require('../utils');
2020

2121
//TODO node >= 10 could be used require('fs').promises()
22-
var _fs = {
22+
const _fs = {
2323
readdirAsync: promisify(fs.readdir),
2424
readFileAsync: promisify(fs.readFile)
2525
};
2626

2727
module.exports = (function() {
28-
var scripts;
28+
let scripts;
2929

3030
return function(client) {
31-
return utils.isRedisReady(client).then(function() {
31+
return utils.isRedisReady(client).then(() => {
3232
scripts = scripts || loadScripts(__dirname);
3333

34-
return scripts.then(function(_scripts) {
35-
return _scripts.forEach(function(command) {
34+
return scripts.then(_scripts => {
35+
return _scripts.forEach(command => {
3636
return client.defineCommand(command.name, command.options);
3737
});
3838
});
@@ -43,19 +43,19 @@ module.exports = (function() {
4343
function loadScripts(dir) {
4444
return _fs
4545
.readdirAsync(dir)
46-
.then(function(files) {
47-
return files.filter(function(file) {
46+
.then(files => {
47+
return files.filter(file => {
4848
return path.extname(file) === '.lua';
4949
});
5050
})
51-
.then(function(files) {
51+
.then(files => {
5252
return Promise.all(
53-
files.map(function(file) {
54-
var longName = path.basename(file, '.lua');
55-
var name = longName.split('-')[0];
56-
var numberOfKeys = parseInt(longName.split('-')[1]);
53+
files.map(file => {
54+
const longName = path.basename(file, '.lua');
55+
const name = longName.split('-')[0];
56+
const numberOfKeys = parseInt(longName.split('-')[1]);
5757

58-
return _fs.readFileAsync(path.join(dir, file)).then(function(lua) {
58+
return _fs.readFileAsync(path.join(dir, file)).then(lua => {
5959
return {
6060
name: name,
6161
options: { numberOfKeys: numberOfKeys, lua: lua.toString() }

lib/getters.js

+21-27
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
/*eslint-env node */
21
'use strict';
32

4-
var _ = require('lodash');
5-
var Job = require('./job');
3+
const _ = require('lodash');
4+
const Job = require('./job');
65

76
module.exports = function(Queue) {
87
Queue.prototype.getJob = function(jobId) {
98
return Job.fromId(this, jobId);
109
};
1110

1211
Queue.prototype._commandByType = function(types, count, callback) {
13-
var _this = this;
14-
15-
return _.map(types, function(type) {
12+
return _.map(types, type => {
1613
type = type === 'waiting' ? 'wait' : type; // alias
1714

18-
var key = _this.toKey(type);
15+
const key = this.toKey(type);
1916

2017
switch (type) {
2118
case 'completed':
@@ -44,7 +41,7 @@ module.exports = function(Queue) {
4441
// Queue#getJobCountByTypes('completed', 'failed') => completed + failed count
4542
// Queue#getJobCountByTypes('completed,waiting', 'failed') => completed + waiting + failed count
4643
Queue.prototype.getJobCountByTypes = function() {
47-
return this.getJobCounts.apply(this, arguments).then(function(result) {
44+
return this.getJobCounts.apply(this, arguments).then(result => {
4845
return _.chain(result)
4946
.values()
5047
.sum()
@@ -57,16 +54,16 @@ module.exports = function(Queue) {
5754
*
5855
*/
5956
Queue.prototype.getJobCounts = function() {
60-
var types = parseTypeArg(arguments);
61-
var multi = this.multi();
57+
const types = parseTypeArg(arguments);
58+
const multi = this.multi();
6259

63-
this._commandByType(types, true, function(key, command) {
60+
this._commandByType(types, true, (key, command) => {
6461
multi[command](key);
6562
});
6663

67-
return multi.exec().then(function(res) {
68-
var counts = {};
69-
res.forEach(function(res, index) {
64+
return multi.exec().then(res => {
65+
const counts = {};
66+
res.forEach((res, index) => {
7067
counts[types[index]] = res[1] || 0;
7168
});
7269
return counts;
@@ -119,15 +116,13 @@ module.exports = function(Queue) {
119116
};
120117

121118
Queue.prototype.getRanges = function(types, start, end, asc) {
122-
var _this = this;
123-
124119
start = _.isUndefined(start) ? 0 : start;
125120
end = _.isUndefined(end) ? -1 : end;
126121

127-
var multi = this.multi();
128-
var multiCommands = [];
122+
const multi = this.multi();
123+
const multiCommands = [];
129124

130-
_this._commandByType(parseTypeArg(types), false, function(key, command) {
125+
this._commandByType(parseTypeArg(types), false, (key, command) => {
131126
switch (command) {
132127
case 'lrange':
133128
if (asc) {
@@ -148,11 +143,11 @@ module.exports = function(Queue) {
148143
}
149144
});
150145

151-
return multi.exec().then(function(responses) {
152-
var results = [];
146+
return multi.exec().then(responses => {
147+
let results = [];
153148

154-
responses.forEach(function(response, index) {
155-
var result = response[1] || [];
149+
responses.forEach((response, index) => {
150+
const result = response[1] || [];
156151

157152
if (asc && multiCommands[index] === 'lrange') {
158153
results = results.concat(result.reverse());
@@ -165,15 +160,14 @@ module.exports = function(Queue) {
165160
};
166161

167162
Queue.prototype.getJobs = function(types, start, end, asc) {
168-
var _this = this;
169-
return this.getRanges(types, start, end, asc).then(function(jobIds) {
170-
return Promise.all(jobIds.map(_this.getJobFromId));
163+
return this.getRanges(types, start, end, asc).then(jobIds => {
164+
return Promise.all(jobIds.map(this.getJobFromId));
171165
});
172166
};
173167
};
174168

175169
function parseTypeArg(args) {
176-
var types = _.chain([])
170+
const types = _.chain([])
177171
.concat(args)
178172
.join(',')
179173
.split(/\s*,\s*/g)

0 commit comments

Comments
 (0)