P1B: Refactor (<src/posts/topics.js:9>): Function with many parameters (count = 5): getPostsFromSet #299
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.
Link to the associated GitHub issue:
#298
Full path to the refactored file:
src/posts/topics.js
What do you think this file does?
This file has some helper functions to help get posts from a set, filter users that are blockec, etc. Generally, this file just helps to manage post data.
What is the scope of your refactoring within that file?
The scope of my refactoring was the getPostsFromSet function. My task was to decrease the number of parameters. How I did this was by working backwards. I had an opts object instead of all of the parameters. This way, you cna just extract whatever parameter you need without having them there in the parameter area of the function, which keeps the function very clean and manageable.
Which Qlty‑reported issue did you address?
Function with many parameters (count = 5): getPostsFromSet
How did the specific issue you chose impact the codebase’s adaptability?
Since there were many parameters in the function initially, it made the code very hard to maintain. This is because, everutime a parameter was needed, all of the calls to the function had to be updated (since they were all parameters). This increased the chances of errors occuring and made it harder to make changes to the code in the future.
What changes did you make to resolve the issue?
I refactored the code to take in an opts object instead of all of the parameters. This makes for the parameters to be passed flexibly, but still holding similar structure to the initial function. I also added validation for the UID to make sure that no errors occur if it is not inputed/not correct.
How do your changes improve adaptability? Did you consider alternatives?
The changes improved adaptability by letting new parameters to be added without changing the function completely or breaking existing calls. It also makes the code easier to read and maintain. I didn't consider any alternative approaches.
How did you trigger the refactored code path from the UI?
I triggered the refactored getPostsFromSet code from the UI whenever a user loaded a bunch of posts, like viewing a topic, scrolling through a feed, or navigating to a page with post listings. In this case, I viewed a bunch of replies to a post that I made.
Attach a screenshot of the logs and UI demonstrating the trigger.


Attach a screenshot of qlty smells --no-snippets <full/path/to/file.js> showing fewer reported issues after the changes.

