Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored code in src/notifications.js to reduce cognitive complexity #167

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ajain-1
Copy link

@ajain-1 ajain-1 commented Jan 23, 2025

Resolves #9

Refactored code in src/notifications.js to reduce cognitive complexity by initially un-nesting the code in the foreach loop at line 87. I did this by returning within the loop if notification is null. I also used optional chaining in other parts of the file to resolve some other SonarCloud errors for this file. This is an initial attempt at solving all warnings for this file, and I'll add more commits as necessary.

notification.datetimeISO = utils.toISOString(notification.datetime);
if (!notification) {
return;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return reduces the complexity of this nested forEach by removing one branch.

notifications = mergeIds.reduce((notifications, mergeId) => {
notifications = mergeIds.reduce(notificationsReducer, notifications);

function notificationsReducer(notifications, mergeId) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduced nesting by making designated functions to reduce the notifications and also to iterate through the differentiators below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactoring code in src/notifications.js to reduce cognitive complexity
1 participant