Skip to content

Commit 4ca2c11

Browse files
authored
refactor: get rid of mitchellh/go-homedir package (#1195)
1 parent 7998011 commit 4ca2c11

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

cli/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/fatih/color"
1313
"github.com/mgechev/revive/config"
1414
"github.com/mgechev/revive/revivelib"
15-
"github.com/mitchellh/go-homedir"
1615
"github.com/spf13/afero"
1716
)
1817

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

131-
if homeDir, err := homedir.Dir(); err == nil {
130+
if homeDir, err := os.UserHomeDir(); err == nil {
132131
homeDirFile = filepath.Join(homeDir, configFileName)
133132
}
134133

cli/main_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ package cli
33
import (
44
"os"
55
"path/filepath"
6+
"runtime"
67
"testing"
78

8-
"github.com/mitchellh/go-homedir"
99
"github.com/spf13/afero"
1010
)
1111

1212
func TestMain(m *testing.M) {
1313
os.Unsetenv("HOME")
14+
os.Unsetenv("USERPROFILE")
1415
os.Unsetenv("XDG_CONFIG_HOME")
1516
AppFs = afero.NewMemMapFs()
16-
homedir.DisableCache = true
1717
os.Exit(m.Run())
1818
}
1919

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

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

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

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

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

61+
func setHome(t *testing.T, dir string) {
62+
homeEnv := "HOME"
63+
if runtime.GOOS == "windows" {
64+
homeEnv = "USERPROFILE"
65+
}
66+
t.Setenv(homeEnv, dir)
67+
}
68+
6169
func TestXDGConfigDir(t *testing.T) {
6270
t.Cleanup(func() { AppFs = afero.NewMemMapFs() })
6371
xdgDirPath := filepath.FromSlash("/tmp-iofs/xdg/config")

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ require (
99
github.com/fatih/structtag v1.2.0
1010
github.com/hashicorp/go-version v1.7.0
1111
github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517
12-
github.com/mitchellh/go-homedir v1.1.0
1312
github.com/olekukonko/tablewriter v0.0.5
1413
github.com/spf13/afero v1.11.0
1514
golang.org/x/mod v0.22.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6T
2121
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
2222
github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517 h1:zpIH83+oKzcpryru8ceC6BxnoG8TBrhgAvRg8obzup0=
2323
github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517/go.mod h1:KQ7+USdGKfpPjXk4Ga+5XxQM4Lm4e3gAogrreFAYpOg=
24-
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
25-
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
2624
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
2725
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
2826
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

0 commit comments

Comments
 (0)