-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trigger warnings for directly assert the builtin `cap` function. For example: ```go Expect(cap(slice)).To(Equal(10)) ==> Expect(slice).To(HaveCap(10)) Expect(cap(slice) == 10).To(BeTrue()) ==> Expect(slice).To(HaveCap(10)) ```
- Loading branch information
Showing
11 changed files
with
357 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cap | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("check cap", func() { | ||
It("should not allow expect cap", func() { | ||
slice := make([]int, 0, 10) | ||
gomega.Expect(cap(slice)).To(gomega.Equal(10)) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.To\(gomega\.HaveCap\(10\)\). instead` | ||
gomega.Expect(cap(slice)).ToNot(gomega.Equal(0)) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.ToNot\(gomega\.HaveCap\(0\)\). instead` | ||
gomega.Expect(cap(slice)).ToNot(gomega.Equal(5)) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.ToNot\(gomega\.HaveCap\(5\)\). instead` | ||
gomega.Expect(cap(slice)).ToNot(gomega.BeZero()) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.ToNot\(gomega\.HaveCap\(0\)\). instead` | ||
gomega.Expect(cap(slice)).To(gomega.BeNumerically("==", 10)) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.To\(gomega\.HaveCap\(10\)\). instead` | ||
gomega.Expect(cap(slice)).To(gomega.BeNumerically("!=", 0)) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.ToNot\(gomega\.HaveCap\(0\)\). instead` | ||
gomega.Expect(cap(slice)).ToNot(gomega.BeNumerically("==", 0)) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.ToNot\(gomega\.HaveCap\(0\)\). instead` | ||
gomega.Expect(cap(slice)).To(gomega.BeNumerically("!=", 5)) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.ToNot\(gomega\.HaveCap\(5\)\). instead` | ||
gomega.Expect(cap(slice)).ToNot(gomega.BeNumerically("==", 5)) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.ToNot\(gomega\.HaveCap\(5\)\). instead` | ||
gomega.Expect(cap(slice)).To(gomega.BeNumerically(">", 0)) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.ToNot\(gomega\.HaveCap\(0\)\). instead` | ||
gomega.Expect(cap(slice)).To(gomega.BeNumerically(">=", 1)) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.ToNot\(gomega\.HaveCap\(0\)\). instead` | ||
gomega.Expect(slice).To(gomega.BeEmpty()) | ||
gomega.Expect(slice).To(gomega.HaveCap(10)) | ||
}) | ||
|
||
It("should not allow comparison with cap", func() { | ||
slice := make([]int, 0, 10) | ||
gomega.Expect(cap(slice) == 10).To(gomega.BeTrue()) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.To\(gomega\.HaveCap\(10\)\). instead` | ||
gomega.Expect(cap(slice) == 10).To(gomega.Equal(true)) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.To\(gomega\.HaveCap\(10\)\). instead` | ||
gomega.Expect(cap(slice) != 10).To(gomega.BeFalse()) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.To\(gomega\.HaveCap\(10\)\). instead` | ||
gomega.Expect(cap(slice) != 10).To(gomega.Equal(false)) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.To\(gomega\.HaveCap\(10\)\). instead` | ||
gomega.Expect(cap(slice) == 10).ToNot(gomega.BeFalse()) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.To\(gomega\.HaveCap\(10\)\). instead` | ||
gomega.Expect(cap(slice) == 10).ToNot(gomega.Equal(false)) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.To\(gomega\.HaveCap\(10\)\). instead` | ||
gomega.Expect(cap(slice) != 10).ToNot(gomega.BeTrue()) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.To\(gomega\.HaveCap\(10\)\). instead` | ||
gomega.Expect(cap(slice) != 10).ToNot(gomega.Equal(true)) // want `ginkgo-linter: wrong cap assertion. Consider using .gomega\.Expect\(slice\)\.To\(gomega\.HaveCap\(10\)\). instead` | ||
}) | ||
}) |
Oops, something went wrong.