Skip to content

Commit

Permalink
Refactored: JavaScript Standard Style (#292)
Browse files Browse the repository at this point in the history
* Fix to use '===' instead of '==' (Including similar modifications)

* Fix using strings for single quotes

* Fix using let

Fix for not being careful with `VARIABLE is already defined`
in JavaScript Standard Style

* Add space and format the code

Fix to prevent the message like the following from being displayed
- Missing space before function parentheses.
- Missing space before opening brace.
  • Loading branch information
abetomo authored and DeviaVir committed May 23, 2017
1 parent 2254ae1 commit 86949dd
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 74 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// For development/testing purposes
exports.handler = function(event, context, callback) {
exports.handler = function (event, context, callback) {
console.log('Running index.handler');
console.log('==================================');
console.log('event', event);
Expand Down
60 changes: 30 additions & 30 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Lambda.prototype._runHandler = function (handler, event, program, context) {
};

if (['nodejs4.3', 'nodejs6.10'].indexOf(program.runtime) === -1) {
console.error("Runtime [" + program.runtime + "] is not supported.");
console.error(`Runtime [${program.runtime}] is not supported.`);
process.exit(254);
}
handler(event, context, callback);
Expand Down Expand Up @@ -159,7 +159,7 @@ Lambda.prototype._eventSourceList = function (program) {
ScheduleEvents: null
};
}
const list = (function() {
const list = (function () {
try {
return fs.readJsonSync(program.eventSourceFile);
} catch(err) {
Expand Down Expand Up @@ -317,9 +317,9 @@ Lambda.prototype._postInstallScript = function (program, codeDirectory, callback
maxBuffer: maxBufferSize
}, function (error, stdout, stderr) {
if (error) {
return callback(error + " stdout: " + stdout + " stderr: " + stderr);
return callback(error + ' stdout: ' + stdout + ' stderr: ' + stderr);
}
console.log("\t\t" + stdout);
console.log('\t\t' + stdout);
callback(null);
});
};
Expand Down Expand Up @@ -369,7 +369,7 @@ Lambda.prototype._setRunTimeEnvironmentVars = function (program) {
var configValues = fs.readFileSync(program.configFile);
var config = dotenv.parse(configValues);

for (var k in config) {
for (let k in config) {
if (!config.hasOwnProperty(k)) {
continue;
}
Expand Down Expand Up @@ -537,9 +537,9 @@ Lambda.prototype._updateEventSources = function (lambda, functionName, existingE
}
var updateEventSourceList = [];
// Checking new and update event sources
for (var i in eventSourceList) {
var isExisting = false;
for (var j in existingEventSourceList) {
for (let i in eventSourceList) {
let isExisting = false;
for (let j in existingEventSourceList) {
if (eventSourceList[i]['EventSourceArn'] === existingEventSourceList[j]['EventSourceArn']) {
isExisting = true;
updateEventSourceList.push({
Expand Down Expand Up @@ -567,9 +567,9 @@ Lambda.prototype._updateEventSources = function (lambda, functionName, existingE
}

// Checking delete event sources
for (var i in existingEventSourceList) {
var isExisting = false;
for (var j in eventSourceList) {
for (let i in existingEventSourceList) {
let isExisting = false;
for (let j in eventSourceList) {
if (eventSourceList[j]['EventSourceArn'] === existingEventSourceList[i]['EventSourceArn']) {
isExisting = true;
break;
Expand Down Expand Up @@ -606,7 +606,7 @@ Lambda.prototype._updateEventSources = function (lambda, functionName, existingE
});
break;
}
}, function(err, results) {
}, function (err, results) {
return cb(err, results);
});
};
Expand All @@ -615,16 +615,16 @@ Lambda.prototype._updateScheduleEvents = function (scheduleEvents, functionArn,
if (scheduleList == null) {
return cb(null, []);
}
return async.series(scheduleList.map(function(schedule) {
return function(_cb) {
return async.series(scheduleList.map(function (schedule) {
return function (_cb) {
const params = Object.assign(schedule, { FunctionArn: functionArn });
scheduleEvents.add(params).then(function (data) {
_cb(null, params);
}).catch(function (err) {
_cb(err);
});
};
}), function(err, results) {
}), function (err, results) {
cb(err, results);
});
};
Expand Down Expand Up @@ -718,26 +718,26 @@ Lambda.prototype.deploy = function (program) {
}, function (err) {
if (err) {
// Function does not exist
return _this._uploadNew(lambda, params, function(err, results) {
return _this._uploadNew(lambda, params, function (err, results) {
if (err) {
throw err;
}
console.log('=> Zip file(s) done uploading. Results follow: ');
console.log(results);

async.parallel([
function(_callback) {
function (_callback) {
// Updating event source(s)
_this._updateEventSources(lambda, params.FunctionName, [], eventSourceList.EventSourceMappings, function(err, results) {
_this._updateEventSources(lambda, params.FunctionName, [], eventSourceList.EventSourceMappings, function (err, results) {
_callback(null, results);
});
},
function(_callback) {
_this._updateScheduleEvents(scheduleEvents, results.FunctionArn, eventSourceList.ScheduleEvents, function(err, results) {
function (_callback) {
_this._updateScheduleEvents(scheduleEvents, results.FunctionArn, eventSourceList.ScheduleEvents, function (err, results) {
_callback(err, results);
});
}
], function(err, results) {
], function (err, results) {
cb(err, results);
});
});
Expand All @@ -746,29 +746,29 @@ Lambda.prototype.deploy = function (program) {
// Function exists
_this._listEventSourceMappings(lambda, {
'FunctionName': params.FunctionName
}, function(err, existingEventSourceList) {
}, function (err, existingEventSourceList) {
if (err) {
throw err;
}
return async.parallel([
function(_callback) {
_this._uploadExisting(lambda, params, function(err, results) {
function (_callback) {
_this._uploadExisting(lambda, params, function (err, results) {
if (err) {
throw err;
}
console.log('=> Zip file(s) done uploading. Results follow: ');
console.log(results);
_this._updateScheduleEvents(scheduleEvents, results.FunctionArn, eventSourceList.ScheduleEvents, function(err, results) {
_this._updateScheduleEvents(scheduleEvents, results.FunctionArn, eventSourceList.ScheduleEvents, function (err, results) {
_callback(err, results);
});
});
},
function(_callback) {
_this._updateEventSources(lambda, params.FunctionName, existingEventSourceList, eventSourceList.EventSourceMappings, function(err, results) {
function (_callback) {
_this._updateEventSources(lambda, params.FunctionName, existingEventSourceList, eventSourceList.EventSourceMappings, function (err, results) {
_callback(err, results);
});
}
], function(err, results) {
], function (err, results) {
cb(err, results);
});
});
Expand All @@ -777,8 +777,8 @@ Lambda.prototype.deploy = function (program) {
if (err) {
throw err;
}
const resultsIsEmpty = results.filter(function(result) {
return result.filter(function(res) {
const resultsIsEmpty = results.filter(function (result) {
return result.filter(function (res) {
return res.length > 0;
}).length > 0;
}).length === 0;
Expand Down
16 changes: 8 additions & 8 deletions lib/schedule_events.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const ScheduleEvents = function(aws) {
const ScheduleEvents = function (aws) {
// Authenticated `aws` object in `lib/main.js`
this.lambda = new aws.Lambda({
apiVersion: '2015-03-31'
Expand All @@ -23,7 +23,7 @@ ScheduleEvents.prototype = {
return params.FunctionArn.split(':').pop();
},

_putRulePrams: function(params) {
_putRulePrams: function (params) {
return {
Name: params.ScheduleName,
Description: this._ruleDescription(params),
Expand All @@ -32,7 +32,7 @@ ScheduleEvents.prototype = {
};
},

_putRule: function(params) {
_putRule: function (params) {
const _this = this;
// return RuleArn if created
return new Promise((resolve) => {
Expand All @@ -44,7 +44,7 @@ ScheduleEvents.prototype = {
});
},

_addPermissionParams: function(params) {
_addPermissionParams: function (params) {
return {
Action: 'lambda:InvokeFunction',
FunctionName: this._functionName(params),
Expand All @@ -54,7 +54,7 @@ ScheduleEvents.prototype = {
};
},

_addPermission: function(params) {
_addPermission: function (params) {
const _this = this;
return new Promise((resolve) => {
const _params = _this._addPermissionParams(params);
Expand All @@ -69,7 +69,7 @@ ScheduleEvents.prototype = {
});
},

_putTargetsParams: function(params) {
_putTargetsParams: function (params) {
return {
Rule: params.ScheduleName,
Targets: [{
Expand All @@ -79,7 +79,7 @@ ScheduleEvents.prototype = {
};
},

_putTargets: function(params) {
_putTargets: function (params) {
const _this = this;
return new Promise((resolve) => {
const _params = _this._putTargetsParams(params);
Expand All @@ -91,7 +91,7 @@ ScheduleEvents.prototype = {
});
},

add: function(params) {
add: function (params) {
const _this = this;
return Promise.resolve().then(() => {
return _this._putRule(params);
Expand Down
Loading

0 comments on commit 86949dd

Please sign in to comment.