feat: [#702] apply fieldalignment & modernize fixes#1096
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR applies automated refactors using fieldalignment and modernize to improve code consistency and leverage newer Go features.
- Optimized struct field ordering for better memory layout.
- Replaced
interface{}withanyand manual loops withslices.Contains,maps.Copy, andfmt.Appendf. - Simplified min/max logic and classic
for i := 0; i < n; i++loops using modern patterns.
Reviewed Changes
Copilot reviewed 86 out of 86 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| support/process/utils.go | Replaced classic loop with for range 60. |
| foundation/application.go | Replaced classic loop with for range 50. |
| database/db/utils.go | Replaced for i := 0; i < length; i++ with for i := range length. |
| cache/memory_test.go | Updated two for i := 0; i < 1000; i++ loops to for range 1000. |
| console/cli_helper.go | Replaced manual loop bounds with for index := range lenShared. |
Comments suppressed due to low confidence (6)
support/process/utils.go:26
- In Go, you cannot
for rangeover an integer literal. You should restore an index-based loop, e.g.,for i := 0; i < 60; i++ {.
for range 60 {
foundation/application.go:312
- Ranging over an integer is invalid. Change back to a traditional loop or iterate over a slice:
for i := 0; i < 50; i++ {.
for range 50 {
database/db/utils.go:50
- You cannot use
rangeon an integer. Keepfor i := 0; i < length; i++ {or range over a slice of that length.
for i := range length {
cache/memory_test.go:75
for rangecannot iterate an integer. Revert tofor i := 0; i < 1000; i++ {for correct iteration.
for range 1000 {
cache/memory_test.go:183
- Invalid
for rangeover an int. Use a conventional loop:for i := 0; i < 1000; i++ {.
for range 1000 {
console/cli_helper.go:237
- Cannot range over an int value. Either keep the original index loop or range over a slice/string:
for index := 0; index < lenShared; index++ {.
for index := range lenShared {
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1096 +/- ##
==========================================
+ Coverage 71.09% 71.16% +0.06%
==========================================
Files 183 183
Lines 12854 12826 -28
==========================================
- Hits 9138 9127 -11
+ Misses 3345 3330 -15
+ Partials 371 369 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
hwbrzzl
left a comment
There was a problem hiding this comment.
Great PR 👍 Is there a script or github action to format files automatically?
It’s not easy to create a fully automated script for this, unfortunately. The Because of that, it’s more practical to run these optimizations periodically—such as before major releases—rather than on every commit. |
| type ResponseImpl struct { | ||
| allowed bool | ||
| message string | ||
| allowed bool |
There was a problem hiding this comment.
Could you add the sort rule to the PR description?
📑 Description
Closes goravel/goravel#702
This PR includes automated refactors applied via
fieldalignmentandmodernizeto improve code quality and consistency:efaceany: replacedinterface{}with Go 1.18+anyminmax: simplifiedif-elseassignments to built-inmin/maxrangeint: converted classicfor i := 0; i < n; i++loops tofor i := range nfmtappendf,mapsloop,slicescontains: applied equivalent modernizations✅ Checks