Skip to content

deps: remove go-homedir in favor of os.UserHomeDir()#2461

Open
kotakanbe wants to merge 5 commits intomasterfrom
diet-go-homedir
Open

deps: remove go-homedir in favor of os.UserHomeDir()#2461
kotakanbe wants to merge 5 commits intomasterfrom
diet-go-homedir

Conversation

@kotakanbe
Copy link
Copy Markdown
Member

@kotakanbe kotakanbe commented Mar 16, 2026

Why (motivation for removing this dependency)

  • go-homedir is a library for resolving the user's home directory ($HOME / %USERPROFILE%)
  • Reason for removal: os.UserHomeDir() (stdlib, Go 1.12+) is a drop-in replacement. The library author recommends using stdlib instead
  • go.mod impact: removed from direct deps. Remains as indirect (via trivy -> go-getter)

What (replacement details)

  • Replace homedir.Dir() with os.UserHomeDir() (identical signature: func() (string, error))
  • scanner/executil.go: removed go-homedir import, added "os" import, replaced call
  • subcmds/util.go: removed go-homedir import, replaced call

Safety (why this is safe)

  • Risk level: near-zero
  • The library author explicitly recommends os.UserHomeDir(). Both resolve the same env vars ($HOME, %USERPROFILE%)
  • No behavioral change whatsoever

Test plan

  • go build ./cmd/... pass
  • go test ./scanner/... pass
  • stdlib drop-in replacement — no additional tests needed

Review hint (how to review efficiently)

  • Both files have the exact same pattern: import swap + one-line call replacement
  • go.mod/go.sum diff is from go mod tidy auto-cleanup

🤖 Generated with Claude Code

kotakanbe and others added 5 commits March 16, 2026 13:01
Replace github.com/mitchellh/go-homedir with the standard library
os.UserHomeDir() which has been available since Go 1.12. This removes
a direct dependency from the project (remains as indirect via trivy).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes direct usage of github.com/mitchellh/go-homedir by switching to Go’s standard library os.UserHomeDir(), reducing direct dependency surface while keeping behavior equivalent for home directory resolution.

Changes:

  • Replace homedir.Dir() with os.UserHomeDir() in subcmds/util.go.
  • Replace homedir.Dir() with os.UserHomeDir() in scanner/executil.go (SSH control path setup).
  • Update go.mod to drop go-homedir as a direct dependency (it remains indirect via other deps).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
subcmds/util.go Switches home directory lookup to os.UserHomeDir() for .vuls directory creation.
scanner/executil.go Switches home directory lookup to os.UserHomeDir() when constructing SSH ControlPath.
go.mod Removes go-homedir from direct requirements and retains it as an indirect dependency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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