Skip to content

chore: apply go fix improvements#78

Open
echarrod wants to merge 3 commits intomainfrom
echarrod/go-fix-improvements
Open

chore: apply go fix improvements#78
echarrod wants to merge 3 commits intomainfrom
echarrod/go-fix-improvements

Conversation

@echarrod
Copy link
Copy Markdown
Contributor

@echarrod echarrod commented Apr 13, 2026

Apply go fix to modernize the codebase:

  • Add missing imports
  • Optimize string concatenation using strings.Builder (performance improvement over concatenation loops)
  • Use Go 1.22 range-over-int syntax (for i := range N instead of for i := 0; i < N; i++)

Summary by CodeRabbit

Release Notes

  • Chores

    • Updated GitHub Actions test workflow to use the latest stable Go release for improved performance and security.
    • Modernised internal type declarations for better code clarity.
    • Enhanced string parsing implementation using latest Go features.
  • Tests

    • Expanded unit test coverage for type conversions, configuration parsing, and value defaults.

- Add missing imports
- Optimize string concatenation using strings.Builder
- Use Go 1.22 range-over-int syntax
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 13, 2026

Warning

Rate limit exceeded

@echarrod has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 43 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 14 minutes and 43 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9fb8f12d-63c5-464f-a41b-a96fbb43186c

📥 Commits

Reviewing files that changed from the base of the PR and between fbda734 and fa4adf8.

📒 Files selected for processing (1)
  • .github/workflows/test.yml
📝 Walkthrough

Walkthrough

This pull request systematically modernises the codebase to use Go's any type alias in place of interface{} across multiple files (arc.go, test files, shift.go, helper_test.go, shiftgen). Additionally, the PR updates GitHub Actions workflow to use the latest stable Go release, refactors string splitting to use strings.SplitSeq, replaces type reflection calls with generic reflect.TypeFor[T](), adds comprehensive unit tests for the shiftgen package, and updates test utilities to use modern APIs for context and metadata serialisation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 From empty interfaces, we've set types free,
any now guides where they used to be,
With TypeFor generic and SplitSeq so neat,
Modern Go patterns make the code complete!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description is related to the changeset but incomplete; it mentions go fix improvements, missing imports, strings.Builder optimizations, and range-over-int syntax, yet the actual changes primarily involve interface{} to any type conversions, SplitSeq usage, and reflect.TypeFor updates. Update the description to accurately reflect the actual changes made, such as interface{} to any conversions, strings.SplitSeq usage, reflect.TypeFor adoption, and test additions rather than focusing on unimplemented optimisations.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: applying go fix improvements to modernize the codebase with interface{} to any conversions and syntax updates.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch echarrod/go-fix-improvements

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.

@echarrod echarrod enabled auto-merge (squash) April 13, 2026 08:33
- Update CI matrix go version from '1' (resolving to 1.25.8) to 'stable'
  so it meets the go.mod requirement of go >= 1.26.0
- Add table-driven tests for toSnakeCase, IDZeroValue, parseUpdaters, and
  parseInserters to cover functions changed in this PR; coverage on those
  functions goes from 0% to 100%

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

🧹 Nitpick comments (3)
.github/workflows/test.yml (1)

18-18: Consider testing against the minimum supported Go version as well.

The workflow now only tests against the latest stable Go release. To ensure the codebase remains compatible with the minimum Go version specified in go.mod (1.26.0), consider adding it to the test matrix:

go: ['1.26.0', 'stable']

This would verify that the code doesn't accidentally rely on features introduced in Go versions newer than 1.26.0.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/test.yml at line 18, Update the CI test matrix in the
workflow to include the minimum supported Go version from go.mod: modify the
existing go matrix entry (currently "go: ['stable']") to include "1.26.0" so it
reads like go: ['1.26.0', 'stable']; this ensures the workflow tests both the
declared minimum Go version and the stable release.
shiftgen/shiftgen.go (1)

150-152: Skip empty tokens while parsing comma-separated flag values.

Both parsers currently append trimmed entries even when they are empty (e.g. trailing commas or ", ,"). Filtering blanks here will produce clearer downstream behaviour.

Proposed patch
 func parseInserters() ([]string, error) {
@@
 	} else if strings.TrimSpace(*inserters) != "" {
 		for i := range strings.SplitSeq(*inserters, ",") {
-			ii = append(ii, strings.TrimSpace(i))
+			v := strings.TrimSpace(i)
+			if v == "" {
+				continue
+			}
+			ii = append(ii, v)
 		}
 	}
 	return ii, nil
 }
@@
 func parseUpdaters() []string {
 	var uu []string
 	if strings.TrimSpace(*updaters) != "" {
 		for u := range strings.SplitSeq(*updaters, ",") {
-			uu = append(uu, strings.TrimSpace(u))
+			v := strings.TrimSpace(u)
+			if v == "" {
+				continue
+			}
+			uu = append(uu, v)
 		}
 	}
 	return uu
 }

Also applies to: 160-162

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shiftgen/shiftgen.go` around lines 150 - 152, The token appending loops using
strings.SplitSeq(*inserters, ",") currently append trimmed tokens even when
empty; change the loops (the one building ii from inserters and the similar loop
around lines 160-162) to trim each token with strings.TrimSpace, then skip
adding it if the result is an empty string (continue), so only non-blank tokens
are appended to ii (and the other target slice).
shiftgen/shiftgen_test.go (1)

56-67: Consider adding comma-edge cases to pin parser behaviour.

An extra case for inputs like "A,,B" or "A," would make empty-token handling explicit and prevent future regressions.

Also applies to: 88-93

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shiftgen/shiftgen_test.go` around lines 56 - 67, Add explicit comma-edge test
cases to TestParseUpdaters to assert how empty tokens are handled: include
inputs like "A,,B" expecting either ["A","B"] or an error/nil as per
ParseUpdaters' contract, and inputs like "A," and ",A" to verify
trailing/leading comma behavior; locate the test table in TestParseUpdaters and
append rows for these scenarios (also mirror the same additions in the other
table around lines 88-93) so the parser's handling of empty tokens is pinned
down.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.github/workflows/test.yml:
- Line 18: Update the CI test matrix in the workflow to include the minimum
supported Go version from go.mod: modify the existing go matrix entry (currently
"go: ['stable']") to include "1.26.0" so it reads like go: ['1.26.0', 'stable'];
this ensures the workflow tests both the declared minimum Go version and the
stable release.

In `@shiftgen/shiftgen_test.go`:
- Around line 56-67: Add explicit comma-edge test cases to TestParseUpdaters to
assert how empty tokens are handled: include inputs like "A,,B" expecting either
["A","B"] or an error/nil as per ParseUpdaters' contract, and inputs like "A,"
and ",A" to verify trailing/leading comma behavior; locate the test table in
TestParseUpdaters and append rows for these scenarios (also mirror the same
additions in the other table around lines 88-93) so the parser's handling of
empty tokens is pinned down.

In `@shiftgen/shiftgen.go`:
- Around line 150-152: The token appending loops using
strings.SplitSeq(*inserters, ",") currently append trimmed tokens even when
empty; change the loops (the one building ii from inserters and the similar loop
around lines 160-162) to trim each token with strings.TrimSpace, then skip
adding it if the result is an empty string (continue), so only non-blank tokens
are appended to ii (and the other target slice).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 39bd9b7c-dcac-4f5a-9ddd-14d883574f4d

📥 Commits

Reviewing files that changed from the base of the PR and between 155848a and fbda734.

📒 Files selected for processing (14)
  • .github/workflows/test.yml
  • arc.go
  • gen_1_test.go
  • gen_2_test.go
  • gen_3_test.go
  • gen_4_test.go
  • gen_string_test.go
  • helper_test.go
  • shift.go
  • shift_internal_test.go
  • shiftgen/shiftgen.go
  • shiftgen/shiftgen_test.go
  • test_shift.go
  • test_shift_test.go

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
12 Security Hotspots
60.4% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant