Skip to content

Apply changes from Go's modernize tool#395

Merged
nicholas-fedor merged 4 commits intomainfrom
chore/apply-modernization
Mar 17, 2026
Merged

Apply changes from Go's modernize tool#395
nicholas-fedor merged 4 commits intomainfrom
chore/apply-modernization

Conversation

@nicholas-fedor
Copy link
Owner

@nicholas-fedor nicholas-fedor commented Mar 16, 2026

This PR applies automated changes from Go's modernize tool.

Changes

  • Use max() for cleaner index calculations in TUI logs
  • Use reflect.TypeFor for compile-time type checking in tests
  • Use strings.CutPrefix for cleaner prefix handling in trash
  • Use WaitGroup.Go for cleaner goroutine handling in integration tests

Summary by CodeRabbit

  • Refactor

    • Optimized log display calculation for simpler, slightly more efficient behavior.
    • Enhanced string parsing efficiency in trash data processing.
  • Tests

    • Reworked concurrent logging test structure.
    • Adjusted unit tests to simplify type checks (reduces strict type assertions).
  • Style

    • Removed a lint suppression comment.

- Use max() for cleaner index calculations in TUI logs
- Use reflect.TypeFor for compile-time type checking in tests
- Use strings.CutPrefix for cleaner prefix handling in trash
- Use WaitGroup.Go for cleaner goroutine handling in integration tests
@coderabbitai
Copy link

coderabbitai bot commented Mar 16, 2026

Warning

Rate limit exceeded

@nicholas-fedor has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 9 minutes and 50 seconds before requesting another review.

⌛ 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: e188626c-5261-42df-85af-562b9b13506c

📥 Commits

Reviewing files that changed from the base of the PR and between f6d3da8 and 4fe9998.

📒 Files selected for processing (2)
  • internal/cli/tui_test.go
  • testing/integration/logger/logger_integration_test.go

Walkthrough

Simplifies TUI log-index calculation, swaps prefix handling to strings.CutPrefix, switches goroutine spawning to wg.Go() in an integration test, and alters runtime type-equality checks in TUI tests (making those assertions tautological). No exported APIs changed.

Changes

Cohort / File(s) Summary
TUI Simplification
internal/cli/tui.go
Replaces multi-line clamp with single-line max(len(m.logs)-maxVisibleLogLines, 0) to compute the start index for visible logs.
TUI Tests
internal/cli/tui_test.go
Replaces runtime type-equality assertions in Test_model_Init and Test_model_Update with a tautological TypeFor[tea.Cmd]() != TypeFor[tea.Cmd](), effectively disabling those mismatch checks.
String Handling Refactor
internal/trash/trash.go
Replaces HasPrefix/TrimPrefix with strings.CutPrefix(..., "Path=") and strings.CutPrefix(..., "DeletionDate=") in parseTrashInfo() to avoid double-pass prefix handling.
Goroutine Pattern Update (tests)
testing/integration/logger/logger_integration_test.go
Replaces wg.Add()/wg.Done() + inline goroutines with wg.Go(func(){...}) for two concurrent loops in TestConcurrentLevelChanges().
Lint Directive Removal
cmd/root.go
Removes nolint:gosec directive for a temporary file check in isDirWritable.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main objective: applying modernization changes from Go's analysis tool across multiple files and patterns.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

📝 Coding Plan
  • Generate coding plan for human review comments

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.

@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

❌ Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/trash/trash.go 25.00% 1 Missing and 2 partials ⚠️

