HYPERFLEET-443 | Fix lint issues and enable 15/16 HyperFleet standard linters#5
Conversation
WalkthroughThis PR updates Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
🔇 Additional comments (1)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
cmd/pull-secret/jobs/pull_secret_test.go (1)
268-278: Prefert.Setenvoveros.Clearenv()/os.Setenv()for test isolation.The added
os.Setenverror check is good, butos.Clearenv()is process-global and can become flaky if any tests in this package start usingt.Parallel()later. Consider switching tot.Setenv(k, v)(and only setting the needed keys) instead of clearing the whole environment.
🤖 Fix all issues with AI agents
In @.golangci.yml:
- Around line 1-6: The header comment claiming "All 16 required linters enabled"
is inaccurate because the revive linter remains disabled (the revive entry in
.golangci.yml is set to disabled); either enable revive or update the header to
say "15 of 16 required linters enabled" (or similar) to match the actual
configuration—locate the revive config block and the top-of-file header comment
and change one of them so the comment and the revive setting are consistent.
🧹 Nitpick comments (2)
cmd/pull-secret/jobs/pull_secret.go (2)
20-22://nolint:gosec (G101)onpullSecretTaskNamelooks unnecessary.The string doesn’t look like a credential; if gosec is flagging it anyway and you want to keep the suppression, the justification comment is good.
349-366: Bound the exponential backoff + seed jitter to avoid overflow and synchronized retries.
1<<uint(i)is only safe whileiis small; sincemaxRetriesis a parameter, consider clamping the exponent and using a locally-seeded RNG for jitter so multiple pods don’t “randomly” retry in lockstep. This also lets you drop the gosec suppressions by construction.Proposed diff (safer backoff + seeded jitter)
func retryWithBackoff(ctx context.Context, fn func() error, maxRetries int) error { var err error + // Seed once per call (low overhead at small maxRetries). Alternatively: package-level rand.New(...) seeded in init(). + rng := rand.New(rand.NewSource(time.Now().UnixNano())) for i := 0; i < maxRetries; i++ { err = fn() if err == nil { return nil } @@ if i < maxRetries-1 { // Calculate backoff with jitter (±20%) - //nolint:gosec // G115: i is bounded by maxRetries (small value) - baseBackoff := time.Duration(1<<uint(i)) * time.Second + // Clamp exponent to avoid overflow for large maxRetries. + exp := i + if exp > 30 { + exp = 30 + } + baseBackoff := time.Duration(1<<uint(exp)) * time.Second jitterRange := float64(baseBackoff) * 0.2 // Random value between -20% and +20% of base backoff - //nolint:gosec // G404: weak random is acceptable for jitter calculation - jitter := time.Duration((rand.Float64()*2 - 1) * jitterRange) + jitter := time.Duration((rng.Float64()*2 - 1) * jitterRange) backoff := baseBackoff + jitter
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
.golangci.ymlcmd/pull-secret/jobs/pull_secret.gocmd/pull-secret/jobs/pull_secret_test.gocmd/pull-secret/main.gopkg/job/job.gopkg/job/metrics.go
🧰 Additional context used
🧬 Code graph analysis (1)
pkg/job/job.go (1)
pkg/job/metrics.go (2)
MetricsReporter(10-12)MetricsCollector(16-22)
🔇 Additional comments (11)
pkg/job/metrics.go (1)
61-65: LGTM!The multi-line formatting improves readability while maintaining identical functionality. This aligns with the PR objective of meeting the 120-character line limit for the lll linter.
pkg/job/job.go (6)
100-106: LGTM!Clean refactoring to an intermediate variable. This improves readability and complies with line length requirements without changing functionality.
210-213: LGTM!Multi-line formatting for the panic logging call improves readability while maintaining identical behavior.
268-272: LGTM!Consistent multi-line formatting applied to panic logging, matching the style used elsewhere in the file.
302-303: LGTM!The
nolint:gosecdirective is appropriate here. The G115 warning concerns int-to-uint32 conversion, but task counts realistically won't exceeduint32bounds in a job runner context. The inline explanation follows best practices for nolint annotations.
307-312: LGTM!Multi-line struct initialization improves readability and meets line length requirements.
357-358: LGTM!Consistent application of the
nolint:gosecdirective, matching the pattern used injobRunner.Run. This maintains uniformity across both runner implementations.cmd/pull-secret/main.go (1)
21-25: Double-check//nolint:errcheckis still recognized (nolintlint can be picky).Putting
//nolint:errcheckon its own line is usually fine, but ifnolintlintis enabled it may enforce stricter placement/formatting. If you see “unused nolint directive”, move it to the end of the assignment line.cmd/pull-secret/jobs/pull_secret.go (2)
93-96: Flag help string wrap is clean.
110-150: Logging line-break refactors look consistent and keep semantics intact.Also applies to: 153-170, 203-229, 309-312
.golangci.yml (1)
5-6: There is no CI in this repository—golangci-lint runs locally only.The config correctly declares
version: "2"and uses v2-specific features like theformatterssection. However, there are no GitHub Actions workflows, CI/CD pipelines, or any automated systems in the repository. The linting tool runs only when developers executemake lintlocally. Developers with golangci-lint v1 installed will encounter errors with this config; document the required v1.61.0+ version in the Makefile or add a version check.Likely an incorrect or invalid review comment.
|
/lgtm |
Summary by CodeRabbit
Bug Fixes
Tests
Chores
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.