Skip to content

chore(lint): enable modernize linter with only bloop analyzer#19520

Open
janisz wants to merge 2 commits intomasterfrom
modernize
Open

chore(lint): enable modernize linter with only bloop analyzer#19520
janisz wants to merge 2 commits intomasterfrom
modernize

Conversation

@janisz
Copy link
Contributor

@janisz janisz commented Mar 20, 2026

Description

omitzero: Omitempty has no effect on nested struct fields (modernize)

https://www.jvt.me/posts/2025/02/12/go-omitzero-124/

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests
  • added e2e tests
  • added regression tests
  • added compatibility tests
  • modified existing tests

How I validated my change

CI

Add the modernize linter to .golangci.yml with only the bloop analyzer
enabled. All other analyzers are disabled for now and will be enabled
incrementally in future commits.

The bloop analyzer fixes loop variable capture issues that can cause
bugs when loop variables are captured by closures or goroutines. This
issue was already addressed in the codebase by PR #17491 which
converted benchmarks to use b.Loop() (Go 1.24+).

Running golangci-lint --fix found 0 issues, confirming the codebase is
already clean for loop variable capture problems.

Reference commits:
- PR #17491: Use b.Loop() for benchmarks (6a5b6a4)
- Fix false positive in BenchmarkSliceRead (ad227d0f25)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Tomasz Janiszewski <tomek@redhat.com>
@rhacs-bot
Copy link
Contributor

rhacs-bot commented Mar 20, 2026

Images are ready for the commit at 4850eb9.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.11.x-391-g4850eb9965.

@codecov
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.23%. Comparing base (f1bd4cf) to head (4850eb9).
⚠️ Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #19520      +/-   ##
==========================================
- Coverage   49.26%   49.23%   -0.04%     
==========================================
  Files        2726     2727       +1     
  Lines      205628   205764     +136     
==========================================
+ Hits       101307   101312       +5     
- Misses      96783    96914     +131     
  Partials     7538     7538              
Flag Coverage Δ
go-unit-tests 49.23% <ø> (-0.04%) ⬇️

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:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Replace misleading `omitempty` tags with `omitzero` on nested struct
and time.Time fields where `omitempty` has no effect.

Changes:
- pkg/auth/authproviders/iap: googleClaims field
- pkg/auth/authproviders/registry: time.Time expiry field
- pkg/auth/authproviders/openshift: k8sapi.ObjectMeta field

The `omitempty` tag doesn't work on:
1. Nested structs (not pointers) - always serialized even when empty
2. time.Time - zero value (Unix epoch) is valid, not considered "empty"

With `omitzero`, these fields are now properly omitted when zero-valued,
which is the intended behavior and improves API responses.

Detected by: modernize/omitzero analyzer
Applied manually after reviewing behavior change impact.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@janisz janisz requested a review from a team as a code owner March 20, 2026 15:28
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Using json:"...,omitzero" introduces a non-standard struct tag that encoding/json does not understand; if these types are marshalled with the standard library, this will change or break JSON behavior—consider either removing omitempty on nested structs or using pointers instead of introducing omitzero in the tag.
  • If the goal is to enforce only the omitzero check from modernize, it might be clearer to enable modernize globally and then explicitly disable it per-directory or via //nolint where needed, rather than disabling nearly all of its analyzers in the config.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Using `json:"...,omitzero"` introduces a non-standard struct tag that `encoding/json` does not understand; if these types are marshalled with the standard library, this will change or break JSON behavior—consider either removing `omitempty` on nested structs or using pointers instead of introducing `omitzero` in the tag.
- If the goal is to enforce only the `omitzero` check from `modernize`, it might be clearer to enable `modernize` globally and then explicitly disable it per-directory or via `//nolint` where needed, rather than disabling nearly all of its analyzers in the config.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@rhybrillou rhybrillou left a comment

Choose a reason for hiding this comment

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

I like the principle.
You'll need to fix other locations before merging (check the failed style job).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants