Skip to content

🧹 chore: add prefixes to unexported boolean fields#4300

Open
pageton wants to merge 2 commits into
gofiber:mainfrom
pageton:style/unexported-bool-prefix
Open

🧹 chore: add prefixes to unexported boolean fields#4300
pageton wants to merge 2 commits into
gofiber:mainfrom
pageton:style/unexported-bool-prefix

Conversation

@pageton
Copy link
Copy Markdown

@pageton pageton commented May 20, 2026

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
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

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: a846db5e-f496-4f10-bc35-465eafb4f7b4

📥 Commits

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

📒 Files selected for processing (4)
  • client/cookiejar_test.go
  • ctx.go
  • ctx_test.go
  • middleware/sse/sse.go

Walkthrough

This PR renames unexported boolean struct fields across the codebase to use is/has/should/are prefixes and updates all internal usages and related tests; public APIs are unchanged.

Changes

Boolean naming convention refactor

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

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • gofiber/fiber#3171: Changes in bind/internal error-handling flags related to dontHandleErrs/skipValidation.
  • gofiber/fiber#4120: Related bind error/validation control flow edits touching the same paths.
  • gofiber/fiber#4282: Related cookie host-only bookkeeping changes in client/cookiejar.go.

Suggested reviewers

  • gaby
  • sixcolors
  • ReneWerner87
  • efectn

Poem

🐰 In fields that once quietly guessed,

names now ask questions—clean and dressed.
is, has, should, are—lined in a row,
the code reads true wherever they go.
Hoppity refactor, brisk and blessed!

🚥 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 describes the main change: adding boolean field name prefixes to unexported struct fields for improved readability.
Description check ✅ Passed The description provides a clear summary, references the closed issue (#4298), lists verification checks performed, and follows the repository's PR description structure adequately.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #4298: renames ~24 unexported boolean fields with proper prefixes (is/has/can/should/are) across app, ctx, group, bind, client, domain, and middleware packages, and updates all internal references accordingly.
Out of Scope Changes check ✅ Passed All changes are within scope: they are confined to renaming unexported boolean fields and updating corresponding internal references per issue #4298, with no unrelated modifications introduced.

✏️ 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

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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
Copy link
Copy Markdown
Contributor

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

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
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
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.

medium

The field abandoned should be renamed to isAbandoned to maintain consistency with the PR's objective of adding prefixes to boolean fields. Although it is an atomic.Bool, it represents a boolean state and should follow the same naming convention as other fields like isMatched.

Comment thread ctx.go Outdated
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
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.

medium

The field userContextSet should be renamed to isUserContextSet or hasUserContextSet for consistency with the other boolean field renames in this struct (e.g., isMatched, shouldSkipNonUseRoutes).

Comment thread middleware/sse/sse.go Outdated
)

var errStreamClosed = errors.New("sse: stream closed")
var errStreamClosed = errors.New("sse: stream is closed")
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.

medium

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.

Suggested change
var errStreamClosed = errors.New("sse: stream is closed")
var errStreamClosed = errors.New("sse: stream closed")

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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
)

var errStreamClosed = errors.New("sse: stream closed")
var errStreamClosed = errors.New("sse: stream is closed")
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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

Suggested change
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.

@gaby
Copy link
Copy Markdown
Member

gaby commented May 20, 2026

@pageton check the review comments

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Patch coverage is 94.28571% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.32%. Comparing base (e7d4940) to head (192ac20).

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.32%   91.32%           
=======================================
  Files         132      132           
  Lines       12933    12933           
=======================================
  Hits        11811    11811           
  Misses        708      708           
  Partials      414      414           
Flag Coverage Δ
unittests 91.32% <94.28%> (ø)

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
Copy link
Copy Markdown
Author

pageton commented May 20, 2026

@gaby all review comments addressed:

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

Ready for review.

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

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

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

3 participants