Refactor (packages/opencode/src/util/repository.ts:139): Function with many returns (count = 8): parseRepositoryReference - #176
Open
Wl1u4 wants to merge 7 commits into
Open
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.
Closes #171
Closes #
Type of change
What does this PR do?
Fixes #171. Qlty flagged
parseRepositoryReferencein packages/opencode/src/util/repository.ts for having too many return statements (8). The func try several parsing strats in a row: GitHub shorthand like "owner/repo", "github:owner/repo" prefix, SCP-style git URLs, direct host/path, and full URLs. returning as soon as one matches.I pulled each strategy out into its own small func (matchGithubPrefixed, matchScpStyle, matchDirectHostPath, matchGithubShorthand, matchUrl), put them in an array, and looped through them, returning the first non null result. This keeps exact same order and fallback behavior as before, but main func now only has 2 return statements instead of 8, and each strategy is easier to read/test on its own.
If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!
How did you verify your code works?
Ran
qlty smellsbefore and after. the "many returns" warning is gone and no new smells were introduced.Ran existing test suite (test/util/repository.test.ts) all 6 tests still pass with no changes needed.
Also ran the full test suite (bun test --coverage) to make sure nothing else broke: 3254 pass, 4 fail (those 4 failures are pre exisitng ones and unrelated to this file).
Checked coverage on the changed file specifically
and confirmed the few uncovered lines
Also ran
bun run typecheckwith no errors.Checklist
If you do not follow this template your PR will be automatically rejected.