Refactor getRecentTopics (reduce params) + add test coverage #256
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
Please provide a link to the associated GitHub issue:
**Link to the associated GitHub issue: **
#14
Full path to the refactored file:
src/topics/recent.js
What do you think this file does?
It handles the functionality of NodeBB's, fetching the most recent topics and display them.
What is the scope of your refactoring within that file?
refactored the getRecentTopics function in recent.js to reduce its number of parameters by passing a single options object. This involved updating the function definition and all calls to it within the file to use the new object-based parameter.
Which Qlty‑reported issue did you address?
Function with many parameters (count = 5): getRecentTopics
2. Refactoring
How did the specific issue you chose impact the codebase’s adaptability?
Because adding or altering parameters required updating the function and all of its callers, it restricted adaptability and made code maintenance more difficult.
What changes did you make to resolve the issue?
I refactored the getRecentTopics function to accept a single options object instead of multiple parameters and updated all calls accordingly.
How do your changes improve adaptability? Did you consider alternatives?
Although I thought about keeping numerous parameters, it is more manageable and scalable to use a single options object. The changes also increase adaptability by enabling the addition of new options without altering the function signature.
3. Validation
How did you trigger the refactored code path from the UI?
The function is not reachable via the UI, so I triggered it by writing a dedicated unit test in test/topics.js.
Attach a screenshot of the logs and UI demonstrating the trigger.
(Run
./nodebb log; include the relevant UI view. Temporary logs should be removed before final commit.)Untitled.pdf
Attach a screenshot of
qlty smells --no-snippets <full/path/to/file.js>showing fewer reported issues after the changes.Before:
Untitled 3.pdf
After:
Untitled 2.pdf