Skip to content

deps: remove samber/lo in favor of local uniqBy#2463

Open
kotakanbe wants to merge 6 commits intomasterfrom
diet-samber-lo
Open

deps: remove samber/lo in favor of local uniqBy#2463
kotakanbe wants to merge 6 commits intomasterfrom
diet-samber-lo

Conversation

@kotakanbe
Copy link
Copy Markdown
Member

@kotakanbe kotakanbe commented Mar 16, 2026

Why (motivation for removing this dependency)

  • samber/lo is a lodash-style utility library for Go with generics
  • Reason for removal: only lo.UniqBy is used (2 call sites). Pulling in a 5000+ line utility library for a single 12-line function is excessive
  • go.mod impact: removed from direct deps. Remains as indirect (via trivy -> fanal)

What (replacement details)

  • Replace lo.UniqBy with a local uniqBy[T, K] generic function (12 lines each)
  • detector/library.go: replaced lo.UniqBy call with local uniqBy
  • detector/util.go: added uniqBy implementation
  • scanner/trivy/jar/parse.go: replaced lo.UniqBy call + added local uniqBy implementation

Two separate implementations because the packages cannot share a common utility without risking import cycles.

Safety (why this is safe)

  • Risk level: low
  • The implementation is a straightforward map-based deduplication preserving first occurrence — identical semantics to lo.UniqBy
  • Generic type constraints ([T any, K comparable]) match the original

Test plan

  • TestUniqBy (detector) - empty slice, no duplicates, duplicates removed (first kept), struct key extraction
  • TestUniqBy (scanner/trivy/jar) - same 4 cases
  • go build ./cmd/... pass
  • go test ./detector/... ./scanner/trivy/jar/... pass

Review hint (how to review efficiently)

  1. Read uniqBy in detector/util.go (12 lines) — this is the core logic
  2. scanner/trivy/jar/parse.go has an identical copy (separate package, no import cycle)
  3. The call sites in detector/library.go and scanner/trivy/jar/parse.go are trivial renames: lo.UniqBy -> uniqBy
  4. Test files mirror each other — reviewing one covers both

🤖 Generated with Claude Code

kotakanbe and others added 6 commits March 16, 2026 13:07
Replace github.com/samber/lo with a minimal generic uniqBy function
implemented locally in each package. samber/lo was only used for
UniqBy to deduplicate library slices.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify that uniqBy correctly deduplicates slices preserving first
occurrence, handles empty slices, and works with struct key functions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kotakanbe kotakanbe requested a review from Copilot March 24, 2026 00:59
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