Refactor (src/user/blocks.js): reduce number of parameters in User.blocks.can() #129
+2
−789
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
P1B: Starter Task: Refactoring PR
1. Issue
Link to the associated GitHub issue:
https://github.com/CMU-313/NodeBB/issues/20#issue-3825901640
Full path to the refactored file:
/workspaces/NodeBB/src/user/blocks.js
What do you think this file does?
This file manages the interaction with multiple users by giving them the ability to block other users if they choose to do so.
What is the scope of your refactoring within that file?
(Name specific functions/blocks/regions touched.)
User.blocks.can
Which Qlty‑reported issue did you address?
(Name the rule/metric and include the BEFORE value; e.g., “Cognitive Complexity 18 in render()”.)
Function with many parameters (count = 4)
2. Refactoring
How did the specific issue you chose impact the codebase’s maintainability?
This specific issue impacted the maintainability by having to many redundant parameters. It is not good practice since it can cause mismatch orders, the caller can accidentally put it in the wrong order and in general its hard to read.
What changes did you make to resolve the issue?
To resolve this issue, instead of making it so that the caller changes, I captured all the arguments as one variable as an array so that it can be organized. I made it so that the array was a list and was able to parse each element out of it so that we don't have 4 arguments passed into the function, but instead just one.
How do your changes improve maintainability? Did you consider alternatives?
The changes I made allow the usage of more parameters If we ever want to increase the arguments in the function the caller can add more and it won't break anything, it makes it more adaptable to changes. As an alternative, I considered changing the caller but I was unsure how many calls there could be in all the files that could possibly be calling the function.
3. Validation
How did you trigger the refactored code path from the UI?

I was not able to do this, since I was having a gui error and could not display or use the block button.
Attach a screenshot of the logs and UI demonstrating the trigger.
(If you refactored a public/src/ file (front-end related file), watch logging via DevTools (Ctrl+Shift+I to open and then navigate to the 'Console' tab). If you refactored a src/ file, watch logging via ./nodebb log. Include the relevant UI view. Temporary logs should be removed before final commit.)
Attach a screenshot of

qlty smells --no-snippets <full/path/to/file.js>showing fewer reported issues after the changes.NOTE: Regarding Test Coverage Report below
The drop in overall coverage is due to socket.io.js being commented out. This was necessary because, when included before and after the change, the file was causing the build and tests to fail across all categories in both instances.
I discussed this issue with Professor Hilton, and he instructed me to document the cause here and note that the relevant changes remain tested. Despite the overall decrease, 100% of the lines changed and added in this PR are covered.