enable ginkgolinter linter (#948)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
Matthieu MOREL 2023-04-04 08:52:59 +02:00 committed by GitHub
parent 780ebd0819
commit 68b520165d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 40 deletions

View file

@ -9,6 +9,7 @@ linters:
- errorlint - errorlint
- exportloopref - exportloopref
- gci - gci
- ginkgolinter
- gofmt - gofmt
- gofumpt - gofumpt
- goimports - goimports

View file

@ -36,7 +36,7 @@ var _ = Describe("Analyzer", func() {
err = analyzer.Process(buildTags, dir) err = analyzer.Process(buildTags, dir)
Expect(err).ShouldNot(HaveOccurred()) Expect(err).ShouldNot(HaveOccurred())
_, _, errors := analyzer.Report() _, _, errors := analyzer.Report()
Expect(len(errors)).To(Equal(0)) Expect(errors).To(BeEmpty())
}) })
It("should report an error if the package fails to build", func() { It("should report an error if the package fails to build", func() {
@ -49,9 +49,9 @@ var _ = Describe("Analyzer", func() {
err = analyzer.Process(buildTags, pkg.Path) err = analyzer.Process(buildTags, pkg.Path)
Expect(err).ShouldNot(HaveOccurred()) Expect(err).ShouldNot(HaveOccurred())
_, _, errors := analyzer.Report() _, _, errors := analyzer.Report()
Expect(len(errors)).To(Equal(1)) Expect(errors).To(HaveLen(1))
for _, ferr := range errors { for _, ferr := range errors {
Expect(len(ferr)).To(Equal(1)) Expect(ferr).To(HaveLen(1))
} }
}) })
@ -155,7 +155,7 @@ var _ = Describe("Analyzer", func() {
_, _, errors := analyzer.Report() _, _, errors := analyzer.Report()
foundErr := false foundErr := false
for _, ferr := range errors { for _, ferr := range errors {
Expect(len(ferr)).To(Equal(1)) Expect(ferr).To(HaveLen(1))
match, err := regexp.MatchString(ferr[0].Err, `expected declaration, found '}'`) match, err := regexp.MatchString(ferr[0].Err, `expected declaration, found '}'`)
if !match || err != nil { if !match || err != nil {
continue continue
@ -420,7 +420,7 @@ var _ = Describe("Analyzer", func() {
err = customAnalyzer.Process(buildTags, nosecPackage.Path) err = customAnalyzer.Process(buildTags, nosecPackage.Path)
Expect(err).ShouldNot(HaveOccurred()) Expect(err).ShouldNot(HaveOccurred())
nosecIssues, _, _ := customAnalyzer.Report() nosecIssues, _, _ := customAnalyzer.Report()
Expect(nosecIssues).Should(HaveLen(0)) Expect(nosecIssues).Should(BeEmpty())
}) })
It("should ignore vulnerabilities when the default tag is found", func() { It("should ignore vulnerabilities when the default tag is found", func() {
@ -443,7 +443,7 @@ var _ = Describe("Analyzer", func() {
err = customAnalyzer.Process(buildTags, nosecPackage.Path) err = customAnalyzer.Process(buildTags, nosecPackage.Path)
Expect(err).ShouldNot(HaveOccurred()) Expect(err).ShouldNot(HaveOccurred())
nosecIssues, _, _ := customAnalyzer.Report() nosecIssues, _, _ := customAnalyzer.Report()
Expect(nosecIssues).Should(HaveLen(0)) Expect(nosecIssues).Should(BeEmpty())
}) })
It("should be able to analyze Go test package", func() { It("should be able to analyze Go test package", func() {
@ -511,7 +511,7 @@ var _ = Describe("Analyzer", func() {
err = customAnalyzer.Process(buildTags, pkg.Path) err = customAnalyzer.Process(buildTags, pkg.Path)
Expect(err).ShouldNot(HaveOccurred()) Expect(err).ShouldNot(HaveOccurred())
issues, _, _ := customAnalyzer.Report() issues, _, _ := customAnalyzer.Report()
Expect(issues).Should(HaveLen(0)) Expect(issues).Should(BeEmpty())
}) })
}) })
It("should be able to analyze Cgo files", func() { It("should be able to analyze Cgo files", func() {
@ -527,7 +527,7 @@ var _ = Describe("Analyzer", func() {
err = analyzer.Process(buildTags, testPackage.Path) err = analyzer.Process(buildTags, testPackage.Path)
Expect(err).ShouldNot(HaveOccurred()) Expect(err).ShouldNot(HaveOccurred())
issues, _, _ := analyzer.Report() issues, _, _ := analyzer.Report()
Expect(issues).Should(HaveLen(0)) Expect(issues).Should(BeEmpty())
}) })
Context("when parsing errors from a package", func() { Context("when parsing errors from a package", func() {
@ -549,9 +549,9 @@ var _ = Describe("Analyzer", func() {
err := analyzer.ParseErrors(pkg) err := analyzer.ParseErrors(pkg)
Expect(err).ShouldNot(HaveOccurred()) Expect(err).ShouldNot(HaveOccurred())
_, _, errors := analyzer.Report() _, _, errors := analyzer.Report()
Expect(len(errors)).To(Equal(1)) Expect(errors).To(HaveLen(1))
for _, ferr := range errors { for _, ferr := range errors {
Expect(len(ferr)).To(Equal(1)) Expect(ferr).To(HaveLen(1))
Expect(ferr[0].Line).To(Equal(1)) Expect(ferr[0].Line).To(Equal(1))
Expect(ferr[0].Column).To(Equal(2)) Expect(ferr[0].Column).To(Equal(2))
Expect(ferr[0].Err).Should(MatchRegexp(`build error`)) Expect(ferr[0].Err).Should(MatchRegexp(`build error`))
@ -570,9 +570,9 @@ var _ = Describe("Analyzer", func() {
err := analyzer.ParseErrors(pkg) err := analyzer.ParseErrors(pkg)
Expect(err).ShouldNot(HaveOccurred()) Expect(err).ShouldNot(HaveOccurred())
_, _, errors := analyzer.Report() _, _, errors := analyzer.Report()
Expect(len(errors)).To(Equal(1)) Expect(errors).To(HaveLen(1))
for _, ferr := range errors { for _, ferr := range errors {
Expect(len(ferr)).To(Equal(1)) Expect(ferr).To(HaveLen(1))
Expect(ferr[0].Line).To(Equal(0)) Expect(ferr[0].Line).To(Equal(0))
Expect(ferr[0].Column).To(Equal(0)) Expect(ferr[0].Column).To(Equal(0))
Expect(ferr[0].Err).Should(MatchRegexp(`build error`)) Expect(ferr[0].Err).Should(MatchRegexp(`build error`))
@ -591,9 +591,9 @@ var _ = Describe("Analyzer", func() {
err := analyzer.ParseErrors(pkg) err := analyzer.ParseErrors(pkg)
Expect(err).ShouldNot(HaveOccurred()) Expect(err).ShouldNot(HaveOccurred())
_, _, errors := analyzer.Report() _, _, errors := analyzer.Report()
Expect(len(errors)).To(Equal(1)) Expect(errors).To(HaveLen(1))
for _, ferr := range errors { for _, ferr := range errors {
Expect(len(ferr)).To(Equal(1)) Expect(ferr).To(HaveLen(1))
Expect(ferr[0].Line).To(Equal(0)) Expect(ferr[0].Line).To(Equal(0))
Expect(ferr[0].Column).To(Equal(0)) Expect(ferr[0].Column).To(Equal(0))
Expect(ferr[0].Err).Should(MatchRegexp(`build error`)) Expect(ferr[0].Err).Should(MatchRegexp(`build error`))
@ -642,9 +642,9 @@ var _ = Describe("Analyzer", func() {
err := analyzer.ParseErrors(pkg) err := analyzer.ParseErrors(pkg)
Expect(err).ShouldNot(HaveOccurred()) Expect(err).ShouldNot(HaveOccurred())
_, _, errors := analyzer.Report() _, _, errors := analyzer.Report()
Expect(len(errors)).To(Equal(1)) Expect(errors).To(HaveLen(1))
for _, ferr := range errors { for _, ferr := range errors {
Expect(len(ferr)).To(Equal(2)) Expect(ferr).To(HaveLen(2))
Expect(ferr[0].Line).To(Equal(1)) Expect(ferr[0].Line).To(Equal(1))
Expect(ferr[0].Column).To(Equal(2)) Expect(ferr[0].Column).To(Equal(2))
Expect(ferr[0].Err).Should(MatchRegexp(`error1`)) Expect(ferr[0].Err).Should(MatchRegexp(`error1`))
@ -675,7 +675,7 @@ var _ = Describe("Analyzer", func() {
It("should skip error for non-buildable packages", func() { It("should skip error for non-buildable packages", func() {
analyzer.AppendError("test", errors.New(`loading file from package "pkg/test": no buildable Go source files in pkg/test`)) analyzer.AppendError("test", errors.New(`loading file from package "pkg/test": no buildable Go source files in pkg/test`))
_, _, errors := analyzer.Report() _, _, errors := analyzer.Report()
Expect(len(errors)).To(Equal(0)) Expect(errors).To(BeEmpty())
}) })
It("should add a new error", func() { It("should add a new error", func() {
@ -691,9 +691,9 @@ var _ = Describe("Analyzer", func() {
Expect(err).ShouldNot(HaveOccurred()) Expect(err).ShouldNot(HaveOccurred())
analyzer.AppendError("file", errors.New("file build error")) analyzer.AppendError("file", errors.New("file build error"))
_, _, errors := analyzer.Report() _, _, errors := analyzer.Report()
Expect(len(errors)).To(Equal(1)) Expect(errors).To(HaveLen(1))
for _, ferr := range errors { for _, ferr := range errors {
Expect(len(ferr)).To(Equal(2)) Expect(ferr).To(HaveLen(2))
} }
}) })
}) })

View file

@ -21,7 +21,7 @@ var _ = Describe("Call List", func() {
}) })
It("should be possible to add a single call", func() { It("should be possible to add a single call", func() {
Expect(calls).Should(HaveLen(0)) Expect(calls).Should(BeEmpty())
calls.Add("foo", "bar") calls.Add("foo", "bar")
Expect(calls).Should(HaveLen(1)) Expect(calls).Should(HaveLen(1))
@ -32,7 +32,7 @@ var _ = Describe("Call List", func() {
}) })
It("should be possible to add multiple calls at once", func() { It("should be possible to add multiple calls at once", func() {
Expect(calls).Should(HaveLen(0)) Expect(calls).Should(BeEmpty())
calls.AddAll("fmt", "Sprint", "Sprintf", "Printf", "Println") calls.AddAll("fmt", "Sprint", "Sprintf", "Printf", "Println")
expected := map[string]bool{ expected := map[string]bool{
@ -46,14 +46,14 @@ var _ = Describe("Call List", func() {
}) })
It("should be possible to add pointer call", func() { It("should be possible to add pointer call", func() {
Expect(calls).Should(HaveLen(0)) Expect(calls).Should(BeEmpty())
calls.Add("*bytes.Buffer", "WriteString") calls.Add("*bytes.Buffer", "WriteString")
actual := calls.ContainsPointer("*bytes.Buffer", "WriteString") actual := calls.ContainsPointer("*bytes.Buffer", "WriteString")
Expect(actual).Should(BeTrue()) Expect(actual).Should(BeTrue())
}) })
It("should be possible to check pointer call", func() { It("should be possible to check pointer call", func() {
Expect(calls).Should(HaveLen(0)) Expect(calls).Should(BeEmpty())
calls.Add("bytes.Buffer", "WriteString") calls.Add("bytes.Buffer", "WriteString")
actual := calls.ContainsPointer("*bytes.Buffer", "WriteString") actual := calls.ContainsPointer("*bytes.Buffer", "WriteString")
Expect(actual).Should(BeTrue()) Expect(actual).Should(BeTrue())

View file

@ -77,7 +77,7 @@ var _ = Describe("Configuration", func() {
Context("when using global configuration options", func() { Context("when using global configuration options", func() {
It("should have a default global section", func() { It("should have a default global section", func() {
settings, err := configuration.Get("global") settings, err := configuration.Get("global")
Expect(err).Should(BeNil()) Expect(err).ShouldNot(HaveOccurred())
expectedType := make(map[gosec.GlobalOption]string) expectedType := make(map[gosec.GlobalOption]string)
Expect(settings).Should(BeAssignableToTypeOf(expectedType)) Expect(settings).Should(BeAssignableToTypeOf(expectedType))
}) })
@ -85,7 +85,7 @@ var _ = Describe("Configuration", func() {
It("should save global settings to correct section", func() { It("should save global settings to correct section", func() {
configuration.SetGlobal(gosec.Nosec, "enabled") configuration.SetGlobal(gosec.Nosec, "enabled")
settings, err := configuration.Get("global") settings, err := configuration.Get("global")
Expect(err).Should(BeNil()) Expect(err).ShouldNot(HaveOccurred())
if globals, ok := settings.(map[gosec.GlobalOption]string); ok { if globals, ok := settings.(map[gosec.GlobalOption]string); ok {
Expect(globals["nosec"]).Should(MatchRegexp("enabled")) Expect(globals["nosec"]).Should(MatchRegexp("enabled"))
} else { } else {
@ -93,14 +93,14 @@ var _ = Describe("Configuration", func() {
} }
setValue, err := configuration.GetGlobal(gosec.Nosec) setValue, err := configuration.GetGlobal(gosec.Nosec)
Expect(err).Should(BeNil()) Expect(err).ShouldNot(HaveOccurred())
Expect(setValue).Should(MatchRegexp("enabled")) Expect(setValue).Should(MatchRegexp("enabled"))
}) })
It("should find global settings which are enabled", func() { It("should find global settings which are enabled", func() {
configuration.SetGlobal(gosec.Nosec, "enabled") configuration.SetGlobal(gosec.Nosec, "enabled")
enabled, err := configuration.IsGlobalEnabled(gosec.Nosec) enabled, err := configuration.IsGlobalEnabled(gosec.Nosec)
Expect(err).Should(BeNil()) Expect(err).ShouldNot(HaveOccurred())
Expect(enabled).Should(BeTrue()) Expect(enabled).Should(BeTrue())
}) })
@ -113,10 +113,10 @@ var _ = Describe("Configuration", func() {
}` }`
cfg := gosec.NewConfig() cfg := gosec.NewConfig()
_, err := cfg.ReadFrom(strings.NewReader(config)) _, err := cfg.ReadFrom(strings.NewReader(config))
Expect(err).Should(BeNil()) Expect(err).ShouldNot(HaveOccurred())
value, err := cfg.GetGlobal(gosec.Nosec) value, err := cfg.GetGlobal(gosec.Nosec)
Expect(err).Should(BeNil()) Expect(err).ShouldNot(HaveOccurred())
Expect(value).Should(Equal("enabled")) Expect(value).Should(Equal("enabled"))
}) })
It("should parse the global settings of other types from file", func() { It("should parse the global settings of other types from file", func() {
@ -128,10 +128,10 @@ var _ = Describe("Configuration", func() {
}` }`
cfg := gosec.NewConfig() cfg := gosec.NewConfig()
_, err := cfg.ReadFrom(strings.NewReader(config)) _, err := cfg.ReadFrom(strings.NewReader(config))
Expect(err).Should(BeNil()) Expect(err).ShouldNot(HaveOccurred())
value, err := cfg.GetGlobal(gosec.Nosec) value, err := cfg.GetGlobal(gosec.Nosec)
Expect(err).Should(BeNil()) Expect(err).ShouldNot(HaveOccurred())
Expect(value).Should(Equal("true")) Expect(value).Should(Equal("true"))
}) })
}) })

View file

@ -18,7 +18,7 @@ var _ = Describe("Cli", func() {
flag.Var(&f, "test1", "") flag.Var(&f, "test1", "")
flag.CommandLine.Init("test1", flag.ContinueOnError) flag.CommandLine.Init("test1", flag.ContinueOnError)
flag.Parse() flag.Parse()
Expect(flag.Parsed()).Should(Equal(true)) Expect(flag.Parsed()).Should(BeTrue())
Expect(f.Value).Should(Equal(``)) Expect(f.Value).Should(Equal(``))
}) })
It("value must be empty as parameter value contains invalid character without equal sign", func() { It("value must be empty as parameter value contains invalid character without equal sign", func() {
@ -27,7 +27,7 @@ var _ = Describe("Cli", func() {
flag.Var(&f, "test2", "") flag.Var(&f, "test2", "")
flag.CommandLine.Init("test2", flag.ContinueOnError) flag.CommandLine.Init("test2", flag.ContinueOnError)
flag.Parse() flag.Parse()
Expect(flag.Parsed()).Should(Equal(true)) Expect(flag.Parsed()).Should(BeTrue())
Expect(f.Value).Should(Equal(``)) Expect(f.Value).Should(Equal(``))
}) })
It("value must not be empty as parameter value contains valid character", func() { It("value must not be empty as parameter value contains valid character", func() {
@ -36,7 +36,7 @@ var _ = Describe("Cli", func() {
flag.Var(&f, "test3", "") flag.Var(&f, "test3", "")
flag.CommandLine.Init("test3", flag.ContinueOnError) flag.CommandLine.Init("test3", flag.ContinueOnError)
flag.Parse() flag.Parse()
Expect(flag.Parsed()).Should(Equal(true)) Expect(flag.Parsed()).Should(BeTrue())
Expect(f.Value).Should(Equal(`correct`)) Expect(f.Value).Should(Equal(`correct`))
}) })
}) })

View file

@ -91,7 +91,7 @@ var _ = Describe("Helpers", func() {
Context("when excluding the dirs", func() { Context("when excluding the dirs", func() {
It("should create a proper regexp", func() { It("should create a proper regexp", func() {
r := gosec.ExcludedDirsRegExp([]string{"test"}) r := gosec.ExcludedDirsRegExp([]string{"test"})
Expect(len(r)).Should(Equal(1)) Expect(r).Should(HaveLen(1))
match := r[0].MatchString("/home/go/src/project/test/pkg") match := r[0].MatchString("/home/go/src/project/test/pkg")
Expect(match).Should(BeTrue()) Expect(match).Should(BeTrue())
match = r[0].MatchString("/home/go/src/project/vendor/pkg") match = r[0].MatchString("/home/go/src/project/vendor/pkg")
@ -100,7 +100,7 @@ var _ = Describe("Helpers", func() {
It("should create a proper regexp for dir with subdir", func() { It("should create a proper regexp for dir with subdir", func() {
r := gosec.ExcludedDirsRegExp([]string{`test/generated`}) r := gosec.ExcludedDirsRegExp([]string{`test/generated`})
Expect(len(r)).Should(Equal(1)) Expect(r).Should(HaveLen(1))
match := r[0].MatchString("/home/go/src/project/test/generated") match := r[0].MatchString("/home/go/src/project/test/generated")
Expect(match).Should(BeTrue()) Expect(match).Should(BeTrue())
match = r[0].MatchString("/home/go/src/project/test/pkg") match = r[0].MatchString("/home/go/src/project/test/pkg")
@ -111,9 +111,9 @@ var _ = Describe("Helpers", func() {
It("should create no regexp when dir list is empty", func() { It("should create no regexp when dir list is empty", func() {
r := gosec.ExcludedDirsRegExp(nil) r := gosec.ExcludedDirsRegExp(nil)
Expect(len(r)).Should(Equal(0)) Expect(r).Should(BeEmpty())
r = gosec.ExcludedDirsRegExp([]string{}) r = gosec.ExcludedDirsRegExp([]string{})
Expect(len(r)).Should(Equal(0)) Expect(r).Should(BeEmpty())
}) })
}) })
@ -281,7 +281,7 @@ var _ = Describe("Helpers", func() {
ast.Walk(visitor, ctx.Root) ast.Walk(visitor, ctx.Root)
operands := gosec.GetBinaryExprOperands(be) operands := gosec.GetBinaryExprOperands(be)
Expect(len(operands)).Should(Equal(2)) Expect(operands).Should(HaveLen(2))
}) })
It("should return all operands of complex binary expression", func() { It("should return all operands of complex binary expression", func() {
pkg := testutils.NewTestPackage() pkg := testutils.NewTestPackage()
@ -313,7 +313,7 @@ var _ = Describe("Helpers", func() {
ast.Walk(visitor, ctx.Root) ast.Walk(visitor, ctx.Root)
operands := gosec.GetBinaryExprOperands(be) operands := gosec.GetBinaryExprOperands(be)
Expect(len(operands)).Should(Equal(4)) Expect(operands).Should(HaveLen(4))
}) })
}) })
}) })