refactor(cmd/compose/run): remove redundant len check#11060
Merged
glours merged 1 commit intodocker:mainfrom Oct 23, 2023
Juneezee:refactor/redundant-len-check
Merged
refactor(cmd/compose/run): remove redundant len check#11060glours merged 1 commit intodocker:mainfrom Juneezee:refactor/redundant-len-check
len check#11060glours merged 1 commit intodocker:mainfrom
Juneezee:refactor/redundant-len-check
Conversation
Contributor
Author
ndeloof
approved these changes
Oct 23, 2023
From the Go specification [1]: "1. For a nil slice, the number of iterations is 0." `len` returns 0 if the slice is nil [2]. Therefore, checking `len(v) > 0` before a loop is unnecessary. [1]: https://go.dev/ref/spec#For_range [2]: https://pkg.go.dev/builtin#len Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
auto-merge was automatically disabled
October 23, 2023 08:18
Head branch was pushed to by a user without write access
Contributor
Author
|
@ndeloof Sorry for the back and forth. Please approve the workflow one more time and it should pass now. Thank you 🙏 |
glours
approved these changes
Oct 23, 2023
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.
What I did
Remove redundant
len(v) > 0checks indocker compose runcommand.From the Go specification (https://go.dev/ref/spec#For_range):
lenreturns 0 if the slice is nil (https://pkg.go.dev/builtin#len). Therefore, checkinglen(v) > 0before a loop is unnecessary.Also it is unnecessary to initialise
target.Ports = []types.ServicePortConfig{}.appendworks on nil slices (https://go.dev/tour/moretypes/15).Update existing test case for
docker compose run --publishand add a new test case fordocker compose run --service-portsto verify the documented behaviour.compose/docs/reference/compose_run.md
Lines 52 to 64 in a345515
Related issue
(not mandatory) A picture of a cute animal, if possible in relation to what you did