opencost
opencost copied to clipboard
Remove redundant `len` and `nil` check before loop
What does this PR change?
From the Go specification (https://go.dev/ref/spec#For_range):
"1. For a nil slice, the number of iterations is 0." "3. If the map is nil, the number of iterations is 0."
len
returns 0 if the slice or map is nil (https://pkg.go.dev/builtin#len). Therefore, having these checks before a loop is unnecessary:
-
len(v) != 0
-
len(v) > 0
-
v != nil
Does this PR relate to any other PRs?
No.
How will this PR impact users?
No user-facing change.
Does this PR address any GitHub or Zendesk issues?
How was this PR tested?
go build ./...
and go test ./...
Does this PR require changes to documentation?
No.
Have you labeled this PR and its corresponding Issue as "next release" if it should be part of the next OpenCost release? If not, why not?
No. External contributor cannot label PR.
Thank you for this PR. I suspect these hooks were left in the code to quickly add an
else { // log error }
since many of these seem to imply exceptional cases except for this https://github.com/opencost/opencost/pull/2184/files#diff-084f229ce009968d50ab3e5cbeb8ff6f42eb0fd08fdc7b9d027f6931d47ea483R1765
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
opencost | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | May 7, 2024 2:15am |
@cliffcolvin Friendly ping :smiley:
Hey @Juneezee I think we'd rather log something about these values being nil in an else clause, as I mentioned earlier, than drop the if altogether since these cases feel exceptional.
Quality Gate passed
Kudos, no new issues were introduced!
0 New issues
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
This pull request has been marked as stale because it has been open for 90 days with no activity. Please remove the stale label or comment or this pull request will be closed in 5 days.
@AjayTripathy do you want to take a quick look?
This pull request has been marked as stale because it has been open for 90 days with no activity. Please remove the stale label or comment or this pull request will be closed in 5 days.
This pull request was closed because it has been inactive for 95 days with no activity.