🧹 chore: add prefixes to unexported boolean fields#4300
Conversation
…elds Rename unexported boolean struct fields to follow Go naming conventions where booleans should read as true/false questions using is/has/can/should prefixes. Changes: - routesRefreshed -> hasRoutesRefreshed - matched -> isMatched - skipNonUseRoutes -> shouldSkipNonUseRoutes - anyRouteDefined -> hasAnyRoute - dontHandleErrs -> shouldSkipErrHandling - skipValidation -> shouldSkipValidation - disablePathNormalizing -> isPathNormalizingDisabled - debug -> isDebug - hostOnly -> isHostOnly - ok -> isOk - fresh -> isFresh - destroyed -> isDestroyed - closed -> isClosed - redactKeys -> shouldRedactKeys - enableColors -> areColorsEnabled - enableLatency -> isLatencyEnabled Closes gofiber#4298
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughThis PR renames unexported boolean struct fields across the codebase to use ChangesBoolean naming convention refactor
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request performs a large-scale refactoring to rename boolean fields across the core and middleware components, adopting clearer naming conventions with prefixes like is, has, should, and are. The review feedback suggests extending these renames to a few missed fields in the DefaultCtx struct for complete consistency. Additionally, it is recommended to revert a change to an error message string in the SSE middleware to avoid breaking changes and stay within the PR's intended scope.
| indexRoute int // Index of the current route | ||
| indexHandler int // Index of the current handler | ||
| methodInt int // HTTP method INT equivalent | ||
| abandoned atomic.Bool // If true, ctx won't be pooled until ForceRelease is called |
There was a problem hiding this comment.
| abandoned atomic.Bool // If true, ctx won't be pooled until ForceRelease is called | ||
| isMatched bool // Non use route matched | ||
| shouldSkipNonUseRoutes bool // Skip non-use routes while iterating middleware | ||
| userContextSet bool // User context was stored in fasthttp user values |
| ) | ||
|
|
||
| var errStreamClosed = errors.New("sse: stream closed") | ||
| var errStreamClosed = errors.New("sse: stream is closed") |
There was a problem hiding this comment.
Changing the error message string from "sse: stream closed" to "sse: stream is closed" is out of scope for this PR, which focuses on renaming boolean fields. This change could potentially break users who rely on the exact error string for logging or logic, even if the error variable itself is unexported.
| var errStreamClosed = errors.New("sse: stream is closed") | |
| var errStreamClosed = errors.New("sse: stream closed") |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
client/cookiejar_test.go (1)
638-671: 💤 Low valueVariable names with
is*prefix should be reserved for booleans.The variables
isHostOnlyOriginandisHostOnlyCookieare a*fasthttp.URIand*fasthttp.Cookierespectively, not booleans. Theis*prefix conventionally signals a boolean type, making these names misleading.The original names
hostOnlyOriginandhostOnlyCookiewere appropriate compound nouns describing "the origin for a host-only cookie" and "a host-only cookie". The PR's scope is renaming boolean fields, not all occurrences ofhostOnlyin variable names.Suggested revert to original variable names
- isHostOnlyOrigin := fasthttp.AcquireURI() - defer fasthttp.ReleaseURI(isHostOnlyOrigin) - require.NoError(t, isHostOnlyOrigin.Parse(nil, []byte("http://example.com/"))) + hostOnlyOrigin := fasthttp.AcquireURI() + defer fasthttp.ReleaseURI(hostOnlyOrigin) + require.NoError(t, hostOnlyOrigin.Parse(nil, []byte("http://example.com/"))) domainOrigin := fasthttp.AcquireURI() defer fasthttp.ReleaseURI(domainOrigin) require.NoError(t, domainOrigin.Parse(nil, []byte("http://sub.example.com/"))) - isHostOnlyCookie := &fasthttp.Cookie{} - isHostOnlyCookie.SetKey("host-only") - isHostOnlyCookie.SetValue("123") + hostOnlyCookie := &fasthttp.Cookie{} + hostOnlyCookie.SetKey("host-only") + hostOnlyCookie.SetValue("123") domainCookie := &fasthttp.Cookie{} domainCookie.SetKey("domain") domainCookie.SetValue("456") domainCookie.SetDomain("example.com") for _, cookieType := range testCase.order { switch cookieType { case "host-only": - jar.Set(isHostOnlyOrigin, isHostOnlyCookie) + jar.Set(hostOnlyOrigin, hostOnlyCookie) case "domain": jar.Set(domainOrigin, domainCookie) default: t.Fatalf("unexpected cookie type %q", cookieType) } } anotherSubdomain := fasthttp.AcquireURI() defer fasthttp.ReleaseURI(anotherSubdomain) require.NoError(t, anotherSubdomain.Parse(nil, []byte("http://child.example.com/"))) require.Equal(t, []string{"domain"}, cookieKeys(jar.Get(anotherSubdomain))) - require.ElementsMatch(t, []string{"domain", "host-only"}, cookieKeys(jar.Get(isHostOnlyOrigin))) + require.ElementsMatch(t, []string{"domain", "host-only"}, cookieKeys(jar.Get(hostOnlyOrigin)))🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@client/cookiejar_test.go` around lines 638 - 671, The variable names isHostOnlyOrigin and isHostOnlyCookie use an "is*" prefix which implies a boolean but they are a *fasthttp.URI and *fasthttp.Cookie; rename them back to hostOnlyOrigin and hostOnlyCookie to reflect noun semantics and match the original intent; update all references in this test block (including the Set/Get calls on jar and the deferred ReleaseURI calls) so the names are consistent and avoid boolean-prefix confusion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@middleware/sse/sse.go`:
- Line 21: The sentinel error variable errStreamClosed was changed to use the
message "sse: stream is closed", which alters err.Error() and can break
downstream assertions/log parsing; revert the error text on the errStreamClosed
declaration back to its original message (restore the previous error string
literal) while keeping the variable name change (errStreamClosed) so only the
cosmetic rename remains and external behavior is preserved.
---
Nitpick comments:
In `@client/cookiejar_test.go`:
- Around line 638-671: The variable names isHostOnlyOrigin and isHostOnlyCookie
use an "is*" prefix which implies a boolean but they are a *fasthttp.URI and
*fasthttp.Cookie; rename them back to hostOnlyOrigin and hostOnlyCookie to
reflect noun semantics and match the original intent; update all references in
this test block (including the Set/Get calls on jar and the deferred ReleaseURI
calls) so the names are consistent and avoid boolean-prefix confusion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: afa8ad2f-7589-4c52-9ab3-89e931c48c74
📒 Files selected for processing (28)
app.gobind.gobind_test.goclient/client.goclient/client_test.goclient/cookiejar.goclient/cookiejar_test.goclient/hooks.goclient/request.goctx.godomain.gogroup.golog/default.golog/default_test.gomiddleware/cache/manager.gomiddleware/csrf/storage_manager.gomiddleware/limiter/manager.gomiddleware/logger/config.gomiddleware/logger/default_logger.gomiddleware/logger/logger.gomiddleware/logger/tags.gomiddleware/session/middleware.gomiddleware/session/session.gomiddleware/session/store.gomiddleware/sse/sse.gomount.gorouter.gorouter_test.go
| ) | ||
|
|
||
| var errStreamClosed = errors.New("sse: stream closed") | ||
| var errStreamClosed = errors.New("sse: stream is closed") |
There was a problem hiding this comment.
Avoid changing sentinel error text in a cosmetic rename PR.
Changing the message to "sse: stream is closed" introduces observable behavior drift (err.Error()) unrelated to the field rename objective. Keep the previous string to avoid downstream assertion/log parsing breakage.
Suggested fix
-var errStreamClosed = errors.New("sse: stream is closed")
+var errStreamClosed = errors.New("sse: stream closed")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| var errStreamClosed = errors.New("sse: stream is closed") | |
| var errStreamClosed = errors.New("sse: stream closed") |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@middleware/sse/sse.go` at line 21, The sentinel error variable
errStreamClosed was changed to use the message "sse: stream is closed", which
alters err.Error() and can break downstream assertions/log parsing; revert the
error text on the errStreamClosed declaration back to its original message
(restore the previous error string literal) while keeping the variable name
change (errStreamClosed) so only the cosmetic rename remains and external
behavior is preserved.
|
@pageton check the review comments |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4300 +/- ##
=======================================
Coverage 91.32% 91.32%
=======================================
Files 132 132
Lines 12933 12933
=======================================
Hits 11811 11811
Misses 708 708
Partials 414 414
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Rename abandoned -> isAbandoned (ctx.go) - Rename userContextSet -> isUserContextSet (ctx.go, ctx_test.go) - Revert error string to original (sse: stream closed) - Revert isHostOnlyOrigin/isHostOnlyCookie to hostOnlyOrigin/hostOnlyCookie (non-boolean variables, cookiejar_test.go)
|
@gaby all review comments addressed:
Ready for review. |
Summary
is,has,can,should, andare.Closes #4298
Checks
GOVERSION=go1.26.3 make auditGOVERSION=go1.26.3 make generateGOVERSION=go1.26.3 make betteralignGOVERSION=go1.26.3 make modernizeGOVERSION=go1.26.3 make formatGOVERSION=go1.26.3 make lintGOVERSION=go1.26.3 make test