Skip to content

Conversation

@sandervonk
Copy link

@sandervonk sandervonk commented Jan 24, 2026

P1B: Starter Task: Refactoring PR

1. Issue

Link to the associated GitHub issue: #38

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

What do you think this file does?
I think this file handles backend behaviors for the user profile pages, especially the behavior for editing a user profile and/or changing its username, etc.

What is the scope of your refactoring within that file?
My changes are contained/pertinent to function isUsernameAvailable, which gained helper functions validateUsernameFormat and checkUsernameUniqueness.

Which Qlty‑reported issue did you address?
Cognitive Complexity 12 in isUsernameAvailable().

2. Refactoring

How did the specific issue you chose impact the codebase’s maintainability?
By splitting off some of the username checking functionality into helper functions, it is now more atomic and can be extended and modified in a way that is much more understandable. With the introduction of smaller chunks of logic, the code is essentially more human-readable and is unlikely to create confusion for future maintainers, as well as being more accessible for bugfixing.

What changes did you make to resolve the issue?
I moved much of the if-then logic of isUsernameAvailable to more understandable and standalone helper functions: validateUsernameFormat and checkUsernameUniqueness, which handle erroring and other logic that previously was all incapsulated in the high-complexity function.

How do your changes improve maintainability? Did you consider alternatives?
My changes improve maintainability by making the code more readable, consistent, and equally sized. I considered other approaches that could've helped with these factors, such as a case/switch, but found that they wouldn't be appropriate for reducing the complexity, and having the one large function was the main issue with maintainability at play.

3. Validation

How did you trigger the refactored code path from the UI?
I triggered the refactored code from the UI by going to the user/{currentUsername}/edit/username URL and typing in usernames (that existed, had other errors, etc), before clicking out of the input to trigger the username check phase. Doing so shows

Attach a screenshot of the logs and UI demonstrating the trigger.

Image Image

Image

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

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