Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: get rid of mitchellh/go-homedir package #1195

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/fatih/color"
"github.com/mgechev/revive/config"
"github.com/mgechev/revive/revivelib"
"github.com/mitchellh/go-homedir"
"github.com/spf13/afero"
)

Expand Down Expand Up @@ -128,7 +127,7 @@ func buildDefaultConfigPath() string {
configFileName := "revive.toml"
configDirFile := filepath.Join(os.Getenv("XDG_CONFIG_HOME"), configFileName)

if homeDir, err := homedir.Dir(); err == nil {
if homeDir, err := os.UserHomeDir(); err == nil {
homeDirFile = filepath.Join(homeDir, configFileName)
}

Expand Down
16 changes: 12 additions & 4 deletions cli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package cli
import (
"os"
"path/filepath"
"runtime"
"testing"

"github.com/mitchellh/go-homedir"
"github.com/spf13/afero"
)

func TestMain(m *testing.M) {
os.Unsetenv("HOME")
os.Unsetenv("USERPROFILE")
os.Unsetenv("XDG_CONFIG_HOME")
AppFs = afero.NewMemMapFs()
homedir.DisableCache = true
os.Exit(m.Run())
}

Expand All @@ -32,7 +32,7 @@ func TestXDGConfigDirIsPreferredFirst(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", xdgDirPath)

afero.WriteFile(AppFs, filepath.Join(homeDirPath, "revive.toml"), []byte("\n"), 0644)
t.Setenv("HOME", homeDirPath)
setHome(t, homeDirPath)

got := buildDefaultConfigPath()
want := filepath.Join(xdgDirPath, "revive.toml")
Expand All @@ -48,7 +48,7 @@ func TestHomeConfigDir(t *testing.T) {
AppFs.MkdirAll(homeDirPath, 0755)

afero.WriteFile(AppFs, filepath.Join(homeDirPath, "revive.toml"), []byte("\n"), 0644)
t.Setenv("HOME", homeDirPath)
setHome(t, homeDirPath)

got := buildDefaultConfigPath()
want := filepath.Join(homeDirPath, "revive.toml")
Expand All @@ -58,6 +58,14 @@ func TestHomeConfigDir(t *testing.T) {
}
}

func setHome(t *testing.T, dir string) {
homeEnv := "HOME"
if runtime.GOOS == "windows" {
homeEnv = "USERPROFILE"
}
t.Setenv(homeEnv, dir)
}

func TestXDGConfigDir(t *testing.T) {
t.Cleanup(func() { AppFs = afero.NewMemMapFs() })
xdgDirPath := filepath.FromSlash("/tmp-iofs/xdg/config")
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/fatih/structtag v1.2.0
github.com/hashicorp/go-version v1.7.0
github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517
github.com/mitchellh/go-homedir v1.1.0
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/afero v1.11.0
golang.org/x/mod v0.22.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6T
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517 h1:zpIH83+oKzcpryru8ceC6BxnoG8TBrhgAvRg8obzup0=
github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517/go.mod h1:KQ7+USdGKfpPjXk4Ga+5XxQM4Lm4e3gAogrreFAYpOg=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
Loading