Skip to content

Commit

Permalink
refactoring code to combine if statements and reduce cognitive load
Browse files Browse the repository at this point in the history
  • Loading branch information
khiyami authored and khiyami committed Sep 5, 2024
1 parent 09ad0fe commit 2931f05
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/socket.io/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ function deserializePayload(payload) {
async function onMessage(socket, payload) {
const { event, params, callback } = payload;
try {
// combine if statements to reduce cognitive load
if (!event) {
return winston.warn('[socket.io] Empty method name');
}
Expand All @@ -166,7 +167,7 @@ async function onMessage(socket, payload) {
const escapedName = validator.escape(typeof event);
return callback({ message: `[[error:invalid-event, ${escapedName}]]` });
}

Check failure on line 170 in src/socket.io/index.js

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed
const parts = event.split('.');
const namespace = parts[0];
const methodToCall = parts.reduce((prev, cur) => {
Expand Down

0 comments on commit 2931f05

Please sign in to comment.