Skip to content

Commit

Permalink
Use let/const instead of var
Browse files Browse the repository at this point in the history
  • Loading branch information
mcheshkov committed Jun 8, 2018
1 parent f77aee2 commit 19adae5
Show file tree
Hide file tree
Showing 55 changed files with 228 additions and 239 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"no-console": 0,
"no-mixed-requires": 0,
"no-multiple-empty-lines": [2, {"max": 1}],
"no-var": "error",
"global-require": 0
},
"env": {
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_master_and_ipc/master.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @type {ClusterProcess} Master or Worker instance */
var proc = require('luster');
const proc = require('luster');

if (proc.isMaster) {
// register command repeater in the master
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_master_and_ipc/worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var http = require('http'),
const http = require('http'),
worker = require('luster'),
counters = {};

Expand Down
2 changes: 1 addition & 1 deletion examples/simple_extension/worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var http = require('http'),
const http = require('http'),
cluster = require('cluster');

if (cluster.worker.id === 1) {
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_server/worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var http = require('http'),
const http = require('http'),
worker = require('luster');

if (worker.wid === 1 || worker.wid === 0) {
Expand Down
32 changes: 15 additions & 17 deletions lib/cluster_process.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var cluster = require('cluster'),
const cluster = require('cluster'),
path = require('path'),
RPC = require('./rpc'),
RPCCallback = require('./rpc-callback'),
Configuration = require('./configuration'),
EventEmitterEx = require('./event_emitter_ex'),
LusterClusterProcessError = require('./errors').LusterClusterProcessError,
LusterConfigurationError = require('./errors').LusterConfigurationError,
ClusterProcess;
LusterConfigurationError = require('./errors').LusterConfigurationError;

/**
* @param {Object} context
Expand All @@ -27,7 +26,7 @@ function has(context, propName) {
* @class ClusterProcess
* @augments EventEmitterEx
*/
ClusterProcess = EventEmitterEx.create(function ClusterProcess() {
const ClusterProcess = EventEmitterEx.create(function ClusterProcess() {
ClusterProcess.__super.apply(this, arguments);

/** @private */
Expand Down Expand Up @@ -116,10 +115,10 @@ ClusterProcess.prototype.configure = function(config, applyEnv, basedir) {
* @param {Function} callback function(error)
*/
ClusterProcess.prototype.loadExtension = function(name, callback) {
var /** @type Extension */
const /** @type Extension */
extension = require(name),
self = this,
config = this.config.get('extensions.' + name);
self = this;
let config = this.config.get('extensions.' + name);

this.extensions[name] = extension;

Expand Down Expand Up @@ -147,13 +146,12 @@ function extendResolvePath(basedir) {
// using module internals isn't good, but restarting with corrected NODE_PATH looks more ugly, IMO
module.paths.push(basedir);

var _basedir = basedir.split('/'),
size = basedir.length,
i = 0,
modulesPath;
const _basedir = basedir.split('/'),
size = basedir.length;
let i = 0;

while (size > i++) {
modulesPath = _basedir.slice(0, i).join('/') + '/node_modules';
const modulesPath = _basedir.slice(0, i).join('/') + '/node_modules';

if (module.paths.indexOf(modulesPath) === -1) {
module.paths.push(modulesPath);
Expand All @@ -178,12 +176,12 @@ ClusterProcess.prototype._onConfigured = function() {
this.config.resolve('extensionsPath', path.dirname(this.config.resolve('app')))
));

var self = this,
const self = this,
extensions = this.config.getKeys('extensions'),
wait = extensions.length,
loadedExtensions = [],
loadTimeout = this.config.get('extensionsLoadTimeout', 10000),
loadTimer;
loadTimeout = this.config.get('extensionsLoadTimeout', 10000);
let loadTimer;

if (wait === 0) {
self._initialized = true;
Expand All @@ -209,7 +207,7 @@ ClusterProcess.prototype._onConfigured = function() {
}, this);

loadTimer = setTimeout(function() {
var timeouted = extensions.filter(function (name) {
const timeouted = extensions.filter(function (name) {
return loadedExtensions.indexOf(name) < 0;
}),
error = LusterClusterProcessError.createError(
Expand Down Expand Up @@ -295,7 +293,7 @@ ClusterProcess.prototype._setupIPCMessagesHandler = function() {
* @private
*/
ClusterProcess.prototype._onMessage = function(target, rawMessage) {
var message = RPC.parseMessage(rawMessage);
const message = RPC.parseMessage(rawMessage);

if (message === null) {
return;
Expand Down
14 changes: 6 additions & 8 deletions lib/configuration/check.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var LusterConfigurationError = require('../errors').LusterConfigurationError,
const LusterConfigurationError = require('../errors').LusterConfigurationError,
typeOf = require('./helpers').typeOf,
get = require('./helpers').get,
CHECKS;
get = require('./helpers').get;

/**
* @typedef PropertyCheck
Expand All @@ -16,7 +15,7 @@ var LusterConfigurationError = require('../errors').LusterConfigurationError,
* @type {Object}
* @property {PropertyCheck} *
*/
CHECKS = {
const CHECKS = {
// path to worker main module
'app': { required: true, type: 'string' },
// number of workers to spawn
Expand Down Expand Up @@ -51,8 +50,7 @@ CHECKS = {
* @throws {LusterConfigurationError} if property check has been failed
*/
function checkProperty(path, value, check) {
var type = typeOf(value),
allowedTypes;
const type = typeOf(value);

// required property
if (type === 'undefined') {
Expand All @@ -66,7 +64,7 @@ function checkProperty(path, value, check) {
}

// allowed types
allowedTypes = check.type && [].concat(check.type);
const allowedTypes = check.type && [].concat(check.type);
if (allowedTypes && allowedTypes.indexOf(type) === -1) {
throw LusterConfigurationError.createError(
LusterConfigurationError.CODES.PROP_TYPE_CHECK_FAILED,
Expand All @@ -84,7 +82,7 @@ function checkProperty(path, value, check) {
* @returns {Number} of failed checks
*/
function checkConfiguration(conf) {
var failedChecks = 0;
let failedChecks = 0;

Object
.keys(CHECKS)
Expand Down
39 changes: 19 additions & 20 deletions lib/configuration/helpers.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var util = require('util'),
const util = require('util'),
LusterConfigurationError = require('../errors').LusterConfigurationError;

/**
* @param {*} value
* @returns {String} `typeof` result extended with 'array', 'regexp', 'date' and 'error'
*/
function typeOf(value) {
var type = typeof value;
let type = typeof value;

if (type === 'object') {
if (util.isArray(value)) {
Expand All @@ -29,16 +29,15 @@ function typeOf(value) {
* @param {*} value
*/
function set(context, path, value) {
var ctx = context,
props = path.split('.'),
let ctx = context;

const props = path.split('.'),
target = props.pop(),
i, size,
propName,
type;
size = props.length;

for (i = 0, size = props.length; i < size; i++) {
propName = props[i];
type = typeOf(ctx[propName]);
for (let i = 0; i < size; i++) {
const propName = props[i];
const type = typeOf(ctx[propName]);

if (type === 'undefined') {
ctx[propName] = {};
Expand Down Expand Up @@ -66,12 +65,12 @@ function get(context, path, defaultValue) {
return context;
}

var props = path.split('.'),
prop = props[0],
i, size,
ctx = context;
const props = path.split('.'),
size = props.length;

let ctx = context;

for (i = 0, size = props.length; i < size; prop = props[++i]) {
for (let i = 0, prop = props[0]; i < size; prop = props[++i]) {
if (typeof ctx === 'undefined' || ctx === null ||
! Object.prototype.hasOwnProperty.call(ctx, prop)) {
return defaultValue;
Expand All @@ -93,12 +92,12 @@ function has(context, path) {
return context;
}

var props = path.split('.'),
prop = props[0],
i, size,
ctx = context;
const props = path.split('.'),
size = props.length;

let ctx = context;

for (i = 0, size = props.length; i < size; prop = props[++i]) {
for (let i = 0, prop = props[0]; i < size; prop = props[++i]) {
if (typeof ctx === 'undefined' || ctx === null ||
! Object.prototype.hasOwnProperty.call(ctx, prop)) {
return false;
Expand Down
17 changes: 8 additions & 9 deletions lib/configuration/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var path = require('path'),
const path = require('path'),
typeOf = require('./helpers').typeOf,
get = require('./helpers').get,
set = require('./helpers').set,
Expand Down Expand Up @@ -48,7 +48,7 @@ Configuration.prototype.has = function(path) {
* @public
*/
Configuration.prototype.getKeys = function(path) {
var obj = get(this, path);
const obj = get(this, path);

if (typeOf(obj) !== 'object') {
return [];
Expand Down Expand Up @@ -133,16 +133,14 @@ Configuration.applyEnvironment = function(config) {
}

function parseProp(prop) {
var delimeterPos = prop.indexOf('='),
propPath,
propValue;
const delimeterPos = prop.indexOf('=');

if (delimeterPos === 0 || delimeterPos === -1) {
return;
}

propPath = prop.substr(0, delimeterPos).trim();
propValue = prop.substr(delimeterPos + 1).trim();
const propPath = prop.substr(0, delimeterPos).trim();
let propValue = prop.substr(delimeterPos + 1).trim();

if (propValue === '') {
propValue = undefined;
Expand All @@ -158,8 +156,9 @@ Configuration.applyEnvironment = function(config) {
set(config, propPath, propValue);
}

var conf = process.env.LUSTER_CONF,
lastSeparator = -1,
const conf = process.env.LUSTER_CONF;

let lastSeparator = -1,
i = 0,
openQuote = false;

Expand Down
4 changes: 2 additions & 2 deletions lib/errors.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var Terror = require('terror'),
const Terror = require('terror'),
errors = {};

/**
* @constructor
* @class LusterError
* @augments Terror
*/
var LusterError = errors.LusterError = Terror.create('LusterError',
const LusterError = errors.LusterError = Terror.create('LusterError',
{
ABSTRACT_METHOD_IS_NOT_IMPLEMENTED:
'Abstract method "%method%" is not implemented in the %klass%'
Expand Down
4 changes: 2 additions & 2 deletions lib/event_emitter_ex.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Objex = require('objex'),
const Objex = require('objex'),
util = require('util'),
EventEmitter = require('events').EventEmitter,

Expand All @@ -17,7 +17,7 @@ function inspect(val) {
// add 'luster:eex' to the `NODE_DEBUG` environment variable to enable events logging
if (process.env.NODE_DEBUG && /luster:eex/i.test(process.env.NODE_DEBUG)) {
EventEmitterEx.prototype.emit = function() {
var args = Array.prototype
const args = Array.prototype
.slice.call(arguments, 0)
.map(inspect);

Expand Down
2 changes: 1 addition & 1 deletion lib/luster.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var cluster = require('cluster'),
const cluster = require('cluster'),
/** @type {ClusterProcess} */
Proc = require(cluster.isMaster ? './master' : './worker');

Expand Down
Loading

0 comments on commit 19adae5

Please sign in to comment.