Refactor (public/src/modules/translator.common.js): reduce nesting in Translator.prototype.translate() #140
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
Link to the associated GitHub issue:
#138
Full path to the refactored file:
public/src/modules/translator.common.js
What do you think this file does?
I think it is related to setting up the page for the client side, since it is called whenever a new page is open. More specifically I believe the file handles Translation instructions.
What is the scope of your refactoring within that file?
I refactored the Translator.prototype.translate() function's main while loop for when it arrives to the end of the string.
Which Qlty‑reported issue did you address?
Deeply nested control flow (level = 5) in Translator.prototype.translate().
2. Refactoring
How did the specific issue you chose impact the codebase’s maintainability?
What changes did you make to resolve the issue?
I moved the the nested logic that was within while loops and if/else statements into an outside function called parseToken.
How do your changes improve maintainability? Did you consider alternatives?
By creating an outside helper function it is easier to test parts individually, it reduces indentation improving readability of the code, and separates the parts of the code to making it easier to test one functionality. My thought for alternatives was making the nested if else statement into one, but felt it would make the code seem more complicated and not as elegant as using a helper function.
3. Validation
How did you trigger the refactored code path from the UI?
I opened different pages by clicking the buttons on the lefthand side to access recent, tags, popular etc and other buttons that changed the page.
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.