Remove naked return values from `ReadBranchConfig` and `prSelectorForCurrentBranch` by jtmcg · Pull Request #10197 · cli/cli
Motivation
After some discussion with @williammartin, we agreed that the naked return values pattern is something that we'd like to avoid in our codebase and that we should make an effort to remove them when we encounter them. This is the PR to remove the named return values from ReadBranchConfig that I encountered while working through #10188.
I also refactored ReadBranchConfig for two reasons: to surface the previously hidden errors it could produce and to allow for better test coverage of its core functionality. I did the latter by separating out the git call and the BranchConfig struct creation into their own functions to leverage dependency injection of the git call's return value into the BranchConfig creation.
While making this refactor work with the rest of the tool, I stumbled upon more named return values in prSelectorForCurrentBranch and decided to remove these as well. This resulted in a slight reorganization of the function in a way that I believe makes it easier to follow.
Changes
- Remove named returns from ReadBranchConfig and surface errors
- Refactor ReadBranchConfig for test coverage of newly returned erros
- Remove named return values from prSelectorForCurrentBranch
Testing
I haven't touched any of the original tests besides accommodating the new ReadBranchConfig api, and they are all passing, so I'm decently confident that this won't introduce any breaking changes. However, to exercise all the changes, follow these steps:
- Pull down the branch
gh pr checkout 10197 - Build the branch
- Execute the
gh pr statuscommand