Skip to content

Commit e7b8fb9

Browse files
committed
Add support for home directory expansion for -c/--config flag
This change introduces the ability to use the tilde (`~`) character in your `-c/--config` flag value to expand your home directory. If invoking this via the command line with `--config ~/.golangci-lint.yaml`, the user's shell expands the `~` to the home directory. However, if something is invoking the program for you (like an editor) it may not do the expansion. Fixes #289 Signed-off-by: Tim Heckman <[email protected]>
1 parent 898ae4d commit e7b8fb9

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ require (
4545
github.com/magiconair/properties v1.7.6 // indirect
4646
github.com/mattn/go-colorable v0.0.9
4747
github.com/mattn/go-isatty v0.0.3 // indirect
48+
github.com/mitchellh/go-homedir v1.0.0
4849
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936
4950
github.com/mitchellh/mapstructure v0.0.0-20180220230111-00c29f56e238 // indirect
5051
github.com/nbutton23/zxcvbn-go v0.0.0-20171102151520-eafdab6b0663 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRU
9595
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
9696
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
9797
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
98+
github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0=
99+
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
98100
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936 h1:kw1v0NlnN+GZcU8Ma8CLF2Zzgjfx95gs3/GN3vYAPpo=
99101
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936/go.mod h1:r1VsdOzOPt1ZSrGZWFoNhsAedKnEd6r9Np1+5blZCWk=
100102
github.com/mitchellh/mapstructure v0.0.0-20180220230111-00c29f56e238 h1:+MZW2uvHgN8kYvksEN3f7eFL2wpzk0GxmlFsMybWc7E=

pkg/config/reader.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111

1212
"github.com/golangci/golangci-lint/pkg/fsutils"
1313
"github.com/golangci/golangci-lint/pkg/logutils"
14+
15+
"github.com/mitchellh/go-homedir"
1416
)
1517

1618
type FileReader struct {
@@ -183,5 +185,10 @@ func (r *FileReader) parseConfigOption() (string, error) {
183185
return "", errConfigDisabled
184186
}
185187

188+
configFile, err := homedir.Expand(configFile)
189+
if err != nil {
190+
return "", fmt.Errorf("failed to expand configuration path")
191+
}
192+
186193
return configFile, nil
187194
}

0 commit comments

Comments
 (0)