Skip to content

Releases: nunnatsa/ginkgolinter

v0.11.2

28 Apr 12:58
Compare
Choose a tag to compare

Fix issue #82: false positive for string non-equal comparison.

v0.11.1

24 Apr 12:31
Compare
Choose a tag to compare

Add option to read the version from the CLI:

ginkgolinter version

Release v0.11.0

02 Apr 10:37
Compare
Choose a tag to compare

Changes

New linter rule

Compare pointer to value

The linter warns when comparing a pointer with a value. These comparisons are always wrong and will always fail.

For example:

num := 5
...
pNum := &num
...
Expect(pNum).ShouldNot(Equal(6))

The linter will suggest to use this instead:

Expect(pNum).ShouldNot(HaveValue(Equal(6)))

v0.10.0

26 Mar 14:44
Compare
Choose a tag to compare

This new version brings some new additions:

New Linter Rule:

Function Call in async assertions

The linter now warns about using Eventually or Consistently with a function call. This is because when doing that, Eventually checks the same returned value again and again, instead of polling by calling the function.

For example:

func slowInt() int {
	time.Sleep(time.Second)
	return 42
}

It("should test that slowInt returns 42, eventually", func() {
	Eventually(slowInt()).WithPolling(time.Millisecond * 100).WithTimeout(time.Second * 2).Equal(42)
})

In the above code, Eventually receives 42 as its argument. Then it polls this value to check if it equal
42. What we really wanted here is:

It("should test that slowInt returns 42, eventually", func() {
	Eventually(slowInt).WithPolling(time.Millisecond * 100).WithTimeout(time.Second * 2).Equal(42)
})

Now, Eventually calls the function until it returns the required value.

Note: The linter ignores function calls that return a function or a channel.

To suppress this warning entirely, add the --suppress-async-assertion=true command line flag, or the ginkgo-linter:ignore-async-assert-warning comment.

Improvements and Bug Fixes

Bug Fix: len() comparison

When comparing len() result with a number; e.g.

Expect(len(x) == 5).Should(BeTrue())

the linter used to wrongly fix suggested to replace to

Expect(len(x)).To(Equal(5))

which is also a wrong pattern.

Now, the linter will suggest:

Expect(x).To(HaveLen(5))

Avoid double negative assertions

For patterns like

Expect(boolVal).ShouldNot(Equal(false))

or

Expect(boolVal).ShouldNot(BeFalse())

the linter will suggest

Expect(boolVal).Should(BeTrue())

Support the WithOffset() method

The linter used to ignore patterns like

Expect(len(x)).WithOffset(1).Should(Equal(3))

Now, the linter will catch these patterns as well. For the above code, the linter will suggest

Expect(x).WithOffset(1).Should(HaveLen(3))

v0.9.0

28 Feb 06:06
Compare
Choose a tag to compare

This new version brings some new additions:

New Linter Rules

  • HaveLen() matcher with a value of 0 (HaveLen(0)), will trigger a warning that will suggest to replace this matcher with BeEmpty().
  • Assertion of a comparison and a boolean matcher will trigger a warning that will suggest to use the a better matcher, like BeEqual()
    For example:
Expect(x == 1).To(BeTrue()) // ===> Expect(x).To(Equal(1))
Expect(x == 0).To(Equal(false)) // ===> Expect(x).ToNot(BeZero())
Expect(x > y).To(BeTrue()) // ===> Expect(x).To(BeNumerically(">", y))

and so on.

New Executable's flags

  • --allow-havelen-0=true: if this flag is set, the linter won't trigger warnings for HaveLen(0)
  • --suppress-compare-assertion=true: if this flag is set, the linter won't trigger warnings for wrong boolean comparisons.

New suppress comment

Adding the // ginkgo-linter:ignore-compare-assert-warning comment, will suppress the wrong comparison warning for a specific file or line. See more details at the README.md file

Release v0.8.1

03 Feb 19:34
Compare
Choose a tag to compare

Tiny fix: go mod tidy

v0.8.0

03 Feb 07:57
Compare
Choose a tag to compare

This version fixes a bug that crashes multi - linters tools like golangci-lint

v0.7.1

18 Jan 08:12
Compare
Choose a tag to compare

Updated README
Tiny fixes

v0.7.0

15 Jan 16:34
Compare
Choose a tag to compare

This version adds support in the usage of gomega without ginkgo.

For example:

func TestSomething(t *testing.T) {
    g := NewGomegaWithT(t)

    var err error
    g.Expect(err).ToNot(BeNil())
}

v0.6.0

07 Dec 11:02
Compare
Choose a tag to compare

This release includes some documentation fixes.

It is also fixes GO-2022-0493