Skip to content

chore: enable the modernize linter for idiomatic packages - #88

Merged
tphakala merged 1 commit into
mainfrom
chore/reenable-modernize-linter
Sep 8, 2026
Merged

chore: enable the modernize linter for idiomatic packages#88
tphakala merged 1 commit into
mainfrom
chore/reenable-modernize-linter

Conversation

@tphakala

@tphakala tphakala commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Summary

The Go 1.27 and golangci-lint v2.13.2 upgrade resolved the golangci-lint v2 panic on atomic types that had kept the modernize linter disabled, so this enables it for the idiomatic packages. It is scoped to skip the deliberately C-shaped transliteration packages (internal/celt, internal/silk, internal/rangecoding, internal/fixedmath, internal/silkmath, internal/opuscompare, internal/opusdec, internal/opusenc) and the cgo differential harness (internal/reftest), because modernize's rangeint and loop rewrites fight line-by-line diffability against the libopus v1.6.1 reference those packages mirror. That matches how the other style and complexity linters are already relaxed in those same blocks.

Applying the four suggestions modernize produced in the idiomatic packages: max/min builtins in the oggopus decoder and writer, plus a range-over-int loop and a min() in two test helpers. All four are behavior-preserving and covered by existing tests.

Test Plan

  • go build ./..., go vet ./..., and gofmt -l are clean
  • golangci-lint run ./... (v2.13.2, default build tags, the CI configuration) reports 0 issues
  • golangci-lint run --enable-only=modernize ./... reports 0 issues, confirming every finding was applied and the excluded packages are suppressed
  • go test ./... passes

Summary by CodeRabbit

  • Refactor

    • Updated internal calculations to use modern Go built-in helpers while preserving existing behavior.
    • Improved compatibility and consistency with modern Go tooling.
    • Clarified configuration comments around Go version compatibility and formatting exceptions.
  • Tests

    • Simplified test iteration and comparison logic without changing coverage or expected results.

The Go 1.27 and golangci-lint v2.13.2 bump resolved the v2 panic on
atomic types that had kept modernize disabled. Enable it, scoped so the
transliteration packages (internal/celt, internal/silk, ...) and the cgo
differential harness (internal/reftest) keep their C-mirroring loops:
modernize's rangeint and loop rewrites fight diffability against the
libopus reference there, the same reason those packages already relax
the other style linters.

Apply the four resulting suggestions in the idiomatic packages: max/min
builtins in the oggopus decoder and writer, and a range-over-int loop
plus a min() in two test helpers. All four are behavior-preserving and
covered by existing tests.
Copilot AI lite review requested due to automatic review settings September 8, 2026 18:14
@gitar-bot

gitar-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

Enables the modernize linter for idiomatic packages now that Go 1.27 and golangci-lint v2.13.2 resolve the atomic types panic. Applies four modernize suggestions: max/min builtins in the oggopus decoder and writer, plus a range-over-int loop and min() in test helpers. All changes are behavior-preserving and covered by existing tests. No issues found.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: af740ff4-bf14-4f27-a51e-299c0fa2d494

📥 Commits

Reviewing files that changed from the base of the PR and between 8c0151b and 9111f8b.

📒 Files selected for processing (5)
  • .golangci.yaml
  • internal/packet/toc_test.go
  • oggopus/decoder.go
  • oggopus/family1_test.go
  • oggopus/writer.go

Included review availability: 0 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.


Walkthrough

The change enables the modernize linter with targeted exclusions. It updates affected loops, minimum calculations, and maximum calculations to use current Go built-ins.

Changes

Modernize lint adoption

Layer / File(s) Summary
Modernize lint policy
.golangci.yaml
The configuration enables modernize and documents exclusions for transliteration packages and the internal/reftest cgo harness.
Modernize syntax updates
internal/packet/toc_test.go, oggopus/decoder.go, oggopus/family1_test.go, oggopus/writer.go
The code uses integer range syntax and the built-in min and max functions. Existing behavior remains unchanged.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 9111f

This enables modernize linting with exclusions for reference-mirroring code and replaces several equivalent expressions with Go built-ins. The changes are behavior-preserving and ready to merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the primary change: enabling the modernize linter for idiomatic packages. It is concise and specific.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/reenable-modernize-linter

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

There is a potential slice-bounds panic on 32-bit platforms due to converting an int64 delta to int before clamping in oggopus/decoder.go.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Enables the modernize golangci-lint linter for idiomatic packages (while keeping transliteration/C-mirroring packages excluded) and applies the resulting behavior-preserving refactors (built-in min/max and range-over-int loops).

Changes:

  • Enable modernize in .golangci.yaml, with explicit exclusions for transliteration packages and internal/reftest.
  • Refactor selected loops and min/max patterns in oggopus and tests to modern Go idioms (min/max, for i := range n, for x := range uint8(4)).
File summaries
File Description
oggopus/writer.go Uses max() to simplify final granule monotonicity guard.
oggopus/family1_test.go Uses min() and range-over-int for prefix-diff helper.
oggopus/decoder.go Uses max() to simplify end-trim clamping logic.
internal/packet/toc_test.go Uses range-over-int for compact frame-count sweep loop.
.golangci.yaml Enables modernize and excludes it where C-diffability is required.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread oggopus/decoder.go
Comment on lines 202 to 204
if d.limit >= 0 && d.delivered+int64(perChan) > d.limit {
keep := int(d.limit - d.delivered)
if keep < 0 {
keep = 0
}
keep := max(int(d.limit-d.delivered), 0)
samples = samples[:keep*d.info.Channels]

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Good eye, but it's safe as written and this change is behavior-preserving: the old keep := int(d.limit-d.delivered); if keep < 0 { keep = 0 } and the new keep := max(int(d.limit-d.delivered), 0) do the int64 to int conversion in exactly the same place, so nothing about the conversion changed here.

At this point d.limit - d.delivered is bounded to [0, perChan). The clamp only runs under d.limit >= 0 && d.delivered+perChan > d.limit, and delivered never exceeds limit (once the end-trim fires, delivered is pinned to limit). perChan is a single Opus frame (<= 5760 samples per channel), so the value fits int32 on every platform, and the max(..., 0) floors the late-discovered-limit case to 0. The only way to feed a large-magnitude int64 into that conversion is a limit discovered late after roughly 2 billion over-delivered samples on a 32-bit build, which is pre-existing and orthogonal to enabling a linter.

I'll track hardening the clamp to int64 (and capping to perChan) as a separate follow-up rather than fold an untrusted-input logic change into this PR.

@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@tphakala
tphakala merged commit f4104c0 into main Sep 8, 2026
23 checks passed
@tphakala
tphakala deleted the chore/reenable-modernize-linter branch September 8, 2026 18:25
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.

2 participants