Skip to content

Commit 68b5201

Browse files
authored
enable ginkgolinter linter (#948)
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 780ebd0 commit 68b5201

File tree

6 files changed

+41
-40
lines changed

6 files changed

+41
-40
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ linters:
99
- errorlint
1010
- exportloopref
1111
- gci
12+
- ginkgolinter
1213
- gofmt
1314
- gofumpt
1415
- goimports

analyzer_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var _ = Describe("Analyzer", func() {
3636
err = analyzer.Process(buildTags, dir)
3737
Expect(err).ShouldNot(HaveOccurred())
3838
_, _, errors := analyzer.Report()
39-
Expect(len(errors)).To(Equal(0))
39+
Expect(errors).To(BeEmpty())
4040
})
4141

4242
It("should report an error if the package fails to build", func() {
@@ -49,9 +49,9 @@ var _ = Describe("Analyzer", func() {
4949
err = analyzer.Process(buildTags, pkg.Path)
5050
Expect(err).ShouldNot(HaveOccurred())
5151
_, _, errors := analyzer.Report()
52-
Expect(len(errors)).To(Equal(1))
52+
Expect(errors).To(HaveLen(1))
5353
for _, ferr := range errors {
54-
Expect(len(ferr)).To(Equal(1))
54+
Expect(ferr).To(HaveLen(1))
5555
}
5656
})
5757

@@ -155,7 +155,7 @@ var _ = Describe("Analyzer", func() {
155155
_, _, errors := analyzer.Report()
156156
foundErr := false
157157
for _, ferr := range errors {
158-
Expect(len(ferr)).To(Equal(1))
158+
Expect(ferr).To(HaveLen(1))
159159
match, err := regexp.MatchString(ferr[0].Err, `expected declaration, found '}'`)
160160
if !match || err != nil {
161161
continue
@@ -420,7 +420,7 @@ var _ = Describe("Analyzer", func() {
420420
err = customAnalyzer.Process(buildTags, nosecPackage.Path)
421421
Expect(err).ShouldNot(HaveOccurred())
422422
nosecIssues, _, _ := customAnalyzer.Report()
423-
Expect(nosecIssues).Should(HaveLen(0))
423+
Expect(nosecIssues).Should(BeEmpty())
424424
})
425425

426426
It("should ignore vulnerabilities when the default tag is found", func() {
@@ -443,7 +443,7 @@ var _ = Describe("Analyzer", func() {
443443
err = customAnalyzer.Process(buildTags, nosecPackage.Path)
444444
Expect(err).ShouldNot(HaveOccurred())
445445
nosecIssues, _, _ := customAnalyzer.Report()
446-
Expect(nosecIssues).Should(HaveLen(0))
446+
Expect(nosecIssues).Should(BeEmpty())
447447
})
448448

449449
It("should be able to analyze Go test package", func() {
@@ -511,7 +511,7 @@ var _ = Describe("Analyzer", func() {
511511
err = customAnalyzer.Process(buildTags, pkg.Path)
512512
Expect(err).ShouldNot(HaveOccurred())
513513
issues, _, _ := customAnalyzer.Report()
514-
Expect(issues).Should(HaveLen(0))
514+
Expect(issues).Should(BeEmpty())
515515
})
516516
})
517517
It("should be able to analyze Cgo files", func() {
@@ -527,7 +527,7 @@ var _ = Describe("Analyzer", func() {
527527
err = analyzer.Process(buildTags, testPackage.Path)
528528
Expect(err).ShouldNot(HaveOccurred())
529529
issues, _, _ := analyzer.Report()
530-
Expect(issues).Should(HaveLen(0))
530+
Expect(issues).Should(BeEmpty())
531531
})
532532

533533
Context("when parsing errors from a package", func() {
@@ -549,9 +549,9 @@ var _ = Describe("Analyzer", func() {
549549
err := analyzer.ParseErrors(pkg)
550550
Expect(err).ShouldNot(HaveOccurred())
551551
_, _, errors := analyzer.Report()
552-
Expect(len(errors)).To(Equal(1))
552+
Expect(errors).To(HaveLen(1))
553553
for _, ferr := range errors {
554-
Expect(len(ferr)).To(Equal(1))
554+
Expect(ferr).To(HaveLen(1))
555555
Expect(ferr[0].Line).To(Equal(1))
556556
Expect(ferr[0].Column).To(Equal(2))
557557
Expect(ferr[0].Err).Should(MatchRegexp(`build error`))
@@ -570,9 +570,9 @@ var _ = Describe("Analyzer", func() {
570570
err := analyzer.ParseErrors(pkg)
571571
Expect(err).ShouldNot(HaveOccurred())
572572
_, _, errors := analyzer.Report()
573-
Expect(len(errors)).To(Equal(1))
573+
Expect(errors).To(HaveLen(1))
574574
for _, ferr := range errors {
575-
Expect(len(ferr)).To(Equal(1))
575+
Expect(ferr).To(HaveLen(1))
576576
Expect(ferr[0].Line).To(Equal(0))
577577
Expect(ferr[0].Column).To(Equal(0))
578578
Expect(ferr[0].Err).Should(MatchRegexp(`build error`))
@@ -591,9 +591,9 @@ var _ = Describe("Analyzer", func() {
591591
err := analyzer.ParseErrors(pkg)
592592
Expect(err).ShouldNot(HaveOccurred())
593593
_, _, errors := analyzer.Report()
594-
Expect(len(errors)).To(Equal(1))
594+
Expect(errors).To(HaveLen(1))
595595
for _, ferr := range errors {
596-
Expect(len(ferr)).To(Equal(1))
596+
Expect(ferr).To(HaveLen(1))
597597
Expect(ferr[0].Line).To(Equal(0))
598598
Expect(ferr[0].Column).To(Equal(0))
599599
Expect(ferr[0].Err).Should(MatchRegexp(`build error`))
@@ -642,9 +642,9 @@ var _ = Describe("Analyzer", func() {
642642
err := analyzer.ParseErrors(pkg)
643643
Expect(err).ShouldNot(HaveOccurred())
644644
_, _, errors := analyzer.Report()
645-
Expect(len(errors)).To(Equal(1))
645+
Expect(errors).To(HaveLen(1))
646646
for _, ferr := range errors {
647-
Expect(len(ferr)).To(Equal(2))
647+
Expect(ferr).To(HaveLen(2))
648648
Expect(ferr[0].Line).To(Equal(1))
649649
Expect(ferr[0].Column).To(Equal(2))
650650
Expect(ferr[0].Err).Should(MatchRegexp(`error1`))
@@ -675,7 +675,7 @@ var _ = Describe("Analyzer", func() {
675675
It("should skip error for non-buildable packages", func() {
676676
analyzer.AppendError("test", errors.New(`loading file from package "pkg/test": no buildable Go source files in pkg/test`))
677677
_, _, errors := analyzer.Report()
678-
Expect(len(errors)).To(Equal(0))
678+
Expect(errors).To(BeEmpty())
679679
})
680680

681681
It("should add a new error", func() {
@@ -691,9 +691,9 @@ var _ = Describe("Analyzer", func() {
691691
Expect(err).ShouldNot(HaveOccurred())
692692
analyzer.AppendError("file", errors.New("file build error"))
693693
_, _, errors := analyzer.Report()
694-
Expect(len(errors)).To(Equal(1))
694+
Expect(errors).To(HaveLen(1))
695695
for _, ferr := range errors {
696-
Expect(len(ferr)).To(Equal(2))
696+
Expect(ferr).To(HaveLen(2))
697697
}
698698
})
699699
})

call_list_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var _ = Describe("Call List", func() {
2121
})
2222

2323
It("should be possible to add a single call", func() {
24-
Expect(calls).Should(HaveLen(0))
24+
Expect(calls).Should(BeEmpty())
2525
calls.Add("foo", "bar")
2626
Expect(calls).Should(HaveLen(1))
2727

@@ -32,7 +32,7 @@ var _ = Describe("Call List", func() {
3232
})
3333

3434
It("should be possible to add multiple calls at once", func() {
35-
Expect(calls).Should(HaveLen(0))
35+
Expect(calls).Should(BeEmpty())
3636
calls.AddAll("fmt", "Sprint", "Sprintf", "Printf", "Println")
3737

3838
expected := map[string]bool{
@@ -46,14 +46,14 @@ var _ = Describe("Call List", func() {
4646
})
4747

4848
It("should be possible to add pointer call", func() {
49-
Expect(calls).Should(HaveLen(0))
49+
Expect(calls).Should(BeEmpty())
5050
calls.Add("*bytes.Buffer", "WriteString")
5151
actual := calls.ContainsPointer("*bytes.Buffer", "WriteString")
5252
Expect(actual).Should(BeTrue())
5353
})
5454

5555
It("should be possible to check pointer call", func() {
56-
Expect(calls).Should(HaveLen(0))
56+
Expect(calls).Should(BeEmpty())
5757
calls.Add("bytes.Buffer", "WriteString")
5858
actual := calls.ContainsPointer("*bytes.Buffer", "WriteString")
5959
Expect(actual).Should(BeTrue())

config_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,30 +77,30 @@ var _ = Describe("Configuration", func() {
7777
Context("when using global configuration options", func() {
7878
It("should have a default global section", func() {
7979
settings, err := configuration.Get("global")
80-
Expect(err).Should(BeNil())
80+
Expect(err).ShouldNot(HaveOccurred())
8181
expectedType := make(map[gosec.GlobalOption]string)
8282
Expect(settings).Should(BeAssignableToTypeOf(expectedType))
8383
})
8484

8585
It("should save global settings to correct section", func() {
8686
configuration.SetGlobal(gosec.Nosec, "enabled")
8787
settings, err := configuration.Get("global")
88-
Expect(err).Should(BeNil())
88+
Expect(err).ShouldNot(HaveOccurred())
8989
if globals, ok := settings.(map[gosec.GlobalOption]string); ok {
9090
Expect(globals["nosec"]).Should(MatchRegexp("enabled"))
9191
} else {
9292
Fail("globals are not defined as map")
9393
}
9494

9595
setValue, err := configuration.GetGlobal(gosec.Nosec)
96-
Expect(err).Should(BeNil())
96+
Expect(err).ShouldNot(HaveOccurred())
9797
Expect(setValue).Should(MatchRegexp("enabled"))
9898
})
9999

100100
It("should find global settings which are enabled", func() {
101101
configuration.SetGlobal(gosec.Nosec, "enabled")
102102
enabled, err := configuration.IsGlobalEnabled(gosec.Nosec)
103-
Expect(err).Should(BeNil())
103+
Expect(err).ShouldNot(HaveOccurred())
104104
Expect(enabled).Should(BeTrue())
105105
})
106106

@@ -113,10 +113,10 @@ var _ = Describe("Configuration", func() {
113113
}`
114114
cfg := gosec.NewConfig()
115115
_, err := cfg.ReadFrom(strings.NewReader(config))
116-
Expect(err).Should(BeNil())
116+
Expect(err).ShouldNot(HaveOccurred())
117117

118118
value, err := cfg.GetGlobal(gosec.Nosec)
119-
Expect(err).Should(BeNil())
119+
Expect(err).ShouldNot(HaveOccurred())
120120
Expect(value).Should(Equal("enabled"))
121121
})
122122
It("should parse the global settings of other types from file", func() {
@@ -128,10 +128,10 @@ var _ = Describe("Configuration", func() {
128128
}`
129129
cfg := gosec.NewConfig()
130130
_, err := cfg.ReadFrom(strings.NewReader(config))
131-
Expect(err).Should(BeNil())
131+
Expect(err).ShouldNot(HaveOccurred())
132132

133133
value, err := cfg.GetGlobal(gosec.Nosec)
134-
Expect(err).Should(BeNil())
134+
Expect(err).ShouldNot(HaveOccurred())
135135
Expect(value).Should(Equal("true"))
136136
})
137137
})

flag_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var _ = Describe("Cli", func() {
1818
flag.Var(&f, "test1", "")
1919
flag.CommandLine.Init("test1", flag.ContinueOnError)
2020
flag.Parse()
21-
Expect(flag.Parsed()).Should(Equal(true))
21+
Expect(flag.Parsed()).Should(BeTrue())
2222
Expect(f.Value).Should(Equal(``))
2323
})
2424
It("value must be empty as parameter value contains invalid character without equal sign", func() {
@@ -27,7 +27,7 @@ var _ = Describe("Cli", func() {
2727
flag.Var(&f, "test2", "")
2828
flag.CommandLine.Init("test2", flag.ContinueOnError)
2929
flag.Parse()
30-
Expect(flag.Parsed()).Should(Equal(true))
30+
Expect(flag.Parsed()).Should(BeTrue())
3131
Expect(f.Value).Should(Equal(``))
3232
})
3333
It("value must not be empty as parameter value contains valid character", func() {
@@ -36,7 +36,7 @@ var _ = Describe("Cli", func() {
3636
flag.Var(&f, "test3", "")
3737
flag.CommandLine.Init("test3", flag.ContinueOnError)
3838
flag.Parse()
39-
Expect(flag.Parsed()).Should(Equal(true))
39+
Expect(flag.Parsed()).Should(BeTrue())
4040
Expect(f.Value).Should(Equal(`correct`))
4141
})
4242
})

helpers_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ var _ = Describe("Helpers", func() {
9191
Context("when excluding the dirs", func() {
9292
It("should create a proper regexp", func() {
9393
r := gosec.ExcludedDirsRegExp([]string{"test"})
94-
Expect(len(r)).Should(Equal(1))
94+
Expect(r).Should(HaveLen(1))
9595
match := r[0].MatchString("/home/go/src/project/test/pkg")
9696
Expect(match).Should(BeTrue())
9797
match = r[0].MatchString("/home/go/src/project/vendor/pkg")
@@ -100,7 +100,7 @@ var _ = Describe("Helpers", func() {
100100

101101
It("should create a proper regexp for dir with subdir", func() {
102102
r := gosec.ExcludedDirsRegExp([]string{`test/generated`})
103-
Expect(len(r)).Should(Equal(1))
103+
Expect(r).Should(HaveLen(1))
104104
match := r[0].MatchString("/home/go/src/project/test/generated")
105105
Expect(match).Should(BeTrue())
106106
match = r[0].MatchString("/home/go/src/project/test/pkg")
@@ -111,9 +111,9 @@ var _ = Describe("Helpers", func() {
111111

112112
It("should create no regexp when dir list is empty", func() {
113113
r := gosec.ExcludedDirsRegExp(nil)
114-
Expect(len(r)).Should(Equal(0))
114+
Expect(r).Should(BeEmpty())
115115
r = gosec.ExcludedDirsRegExp([]string{})
116-
Expect(len(r)).Should(Equal(0))
116+
Expect(r).Should(BeEmpty())
117117
})
118118
})
119119

@@ -281,7 +281,7 @@ var _ = Describe("Helpers", func() {
281281
ast.Walk(visitor, ctx.Root)
282282

283283
operands := gosec.GetBinaryExprOperands(be)
284-
Expect(len(operands)).Should(Equal(2))
284+
Expect(operands).Should(HaveLen(2))
285285
})
286286
It("should return all operands of complex binary expression", func() {
287287
pkg := testutils.NewTestPackage()
@@ -313,7 +313,7 @@ var _ = Describe("Helpers", func() {
313313
ast.Walk(visitor, ctx.Root)
314314

315315
operands := gosec.GetBinaryExprOperands(be)
316-
Expect(len(operands)).Should(Equal(4))
316+
Expect(operands).Should(HaveLen(4))
317317
})
318318
})
319319
})

0 commit comments

Comments
 (0)