eslint-plugin-stedi-aws-rules
eslint-plugin-stedi-aws-rules copied to clipboard
Prefer async handlers instead of callback based
Rule name
no-callback-handlers
Use case description
Callbacks are considered a bad pattern eventually leading to callback hell. Lambda functions should be written using async/await
style for better readability.
Examples
Incorrect
exports.handler = function(event, context, callback) {
let calculationResult = await calculate();
callback(null, calculationResult);
}
Correct
exports.handler = async (event) => {
let calculationResult = await calculate();
return calculationResult;
}
Might be useful to put a rule warning that context.callbackWaitsForEmptyEventLoop
doesn't work with async
, though