🧹 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 (1)
WalkthroughRenames many unexported boolean struct fields to use ChangesBoolean naming convention refactor
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 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 There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" 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.
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
|
@pageton check the review comments |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4300 +/- ##
==========================================
+ Coverage 91.35% 91.40% +0.05%
==========================================
Files 132 132
Lines 12977 12977
==========================================
+ Hits 11855 11862 +7
+ Misses 708 703 -5
+ Partials 414 412 -2
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. |
Fixes alignment of isUserContextSet field in DefaultCtx and indentation of c.isAbandoned.Store(false) in ForceRelease that were flagged by the gofmt linter in CI.
|
Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
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