diff --git a/cli/main.go b/cli/main.go index 81c0b5867..98832ebb8 100644 --- a/cli/main.go +++ b/cli/main.go @@ -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" ) @@ -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) } diff --git a/cli/main_test.go b/cli/main_test.go index 6e1eee4d3..173016919 100644 --- a/cli/main_test.go +++ b/cli/main_test.go @@ -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()) } @@ -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") @@ -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") @@ -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") diff --git a/go.mod b/go.mod index ca23cba6c..f51a29d82 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 696de223e..f3ac64639 100644 --- a/go.sum +++ b/go.sum @@ -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=