Skip to content

Conversation

@zachikeh123
Copy link

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

@coveralls
Copy link

Pull Request Test Coverage Report for Build 17483248248

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 78.532%

Totals Coverage Status
Change from base Build 17435863312: 0.003%
Covered Lines: 24693
Relevant Lines: 29606

💛 - Coveralls

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.

2 participants