Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useless-assert: negative-nature assertions for unsigned values #133

Open
Antonboom opened this issue Jun 20, 2024 · 1 comment
Open

useless-assert: negative-nature assertions for unsigned values #133

Antonboom opened this issue Jun 20, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Antonboom
Copy link
Owner

From #126:

	// These one will be reported by incorrect-assert.
	ignoredAssertions = append(ignoredAssertions,
		Assertion{Fn: "Negative", Argsf: "uint(a)"},
		Assertion{Fn: "Less", Argsf: "uint(a), 0"},
		Assertion{Fn: "True", Argsf: "uint(a) < 0"},
		Assertion{Fn: "True", Argsf: "0 > uint(a)"},
		Assertion{Fn: "False", Argsf: "uint(a) >= 0"},
		Assertion{Fn: "False", Argsf: "0 <= uint(a)"},
	)
@Antonboom Antonboom added the enhancement New feature or request label Jun 20, 2024
@Antonboom Antonboom changed the title incorrect-assert: negative-nature assertions for unsigned values useless-assert: negative-nature assertions for unsigned values Nov 19, 2024
@Antonboom
Copy link
Owner Author

--- a/analyzer/testdata/src/debug/useless_assert_test.go
+++ b/analyzer/testdata/src/debug/useless_assert_test.go
@@ -1,6 +1,7 @@
 package debug
 
 import (
+       "fmt"
        "testing"
 
        "github.com/stretchr/testify/assert"
@@ -23,3 +24,16 @@ func TestUselessAsserts(t *testing.T) {
        assert.Zero(t, "")
        assert.Zero(t, nil)
 }
+
+func TestUselessUnsigned(t *testing.T) {
+       for _, a := range []int{-1, 0, 1} {
+               t.Run(fmt.Sprintf("%d", a), func(t *testing.T) {
+                       assert.Negative(t, uint(a))
+                       assert.Less(t, uint(a), uint(0))
+                       assert.True(t, uint(a) < 0)
+                       assert.True(t, 0 > uint(a))
+                       assert.False(t, uint(a) >= 0)
+                       assert.False(t, 0 <= uint(a))
+               })
+       }
+}
~

@Antonboom Antonboom removed this from the v1.6.0 New 2 complex checkers milestone Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant