Refactor (packages/desktop/src/main/sidecar.ts): Function with many returns - #46
Open
ammarri14 wants to merge 5 commits into
Open
Refactor (packages/desktop/src/main/sidecar.ts): Function with many returns#46ammarri14 wants to merge 5 commits into
ammarri14 wants to merge 5 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue for this PR
Closes #44
Type of change
What does this PR do?
Qlty flagged parseCommand in sidecar.ts:130 with 8 returns
Collapsed four typeof guards into own combined condition which made it gofrom 8 returns to 5 which cleared the smell
Moved the function into a new sidecar-command.ts.
Because sidecar.ts runs electron code as soon as it is imported which fails outside he app hence a test couldn't import it
sidecar.ts imports parseCommand from the new module
How did you verify your code works?
Added sidecar-command.test.ts, it had 7 tests and 17 assertions
They cover parseCommand when input is not an object, the stop command, an unknown command type, the four required fields missing, each field with the wrong type, and a valid start command.
100% function and line coverage on the sidecar-command.ts file
it had 59 pass and 0 fail, it was 52 before. The 52 that already existed still pass, which shows that nothing broke.
bunx tsc --noEmit is clean for both
Qlty before and after code blocks:
Before
After
The 698 warning and 2 errors from bun lint are already in other packages not from the change and neither sidecar file shows any lint output.
Added a CI test task for the desktop package. I pointed it at my test file because another test in that folder was already broken on CI.
Screenshots / recordings
Checklist
If you do not follow this template your PR will be automatically rejected.