From de3045325abca6f4ec4aff60e4aee41683983a9a Mon Sep 17 00:00:00 2001 From: Joe Fitzgerald Date: Fri, 17 Nov 2023 13:17:25 -0700 Subject: [PATCH] address lint warnings Signed-off-by: Joe Fitzgerald --- .golangci.yaml | 3 +++ generated_fakes_test.go | 12 ++++++------ generator/interface_template.go | 7 ++++++- go.mod | 2 +- integration/copy_test.go | 12 ++++++++++-- main.go | 2 +- 6 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 .golangci.yaml diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 00000000..1f2afa43 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,3 @@ +run: + skip-dirs: + - fixtures \ No newline at end of file diff --git a/generated_fakes_test.go b/generated_fakes_test.go index ff719438..e1e3d6a0 100644 --- a/generated_fakes_test.go +++ b/generated_fakes_test.go @@ -76,7 +76,7 @@ func testFakes(t *testing.T, when spec.G, it spec.S) { it("records the arguments it was called with", func() { Expect(fake.DoThingsCallCount()).To(Equal(0)) - fake.DoThings("stuff", 5) + _, _ = fake.DoThings("stuff", 5) Expect(fake.DoThingsCallCount()).To(Equal(1)) arg1, arg2 := fake.DoThingsArgsForCall(0) @@ -147,7 +147,7 @@ func testFakes(t *testing.T, when spec.G, it spec.S) { Expect(len(fake.Invocations()["DoASlice"])).To(Equal(0)) Expect(len(fake.Invocations()["DoAnArray"])).To(Equal(0)) - fake.DoThings("hello", 0) + _, _ = fake.DoThings("hello", 0) Expect(len(fake.Invocations()["DoThings"])).To(Equal(1)) Expect(fake.Invocations()["DoThings"][0][0]).To(Equal("hello")) Expect(fake.Invocations()["DoThings"][0][1]).To(Equal(uint64(0))) @@ -190,7 +190,7 @@ func testFakes(t *testing.T, when spec.G, it spec.S) { go fake.DoNothing() <-start1 - go fake.DoThings("abc", 1) + go func() { _, _ = fake.DoThings("abc", 1) }() <-start2 }) @@ -211,7 +211,7 @@ func testFakes(t *testing.T, when spec.G, it spec.S) { when("when methods are called concurrently", func() { it.Before(func() { go fake.DoNothing() - go fake.DoThings("", 0) + go func() { _, _ = fake.DoThings("", 0) }() }) it("records the call count without race conditions", func() { @@ -297,9 +297,9 @@ func testFakes(t *testing.T, when spec.G, it spec.S) { it("succeeds and does not cause a data race", func() { go fake.DoThingsReturns(1, nil) - go fake.DoThings("1", 1) + go func() { _, _ = fake.DoThings("1", 1) }() go fake.DoThingsReturns(1, nil) - go fake.DoThings("1", 1) + go func() { _, _ = fake.DoThings("1", 1) }() }) }) } diff --git a/generator/interface_template.go b/generator/interface_template.go index b569bdf7..1a8fde9b 100644 --- a/generator/interface_template.go +++ b/generator/interface_template.go @@ -3,14 +3,19 @@ package generator import ( "strings" "text/template" + + "golang.org/x/text/cases" + "golang.org/x/text/language" ) +var title = cases.Title(language.Und, cases.NoLower) + var interfaceFuncs = template.FuncMap{ "ToLower": strings.ToLower, "UnExport": unexport, "Replace": strings.Replace, "IsExported": isExported, - "Title": strings.Title, + "Title": title.String, } const interfaceTemplate string = `{{.Header}}// Code generated by counterfeiter. DO NOT EDIT. diff --git a/go.mod b/go.mod index 94a231ba..150df6d5 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/maxbrunsfeld/counterfeiter/v6 require ( github.com/onsi/gomega v1.30.0 github.com/sclevine/spec v1.4.0 + golang.org/x/text v0.14.0 golang.org/x/tools v0.15.0 ) @@ -11,7 +12,6 @@ require ( golang.org/x/mod v0.14.0 // indirect golang.org/x/net v0.18.0 // indirect golang.org/x/sys v0.14.0 // indirect - golang.org/x/text v0.14.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/integration/copy_test.go b/integration/copy_test.go index 9d14a5b1..9c9a7e81 100644 --- a/integration/copy_test.go +++ b/integration/copy_test.go @@ -2,7 +2,7 @@ package integration_test import ( "io" - "io/ioutil" + "io/fs" "os" "path/filepath" "strings" @@ -69,10 +69,18 @@ func dcopy(srcdir, destdir string, info os.FileInfo) error { return err } - contents, err := ioutil.ReadDir(srcdir) + entries, err := os.ReadDir(srcdir) if err != nil { return err } + contents := make([]fs.FileInfo, 0, len(entries)) + for _, entry := range entries { + info, err := entry.Info() + if err != nil { + return err + } + contents = append(contents, info) + } for _, content := range contents { cs, cd := filepath.Join(srcdir, content.Name()), filepath.Join(destdir, content.Name()) diff --git a/main.go b/main.go index b9b84ce9..fcaf995a 100644 --- a/main.go +++ b/main.go @@ -174,7 +174,7 @@ func printCode(code []byte, outputPath string, printToStdOut bool) error { fmt.Println(string(formattedCode)) return nil } - os.MkdirAll(filepath.Dir(outputPath), 0777) + _ = os.MkdirAll(filepath.Dir(outputPath), 0777) file, err := os.Create(outputPath) if err != nil { return fmt.Errorf("Couldn't create fake file - %v", err)