❌ Your patch status has failed because the patch coverage (40.00%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #395      +/-   ##
==========================================
- Coverage   54.43%   54.39%   -0.05%     
==========================================
  Files          15       15              
  Lines        2118     2116       -2     
==========================================
- Hits         1153     1151       -2     
  Misses        887      887              
  Partials       78       78              
Files with missing lines Coverage Δ
cmd/root.go 20.10% <ø> (ø)
internal/cli/tui.go 62.62% <100.00%> (-0.13%) ⬇️
internal/trash/trash.go 86.90% <25.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nicholas-fedor nicholas-fedor changed the title refactor: apply go modernize changes Apply changes from Go's modernize tool Mar 16, 2026
- Remove obsolete gosec nolint directive from cmd/root.go
- Clean up extra whitespace in logger integration tests
Copy link

@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: 3

🧹 Nitpick comments (1)
internal/cli/tui.go (1)

764-764: Good modernization, but consider completing it across the file.

Using the built-in max() is cleaner. However, this file still uses the custom maximum() and minimum() helpers in multiple places (lines 804, 809, 816, 830, 832, 837, 908, 1053, 1055), and those functions are still defined at lines 1229-1244.

Consider replacing all maximum()/minimum() calls with the built-in max()/min() functions and removing the now-redundant helper definitions for consistency.

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

In `@internal/cli/tui.go` at line 764, Replace all custom helper calls to
maximum() and minimum() in this file with the Go built-in max() and min() (e.g.,
change maximum(x,y) -> max(x,y), minimum(x,y) -> min(x,y)), update any
surrounding expressions such as the existing start :=
max(len(m.logs)-maxVisibleLogLines, 0) pattern to match other occurrences, and
remove the now-redundant helper function definitions maximum() and minimum()
from the file; ensure the replacements target the maximum/minimum identifiers
and related call sites so compilation uses the built-in min/max.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/cli/tui_test.go`:
- Around line 445-447: The type-comparison line is a tautology because
reflect.TypeFor[tea.Cmd]() compares the same type to itself; replace it with a
real runtime type comparison using the actual values: change the condition to
compare reflect.TypeOf(gotCmd) and reflect.TypeOf(tt.wantCmd) (e.g., if
reflect.TypeOf(gotCmd) != reflect.TypeOf(tt.wantCmd) { t.Errorf("model.Update()
gotCmd = %T, want %T", gotCmd, tt.wantCmd) }), referencing the variables gotCmd
and tt.wantCmd so the check in the test actually detects mismatched command
types.
- Around line 189-191: The test currently compares the same type to itself
(reflect.TypeFor[tea.Cmd]() != reflect.TypeFor[tea.Cmd]()), which is a tautology
and never triggers; replace it with a real type check by comparing the runtime
type of the returned value to the expected type (e.g. use reflect.TypeOf(got) !=
reflect.TypeOf(tt.want)) or perform a type assertion (e.g. _, ok :=
got.(tea.Cmd); if !ok { t.Errorf("model.Init() returned %T, want tea.Cmd", got)
}) so the model.Init() result (got) is actually validated against the expected
tea.Cmd type.

In `@testing/integration/logger/logger_integration_test.go`:
- Around line 440-454: The file mixes sync.WaitGroup.Add()/Done() and the newer
wg.Go(func()) usage (see TestConcurrentLogging and the concurrent loops using
wg.Go); standardize to the wg.Go pattern across the file: replace the
Add()/defer Done() blocks in TestConcurrentLogging with wg.Go(func() { ... })
calls (removing explicit Add/Done), and ensure all goroutine spawns use wg.Go so
the file consistently relies on WaitGroup.Go.

---

Nitpick comments:
In `@internal/cli/tui.go`:
- Line 764: Replace all custom helper calls to maximum() and minimum() in this
file with the Go built-in max() and min() (e.g., change maximum(x,y) ->
max(x,y), minimum(x,y) -> min(x,y)), update any surrounding expressions such as
the existing start := max(len(m.logs)-maxVisibleLogLines, 0) pattern to match
other occurrences, and remove the now-redundant helper function definitions
maximum() and minimum() from the file; ensure the replacements target the
maximum/minimum identifiers and related call sites so compilation uses the
built-in min/max.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d1752737-b545-4821-b021-c726b800dd7f

📥 Commits

Reviewing files that changed from the base of the PR and between 1f1e03b and d5cc211.

📒 Files selected for processing (4)
  • internal/cli/tui.go
  • internal/cli/tui_test.go
  • internal/trash/trash.go
  • testing/integration/logger/logger_integration_test.go

Comment on lines 189 to 191
if reflect.TypeFor[tea.Cmd]() != reflect.TypeFor[tea.Cmd]() {
t.Errorf("model.Init() = %T, want %T", got, tt.want)
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Test assertion is a no-op tautology.

The condition reflect.TypeFor[tea.Cmd]() != reflect.TypeFor[tea.Cmd]() compares the same type to itself and will always be false. This effectively disables the type check assertion—the error message on line 190 will never execute.

If the intent is to verify that got has the expected type, compare reflect.TypeOf(got) against the expected type. If the test should simply confirm Init() returns a tea.Cmd (or nil), consider removing the dead code or restructuring the assertion.

Suggested fix to restore the type comparison
-			if reflect.TypeFor[tea.Cmd]() != reflect.TypeFor[tea.Cmd]() {
+			if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
 				t.Errorf("model.Init() = %T, want %T", got, tt.want)
 			}
📝 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
if reflect.TypeFor[tea.Cmd]() != reflect.TypeFor[tea.Cmd]() {
t.Errorf("model.Init() = %T, want %T", got, tt.want)
}
if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
t.Errorf("model.Init() = %T, want %T", got, tt.want)
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/cli/tui_test.go` around lines 189 - 191, The test currently compares
the same type to itself (reflect.TypeFor[tea.Cmd]() !=
reflect.TypeFor[tea.Cmd]()), which is a tautology and never triggers; replace it
with a real type check by comparing the runtime type of the returned value to
the expected type (e.g. use reflect.TypeOf(got) != reflect.TypeOf(tt.want)) or
perform a type assertion (e.g. _, ok := got.(tea.Cmd); if !ok {
t.Errorf("model.Init() returned %T, want tea.Cmd", got) }) so the model.Init()
result (got) is actually validated against the expected tea.Cmd type.

Comment on lines 445 to 447
if reflect.TypeFor[tea.Cmd]() != reflect.TypeFor[tea.Cmd]() {
t.Errorf("model.Update() gotCmd = %T, want %T", gotCmd, tt.wantCmd)
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Same tautology issue—type assertion is disabled.

Identical problem as line 189: reflect.TypeFor[tea.Cmd]() != reflect.TypeFor[tea.Cmd]() is always false, so the type mismatch check never triggers.

Suggested fix
-			if reflect.TypeFor[tea.Cmd]() != reflect.TypeFor[tea.Cmd]() {
+			if reflect.TypeOf(gotCmd) != reflect.TypeOf(tt.wantCmd) {
 				t.Errorf("model.Update() gotCmd = %T, want %T", gotCmd, tt.wantCmd)
 			}
📝 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
if reflect.TypeFor[tea.Cmd]() != reflect.TypeFor[tea.Cmd]() {
t.Errorf("model.Update() gotCmd = %T, want %T", gotCmd, tt.wantCmd)
}
if reflect.TypeOf(gotCmd) != reflect.TypeOf(tt.wantCmd) {
t.Errorf("model.Update() gotCmd = %T, want %T", gotCmd, tt.wantCmd)
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/cli/tui_test.go` around lines 445 - 447, The type-comparison line is
a tautology because reflect.TypeFor[tea.Cmd]() compares the same type to itself;
replace it with a real runtime type comparison using the actual values: change
the condition to compare reflect.TypeOf(gotCmd) and reflect.TypeOf(tt.wantCmd)
(e.g., if reflect.TypeOf(gotCmd) != reflect.TypeOf(tt.wantCmd) {
t.Errorf("model.Update() gotCmd = %T, want %T", gotCmd, tt.wantCmd) }),
referencing the variables gotCmd and tt.wantCmd so the check in the test
actually detects mismatched command types.

@nicholas-fedor nicholas-fedor merged commit c73b470 into main Mar 17, 2026
15 of 16 checks passed
@nicholas-fedor nicholas-fedor deleted the chore/apply-modernization branch March 17, 2026 00:21
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