From 7dcc05a50e445dd0550ecd0331557d08ae05768a Mon Sep 17 00:00:00 2001 From: Hakan Date: Sun, 26 Dec 2021 11:00:52 +0100 Subject: [PATCH] - fix lints for new version --- .golangci.yml | 1 + go.mod | 1 + go.sum | 3 ++- internal/io/io.go | 4 ++-- internal/provider/bw.go | 2 +- internal/provider/bw_test.go | 4 ++-- internal/provider/error.go | 12 ++++++------ internal/provider/op.go | 2 +- internal/provider/op_test.go | 4 ++-- main.go | 4 ++-- test/error.go | 6 +++--- test/fixture.go | 2 +- test/fixture_test.go | 2 +- 13 files changed, 25 insertions(+), 22 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 02481fd..485c4cd 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -41,3 +41,4 @@ linters: disable: - exhaustivestruct - wrapcheck + - ireturn diff --git a/go.mod b/go.mod index 952c19e..c0a6741 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,7 @@ require ( github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/google/go-cmp v0.5.6 // indirect + github.com/google/uuid v1.3.0 // indirect github.com/googleapis/gax-go/v2 v2.1.1 // indirect github.com/googleapis/google-cloud-go-testing v0.0.0-20210719221736-1c9a4c676720 // indirect github.com/hashicorp/hcl v1.0.0 // indirect diff --git a/go.sum b/go.sum index c72c997..c3585dd 100644 --- a/go.sum +++ b/go.sum @@ -221,8 +221,9 @@ github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/gax-go/v2 v2.1.0/go.mod h1:Q3nei7sK6ybPYH7twZdmQpAd1MKb7pfu6SK+H1/DsU0= diff --git a/internal/io/io.go b/internal/io/io.go index 38c3ab9..1b6d17d 100644 --- a/internal/io/io.go +++ b/internal/io/io.go @@ -27,7 +27,7 @@ func WriteSSHKey(fileName string, data []byte) error { if _, err = os.Stat(sshDirectory); os.IsNotExist(err) { //nolint:gomnd // change this later. - err = os.Mkdir(sshDirectory, os.FileMode(0777)) + err = os.Mkdir(sshDirectory, os.FileMode(0o777)) if err != nil { return err } @@ -36,7 +36,7 @@ func WriteSSHKey(fileName string, data []byte) error { sshPath := filepath.Join(sshDirectory, fileName) //nolint:gomnd // change this later. - err = ioutil.WriteFile(sshPath, data, os.FileMode(0600)) + err = ioutil.WriteFile(sshPath, data, os.FileMode(0o600)) if err != nil { return err } diff --git a/internal/provider/bw.go b/internal/provider/bw.go index d7ce9cb..6aed72c 100644 --- a/internal/provider/bw.go +++ b/internal/provider/bw.go @@ -43,7 +43,7 @@ func (b Bitwarden) GetName() string { func (b Bitwarden) Add(item *Item) error { _, err := b.Get(item.Name) if err == nil { - return ItemAlreadyExists{Name: item.Name} + return ItemAlreadyExistsError{Name: item.Name} } encodedValues, err := item.EncodeValues() diff --git a/internal/provider/bw_test.go b/internal/provider/bw_test.go index 6ed70b2..cc03384 100644 --- a/internal/provider/bw_test.go +++ b/internal/provider/bw_test.go @@ -26,7 +26,7 @@ func TestBitwarden_Add(t *testing.T) { }, } - bw := provider.Bitwarden{ + bitw := provider.Bitwarden{ Commander: internal.Commander{Executor: test.NewExecutor(expectedCommands)}, } @@ -44,7 +44,7 @@ func TestBitwarden_Add(t *testing.T) { }, } - err := bw.Add(&item) + err := bitw.Add(&item) assert.NoError(t, err) } diff --git a/internal/provider/error.go b/internal/provider/error.go index 3972cf2..f8de593 100644 --- a/internal/provider/error.go +++ b/internal/provider/error.go @@ -2,12 +2,12 @@ package provider import "fmt" -// NotFound occurs when no provider found. -type NotFound struct { +// NotFoundError occurs when no provider found. +type NotFoundError struct { Name *string } -func (e NotFound) Error() string { +func (e NotFoundError) Error() string { return fmt.Sprintf("no provider found for %s", *e.Name) } @@ -21,11 +21,11 @@ func (e ExecutionFailedError) Error() string { return fmt.Sprintf("'%s': Execution failed: %s", e.Command, e.Message) } -// ItemAlreadyExists occurs when given item is not found in the provder. -type ItemAlreadyExists struct { +// ItemAlreadyExistsError occurs when given item is not found in the provder. +type ItemAlreadyExistsError struct { Name string } -func (e ItemAlreadyExists) Error() string { +func (e ItemAlreadyExistsError) Error() string { return fmt.Sprintf("item %s already exists", e.Name) } diff --git a/internal/provider/op.go b/internal/provider/op.go index 9967432..15cae00 100644 --- a/internal/provider/op.go +++ b/internal/provider/op.go @@ -52,7 +52,7 @@ func (o OnePassword) GetName() string { func (o OnePassword) Add(item *Item) error { _, err := o.Get(item.Name) if err == nil { - return ItemAlreadyExists{Name: item.Name} + return ItemAlreadyExistsError{Name: item.Name} } encodedValues, err := item.EncodeValues() diff --git a/internal/provider/op_test.go b/internal/provider/op_test.go index 870f14d..2fc2fd0 100644 --- a/internal/provider/op_test.go +++ b/internal/provider/op_test.go @@ -34,7 +34,7 @@ func TestOnePassword_Add(t *testing.T) { }, } - op := provider.OnePassword{ + onep := provider.OnePassword{ Commander: internal.Commander{Executor: test.NewExecutor(expectedCommands)}, } @@ -52,7 +52,7 @@ func TestOnePassword_Add(t *testing.T) { }, } - err := op.Add(&item) + err := onep.Add(&item) assert.NoError(t, err) } diff --git a/main.go b/main.go index bbdcb22..8219f52 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ func main() { SilenceUsage: true, } - c := commander.NewCommander(root). + comm := commander.NewCommander(root). SetCommand( cmd.Version(), cmd.Get(), @@ -26,7 +26,7 @@ func main() { ). Init() - if err := c.Execute(); err != nil { + if err := comm.Execute(); err != nil { os.Exit(1) } } diff --git a/test/error.go b/test/error.go index 7732129..6606a45 100644 --- a/test/error.go +++ b/test/error.go @@ -2,12 +2,12 @@ package test import "fmt" -// FixtureFileNotFound occurs when the requested fixture file does not exist. -type FixtureFileNotFound struct { +// FixtureFileNotFoundError occurs when the requested fixture file does not exist. +type FixtureFileNotFoundError struct { Path string Name string } -func (e FixtureFileNotFound) Error() string { +func (e FixtureFileNotFoundError) Error() string { return fmt.Sprintf("Fixture file does not exist: %s/fixtures/%s", e.Path, e.Name) } diff --git a/test/fixture.go b/test/fixture.go index 183eae5..cafee52 100644 --- a/test/fixture.go +++ b/test/fixture.go @@ -12,7 +12,7 @@ func LoadFixture(name string) ([]byte, error) { if err != nil { path, _ := os.Getwd() - return []byte{}, FixtureFileNotFound{Path: path, Name: name} + return []byte{}, FixtureFileNotFoundError{Path: path, Name: name} } return content, nil diff --git a/test/fixture_test.go b/test/fixture_test.go index f6b94f5..86d8ac9 100644 --- a/test/fixture_test.go +++ b/test/fixture_test.go @@ -35,5 +35,5 @@ func TestMust_hasError(t *testing.T) { } }() - _ = Must([]byte{}, FixtureFileNotFound{Path: "/path", Name: "file"}) + _ = Must([]byte{}, FixtureFileNotFoundError{Path: "/path", Name: "file"}) }