Skip to content

🧹 chore: add prefixes to unexported boolean fields#4300

Merged
ReneWerner87 merged 4 commits into
gofiber:mainfrom
pageton:style/unexported-bool-prefix
May 21, 2026
Merged

🧹 chore: add prefixes to unexported boolean fields#4300
ReneWerner87 merged 4 commits into
gofiber:mainfrom
pageton:style/unexported-bool-prefix

Conversation

@pageton

@pageton pageton commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Rename unexported boolean struct fields to use readable boolean prefixes such as is, has, can, should, and are.
  • Update internal references and tests to match the renamed fields.

Closes #4298

Checks

  • GOVERSION=go1.26.3 make audit
  • GOVERSION=go1.26.3 make generate
  • GOVERSION=go1.26.3 make betteralign
  • GOVERSION=go1.26.3 make modernize
  • GOVERSION=go1.26.3 make format
  • GOVERSION=go1.26.3 make lint
  • GOVERSION=go1.26.3 make test

…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
@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8faf41f6-943b-4962-9e4b-76565c20576f

📥 Commits

Reviewing files that changed from the base of the PR and between d7b8c48 and 5aeb997.

📒 Files selected for processing (1)
  • ctx.go

Walkthrough

Renames many unexported boolean struct fields to use is/has/should/are prefixes and updates all internal usages and tests; no public API changes.

Changes

Boolean naming convention refactor

Layer / File(s) Summary
Bind error-handling and validation control flag renames
bind.go, bind_test.go
dontHandleErrsshouldSkipErrHandling, skipValidationshouldSkipValidation; pool init, methods, validation, All(out), and tests updated.
Client core and hooks renames
client/client.go, client/hooks.go, client/client_test.go
debugisDebug, disablePathNormalizingisPathNormalizingDisabled; methods, hooks, Reset and tests updated.
Request path-normalizing rename
client/request.go
disablePathNormalizingisPathNormalizingDisabled; getter/setter and Reset updated.
Cookie jar host-only and acceptance renames
client/cookiejar.go, client/cookiejar_test.go
storedCookie.hostOnlyisHostOnly, cookieDomainAcceptance.ok/hostOnlyisOk/isHostOnly; filtering, SetByHost, parsing, acceptance helper, and tests updated.
App and context routing state renames
app.go, ctx.go, router.go, router_test.go, mount.go
routesRefreshedhasRoutesRefreshed, matchedisMatched, skipNonUseRoutesshouldSkipNonUseRoutes; routing, buildTree, mount, and tests updated.
Domain match caching and group tracking renames
domain.go, group.go
domainCheckResult.matchedisMatched, anyRouteDefinedhasAnyRoute; wrapHandlers and group registration updated.
Session lifecycle and middleware renames
middleware/session/session.go, middleware/session/middleware.go, middleware/session/store.go
freshisFresh, destroyedisDestroyed; session acquire/refresh/store and middleware pooling/destruction updated.
Logger middleware configuration renames
middleware/logger/config.go, middleware/logger/default_logger.go, middleware/logger/logger.go, middleware/logger/tags.go
enableColorsareColorsEnabled, enableLatencyisLatencyEnabled; config defaults, detection, and tag rendering updated.
Cache/CSRF/Limiter manager redaction renames
middleware/cache/manager.go, middleware/csrf/storage_manager.go, middleware/limiter/manager.go
redactKeysshouldRedactKeys; constructors, struct fields, and logKey checks updated.
SSE stream closure and logging retained-context renames
middleware/sse/sse.go, log/default.go, log/default_test.go
closedisClosed, okisOk; stream write/fail/close and retained-context rendering/tests updated.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • sixcolors
  • ReneWerner87
  • efectn

🐰 I hopped through code with nimble paws,
names now ask questions, no more because.
is, has, should, are — tidy and bright,
the repo nods, all fields read right. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 51.72% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: renaming unexported boolean fields to use consistent prefixes for improved readability.
Description check ✅ Passed The description provides a clear summary of changes, references the linked issue (#4298), and documents the test/build checks performed.
Linked Issues check ✅ Passed All code changes directly address the requirements in issue #4298: renaming ~24 unexported boolean fields across multiple files to use readable prefixes (is, has, should, are, can).
Out of Scope Changes check ✅ Passed All changes are in-scope: the pull request focuses exclusively on renaming unexported boolean fields and updating internal code/tests without introducing unrelated functionality or modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ReneWerner87 ReneWerner87 added this to v3 May 20, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone May 20, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread ctx.go Outdated
Comment thread ctx.go Outdated
Comment thread middleware/sse/sse.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
client/cookiejar_test.go (1)

638-671: 💤 Low value

Variable names with is* prefix should be reserved for booleans.

The variables isHostOnlyOrigin and isHostOnlyCookie are a *fasthttp.URI and *fasthttp.Cookie respectively, not booleans. The is* prefix conventionally signals a boolean type, making these names misleading.

The original names hostOnlyOrigin and hostOnlyCookie were 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 of hostOnly in 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

📥 Commits

Reviewing files that changed from the base of the PR and between e7d4940 and 192ac20.

📒 Files selected for processing (28)
  • app.go
  • bind.go
  • bind_test.go
  • client/client.go
  • client/client_test.go
  • client/cookiejar.go
  • client/cookiejar_test.go
  • client/hooks.go
  • client/request.go
  • ctx.go
  • domain.go
  • group.go
  • log/default.go
  • log/default_test.go
  • middleware/cache/manager.go
  • middleware/csrf/storage_manager.go
  • middleware/limiter/manager.go
  • middleware/logger/config.go
  • middleware/logger/default_logger.go
  • middleware/logger/logger.go
  • middleware/logger/tags.go
  • middleware/session/middleware.go
  • middleware/session/session.go
  • middleware/session/store.go
  • middleware/sse/sse.go
  • mount.go
  • router.go
  • router_test.go

Comment thread middleware/sse/sse.go Outdated
@gaby

gaby commented May 20, 2026

Copy link
Copy Markdown
Member

@pageton check the review comments

@codecov

codecov Bot commented May 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.59459% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.40%. Comparing base (da9b7b6) to head (5aeb997).

Files with missing lines Patch % Lines
middleware/logger/default_logger.go 40.00% 3 Missing ⚠️
domain.go 80.00% 1 Missing and 1 partial ⚠️
client/cookiejar.go 94.73% 1 Missing ⚠️
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     
Flag Coverage Δ
unittests 91.40% <94.59%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- 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)
@pageton

pageton commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

@gaby all review comments addressed:

  • abandonedisAbandoned
  • userContextSetisUserContextSet
  • Error string reverted to original
  • Non-boolean isHostOnly* variables reverted

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.
@ReneWerner87 ReneWerner87 merged commit 60716c8 into gofiber:main May 21, 2026
18 checks passed
@welcome

welcome Bot commented May 21, 2026

Copy link
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

🎨 Style: Add is/has/can prefix to unexported boolean struct fields

3 participants