Skip to content

Refactor(src/user/profile.js): reduce complexity in changePassword#186

Open
connorcarpenter15 wants to merge 2 commits intoCMU-313:mainfrom
connorcarpenter15:reduce-profile-complexity
Open

Refactor(src/user/profile.js): reduce complexity in changePassword#186
connorcarpenter15 wants to merge 2 commits intoCMU-313:mainfrom
connorcarpenter15:reduce-profile-complexity

Conversation

@connorcarpenter15
Copy link

P1B: Starter Task: Refactoring PR

1. Issue

Link to the associated GitHub issue: #185

Full path to the refactored file: src/user/profile.js

What do you think this file does?
(Your answer does not have to be 100% correct; give a reasonable, evidence‑based guess.)
This file implements functionality for interacting with user objects, such as validating attributes (i.e. birthday, email), updating profile information (i.e. username, email), and changing passwords.

What is the scope of your refactoring within that file?
(Name specific functions/blocks/regions touched.)
The scope of this refactoring involved the User.changePassword function, specifically the validation logic at the start of the function.

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 high complexity (count = 10)

2. Refactoring

How did the specific issue you chose impact the codebase’s maintainability?
The incorporation of extensive validation logic within the User.changePassword function itself decreases readability and understanding of the main purpose of the function, making it harder to debug and modify.

What changes did you make to resolve the issue?
I separated the validation logic into a helper function.

How do your changes improve maintainability? Did you consider alternatives?
Separating this logic into a helper function increases modularity and makes it easier to debug and modify this function in the future. This is the most straightforward and widely-used method for this use case, so no alternatives were considered.

3. Validation

How did you trigger the refactored code path from the UI?
I navigated to the user profile settings, selected to change password, and inputted a new password in the given fields.

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.)
Screenshot 2026-01-28 at 12 01 18 PM
Screenshot 2026-01-28 at 12 01 28 PM

Attach a screenshot of qlty smells --no-snippets <full/path/to/file.js> showing fewer reported issues after the changes.
Screenshot 2026-01-28 at 12 05 03 PM

Reduce the complexity of the `User.changePassword` function by
consolidating validation logic in the helper function
`validatePasswordRequest`.
Auto-formatter changed parens and spacing. Revert back to previous
formatting for linter.
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.

1 participant

Comments