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
- exportloopref
- gci
- ginkgolinter
- gofmt
- gofumpt
- goimports

View file

@ -36,7 +36,7 @@ var _ = Describe("Analyzer", func() {
err = analyzer.Process(buildTags, dir)
Expect(err).ShouldNot(HaveOccurred())
_, _, 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() {
@ -49,9 +49,9 @@ var _ = Describe("Analyzer", func() {
err = analyzer.Process(buildTags, pkg.Path)
Expect(err).ShouldNot(HaveOccurred())
_, _, errors := analyzer.Report()
Expect(len(errors)).To(Equal(1))
Expect(errors).To(HaveLen(1))
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()
foundErr := false
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 '}'`)
if !match || err != nil {
continue
@ -420,7 +420,7 @@ var _ = Describe("Analyzer", func() {
err = customAnalyzer.Process(buildTags, nosecPackage.Path)
Expect(err).ShouldNot(HaveOccurred())
nosecIssues, _, _ := customAnalyzer.Report()
Expect(nosecIssues).Should(HaveLen(0))
Expect(nosecIssues).Should(BeEmpty())
})
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)
Expect(err).ShouldNot(HaveOccurred())
nosecIssues, _, _ := customAnalyzer.Report()
Expect(nosecIssues).Should(HaveLen(0))
Expect(nosecIssues).Should(BeEmpty())
})
It("should be able to analyze Go test package", func() {
@ -511,7 +511,7 @@ var _ = Describe("Analyzer", func() {
err = customAnalyzer.Process(buildTags, pkg.Path)
Expect(err).ShouldNot(HaveOccurred())
issues, _, _ := customAnalyzer.Report()
Expect(issues).Should(HaveLen(0))
Expect(issues).Should(BeEmpty())
})
})
It("should be able to analyze Cgo files", func() {
@ -527,7 +527,7 @@ var _ = Describe("Analyzer", func() {
err = analyzer.Process(buildTags, testPackage.Path)
Expect(err).ShouldNot(HaveOccurred())
issues, _, _ := analyzer.Report()
Expect(issues).Should(HaveLen(0))
Expect(issues).Should(BeEmpty())
})
Context("when parsing errors from a package", func() {
@ -549,9 +549,9 @@ var _ = Describe("Analyzer", func() {
err := analyzer.ParseErrors(pkg)
Expect(err).ShouldNot(HaveOccurred())
_, _, errors := analyzer.Report()
Expect(len(errors)).To(Equal(1))
Expect(errors).To(HaveLen(1))
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].Column).To(Equal(2))
Expect(ferr[0].Err).Should(MatchRegexp(`build error`))
@ -570,9 +570,9 @@ var _ = Describe("Analyzer", func() {
err := analyzer.ParseErrors(pkg)
Expect(err).ShouldNot(HaveOccurred())
_, _, errors := analyzer.Report()
Expect(len(errors)).To(Equal(1))
Expect(errors).To(HaveLen(1))
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].Column).To(Equal(0))
Expect(ferr[0].Err).Should(MatchRegexp(`build error`))
@ -591,9 +591,9 @@ var _ = Describe("Analyzer", func() {
err := analyzer.ParseErrors(pkg)
Expect(err).ShouldNot(HaveOccurred())
_, _, errors := analyzer.Report()
Expect(len(errors)).To(Equal(1))
Expect(errors).To(HaveLen(1))
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].Column).To(Equal(0))
Expect(ferr[0].Err).Should(MatchRegexp(`build error`))
@ -642,9 +642,9 @@ var _ = Describe("Analyzer", func() {
err := analyzer.ParseErrors(pkg)
Expect(err).ShouldNot(HaveOccurred())
_, _, errors := analyzer.Report()
Expect(len(errors)).To(Equal(1))
Expect(errors).To(HaveLen(1))
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].Column).To(Equal(2))
Expect(ferr[0].Err).Should(MatchRegexp(`error1`))
@ -675,7 +675,7 @@ var _ = Describe("Analyzer", 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`))
_, _, errors := analyzer.Report()
Expect(len(errors)).To(Equal(0))
Expect(errors).To(BeEmpty())
})
It("should add a new error", func() {
@ -691,9 +691,9 @@ var _ = Describe("Analyzer", func() {
Expect(err).ShouldNot(HaveOccurred())
analyzer.AppendError("file", errors.New("file build error"))
_, _, errors := analyzer.Report()
Expect(len(errors)).To(Equal(1))
Expect(errors).To(HaveLen(1))
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() {
Expect(calls).Should(HaveLen(0))
Expect(calls).Should(BeEmpty())
calls.Add("foo", "bar")
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() {
Expect(calls).Should(HaveLen(0))
Expect(calls).Should(BeEmpty())
calls.AddAll("fmt", "Sprint", "Sprintf", "Printf", "Println")
expected := map[string]bool{
@ -46,14 +46,14 @@ var _ = Describe("Call List", func() {
})
It("should be possible to add pointer call", func() {
Expect(calls).Should(HaveLen(0))
Expect(calls).Should(BeEmpty())
calls.Add("*bytes.Buffer", "WriteString")
actual := calls.ContainsPointer("*bytes.Buffer", "WriteString")
Expect(actual).Should(BeTrue())
})
It("should be possible to check pointer call", func() {
Expect(calls).Should(HaveLen(0))
Expect(calls).Should(BeEmpty())
calls.Add("bytes.Buffer", "WriteString")
actual := calls.ContainsPointer("*bytes.Buffer", "WriteString")
Expect(actual).Should(BeTrue())

View file

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

View file

@ -18,7 +18,7 @@ var _ = Describe("Cli", func() {
flag.Var(&f, "test1", "")
flag.CommandLine.Init("test1", flag.ContinueOnError)
flag.Parse()
Expect(flag.Parsed()).Should(Equal(true))
Expect(flag.Parsed()).Should(BeTrue())
Expect(f.Value).Should(Equal(``))
})
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.CommandLine.Init("test2", flag.ContinueOnError)
flag.Parse()
Expect(flag.Parsed()).Should(Equal(true))
Expect(flag.Parsed()).Should(BeTrue())
Expect(f.Value).Should(Equal(``))
})
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.CommandLine.Init("test3", flag.ContinueOnError)
flag.Parse()
Expect(flag.Parsed()).Should(Equal(true))
Expect(flag.Parsed()).Should(BeTrue())
Expect(f.Value).Should(Equal(`correct`))
})
})

View file

@ -91,7 +91,7 @@ var _ = Describe("Helpers", func() {
Context("when excluding the dirs", func() {
It("should create a proper regexp", func() {
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")
Expect(match).Should(BeTrue())
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() {
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")
Expect(match).Should(BeTrue())
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() {
r := gosec.ExcludedDirsRegExp(nil)
Expect(len(r)).Should(Equal(0))
Expect(r).Should(BeEmpty())
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)
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() {
pkg := testutils.NewTestPackage()
@ -313,7 +313,7 @@ var _ = Describe("Helpers", func() {
ast.Walk(visitor, ctx.Root)
operands := gosec.GetBinaryExprOperands(be)
Expect(len(operands)).Should(Equal(4))
Expect(operands).Should(HaveLen(4))
})
})
})