From ab15f8201026876da5d9ac14d54c2f6634683d07 Mon Sep 17 00:00:00 2001 From: armfazh Date: Mon, 30 Sep 2024 16:25:12 -0700 Subject: [PATCH] Updates golangci-lint to v1.61.0 and fixes code. --- .github/workflows/ci-actions.yml | 6 +++--- .etc/golangci.yml => .golangci.yaml | 13 ++++++++----- abe/cpabe/tkn20/internal/dsl/lexer.go | 3 ++- group/group_test.go | 1 - group/hash_test.go | 1 - internal/test/test.go | 2 +- kem/frodo/kat_test.go | 1 - kem/kyber/kat_test.go | 1 - kem/schemes/schemes_test.go | 4 ---- math/wnaf_test.go | 2 -- oprf/vectors_test.go | 2 +- pke/kyber/internal/common/poly_test.go | 2 -- pki/pki_test.go | 1 - sign/ed448/ed448.go | 2 +- sign/schemes/schemes_test.go | 4 ---- 15 files changed, 16 insertions(+), 29 deletions(-) rename .etc/golangci.yml => .golangci.yaml (89%) diff --git a/.github/workflows/ci-actions.yml b/.github/workflows/ci-actions.yml index a1105bf1c..88869975d 100644 --- a/.github/workflows/ci-actions.yml +++ b/.github/workflows/ci-actions.yml @@ -22,10 +22,10 @@ jobs: with: go-version: ${{ matrix.GOVER }} - name: Linting - uses: golangci/golangci-lint-action@v4 + uses: golangci/golangci-lint-action@v6 with: - version: v1.56.2 - args: --config=./.etc/golangci.yml ./... + version: v1.61.0 + install-mode: goinstall - name: Check shadowing run: | go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest diff --git a/.etc/golangci.yml b/.golangci.yaml similarity index 89% rename from .etc/golangci.yml rename to .golangci.yaml index 386ef2781..064024654 100644 --- a/.etc/golangci.yml +++ b/.golangci.yaml @@ -12,11 +12,12 @@ linters: # - structcheck (deprecated since v1.49.0) # - varcheck (deprecated since v1.49.0) # - deadcode (deprecated since v1.49.0) + # - exportloopref (deprecated since v1.60.2) - bodyclose + - copyloopvar - depguard - dogsled - errcheck - - exportloopref - forbidigo - funlen - goconst @@ -56,15 +57,17 @@ linters-settings: goconst: min-occurrences: 4 govet: - check-shadowing: true + enable-all: true + disable: + - fieldalignment staticcheck: # TODO: replace deprecated elliptic.Marshal, elliptic.GenerateKey, # elliptic.Unmarshal, params.ScalarBaseMult before re-enabling SA1019. checks: ["*", "-SA1019"] + gosec: + excludes: + - G115 issues: max-issues-per-linter: 0 max-same-issues: 0 - -output: - format: github-actions diff --git a/abe/cpabe/tkn20/internal/dsl/lexer.go b/abe/cpabe/tkn20/internal/dsl/lexer.go index 43c19d97f..be648ef7a 100644 --- a/abe/cpabe/tkn20/internal/dsl/lexer.go +++ b/abe/cpabe/tkn20/internal/dsl/lexer.go @@ -1,6 +1,7 @@ package dsl import ( + "errors" "fmt" "strings" ) @@ -58,7 +59,7 @@ func (l *Lexer) scanTokens() error { } l.addToken(EOF) if l.hadError { - return fmt.Errorf(strings.TrimSpace(errMsg)) + return errors.New(strings.TrimSpace(errMsg)) } return nil } diff --git a/group/group_test.go b/group/group_test.go index ee7e25059..b48cd507c 100644 --- a/group/group_test.go +++ b/group/group_test.go @@ -20,7 +20,6 @@ var allGroups = []group.Group{ func TestGroup(t *testing.T) { const testTimes = 1 << 7 for _, g := range allGroups { - g := g n := g.(fmt.Stringer).String() t.Run(n+"/Add", func(tt *testing.T) { testAdd(tt, testTimes, g) }) t.Run(n+"/Neg", func(tt *testing.T) { testNeg(tt, testTimes, g) }) diff --git a/group/hash_test.go b/group/hash_test.go index 51b44ad78..1e784e9ef 100644 --- a/group/hash_test.go +++ b/group/hash_test.go @@ -115,7 +115,6 @@ type vector struct { func BenchmarkHash(b *testing.B) { for _, g := range allGroups { - g := g name := g.(fmt.Stringer).String() b.Run(name+"/HashToElement", func(b *testing.B) { for i := 0; i < b.N; i++ { diff --git a/internal/test/test.go b/internal/test/test.go index 576211a9f..9ba73dd74 100644 --- a/internal/test/test.go +++ b/internal/test/test.go @@ -16,7 +16,7 @@ func ReportError(t testing.TB, got, want interface{}, inputs ...interface{}) { } fmt.Fprintf(b, "got: %v\nwant: %v", got, want) t.Helper() - t.Fatalf(b.String()) + t.Fatal(b.String()) } // CheckOk fails the test if result == false. diff --git a/kem/frodo/kat_test.go b/kem/frodo/kat_test.go index 61b0aae25..c4694c8d3 100644 --- a/kem/frodo/kat_test.go +++ b/kem/frodo/kat_test.go @@ -23,7 +23,6 @@ func TestPQCgenKATKem(t *testing.T) { {"FrodoKEM-640-SHAKE", "604a10cfc871dfaed9cb5b057c644ab03b16852cea7f39bc7f9831513b5b1cfa"}, } for _, kat := range kats { - kat := kat t.Run(kat.name, func(t *testing.T) { testPQCgenKATKem(t, kat.name, kat.want) }) diff --git a/kem/kyber/kat_test.go b/kem/kyber/kat_test.go index 5b6d39e86..08726cd79 100644 --- a/kem/kyber/kat_test.go +++ b/kem/kyber/kat_test.go @@ -31,7 +31,6 @@ func TestPQCgenKATKem(t *testing.T) { {"ML-KEM-1024", "3fba7327d0320cb6134badf2a1bcb963a5b3c0026c7dece8f00d6a6155e47b33"}, } for _, kat := range kats { - kat := kat t.Run(kat.name, func(t *testing.T) { testPQCgenKATKem(t, kat.name, kat.want) }) diff --git a/kem/schemes/schemes_test.go b/kem/schemes/schemes_test.go index 88a02f31b..d9caf70a9 100644 --- a/kem/schemes/schemes_test.go +++ b/kem/schemes/schemes_test.go @@ -17,7 +17,6 @@ func TestCaseSensitivity(t *testing.T) { func BenchmarkGenerateKeyPair(b *testing.B) { allSchemes := schemes.All() for _, scheme := range allSchemes { - scheme := scheme b.Run(scheme.Name(), func(b *testing.B) { for i := 0; i < b.N; i++ { _, _, _ = scheme.GenerateKeyPair() @@ -29,7 +28,6 @@ func BenchmarkGenerateKeyPair(b *testing.B) { func BenchmarkEncapsulate(b *testing.B) { allSchemes := schemes.All() for _, scheme := range allSchemes { - scheme := scheme pk, _, _ := scheme.GenerateKeyPair() b.Run(scheme.Name(), func(b *testing.B) { for i := 0; i < b.N; i++ { @@ -42,7 +40,6 @@ func BenchmarkEncapsulate(b *testing.B) { func BenchmarkDecapsulate(b *testing.B) { allSchemes := schemes.All() for _, scheme := range allSchemes { - scheme := scheme pk, sk, _ := scheme.GenerateKeyPair() ct, _, _ := scheme.Encapsulate(pk) b.Run(scheme.Name(), func(b *testing.B) { @@ -56,7 +53,6 @@ func BenchmarkDecapsulate(b *testing.B) { func TestApi(t *testing.T) { allSchemes := schemes.All() for _, scheme := range allSchemes { - scheme := scheme t.Run(scheme.Name(), func(t *testing.T) { if scheme == nil { t.Fatal() diff --git a/math/wnaf_test.go b/math/wnaf_test.go index d397b0640..ad33d20b6 100644 --- a/math/wnaf_test.go +++ b/math/wnaf_test.go @@ -63,7 +63,6 @@ func BenchmarkOmegaNAF(b *testing.B) { Two128.Lsh(Two128, 128) for w := uint(2); w < 6; w++ { - w := w // pin variable b.Run(fmt.Sprintf("%v", w), func(b *testing.B) { x, _ := rand.Int(rand.Reader, Two128) b.ResetTimer() @@ -79,7 +78,6 @@ func BenchmarkOmegaNAFRegular(b *testing.B) { Two128.Lsh(Two128, 128) for w := uint(2); w < 6; w++ { - w := w // pin variable b.Run(fmt.Sprintf("%v", w), func(b *testing.B) { x, _ := rand.Int(rand.Reader, Two128) x.SetBit(x, 0, uint(1)) // odd-numbers diff --git a/oprf/vectors_test.go b/oprf/vectors_test.go index 774dc50fa..2293049e8 100644 --- a/oprf/vectors_test.go +++ b/oprf/vectors_test.go @@ -245,7 +245,7 @@ func TestVectors(t *testing.T) { for i := range v { suite, err := GetSuite(v[i].Identifier) if err != nil { - t.Logf(v[i].Identifier + " not supported yet") + t.Log(v[i].Identifier + " not supported yet") continue } t.Run(fmt.Sprintf("%v/Mode%v", suite, v[i].Mode), v[i].test) diff --git a/pke/kyber/internal/common/poly_test.go b/pke/kyber/internal/common/poly_test.go index 350bef961..cc305d730 100644 --- a/pke/kyber/internal/common/poly_test.go +++ b/pke/kyber/internal/common/poly_test.go @@ -44,7 +44,6 @@ func TestDecompressMessage(t *testing.T) { func TestCompress(t *testing.T) { for _, d := range []int{4, 5, 10, 11} { - d := d t.Run(fmt.Sprintf("d=%d", d), func(t *testing.T) { var p, q Poly bound := (Q + (1 << uint(d))) >> uint(d+1) @@ -351,7 +350,6 @@ func (p *Poly) OldCompressTo(m []byte, d int) { func TestCompressFullInputFirstCoeff(t *testing.T) { for _, d := range []int{4, 5, 10, 11} { - d := d t.Run(fmt.Sprintf("d=%d", d), func(t *testing.T) { var p, q Poly bound := (Q + (1 << uint(d))) >> uint(d+1) diff --git a/pki/pki_test.go b/pki/pki_test.go index 7412dd0ae..64b43759d 100644 --- a/pki/pki_test.go +++ b/pki/pki_test.go @@ -9,7 +9,6 @@ import ( func TestPEM(t *testing.T) { for _, scheme := range schemes.All() { - scheme := scheme t.Run(scheme.Name(), func(t *testing.T) { if scheme == nil { t.Fatal() diff --git a/sign/ed448/ed448.go b/sign/ed448/ed448.go index 324bd8f33..c368b181b 100644 --- a/sign/ed448/ed448.go +++ b/sign/ed448/ed448.go @@ -206,7 +206,7 @@ func newKeyFromSeed(privateKey, seed []byte) { func signAll(signature []byte, privateKey PrivateKey, message, ctx []byte, preHash bool) { if len(ctx) > ContextMaxSize { - panic(fmt.Errorf("ed448: bad context length: " + strconv.Itoa(len(ctx)))) + panic(fmt.Errorf("ed448: bad context length: %v", len(ctx))) } H := sha3.NewShake256() diff --git a/sign/schemes/schemes_test.go b/sign/schemes/schemes_test.go index 2d8e86512..dfa044d78 100644 --- a/sign/schemes/schemes_test.go +++ b/sign/schemes/schemes_test.go @@ -17,7 +17,6 @@ func TestCaseSensitivity(t *testing.T) { func TestApi(t *testing.T) { allSchemes := schemes.All() for _, scheme := range allSchemes { - scheme := scheme t.Run(scheme.Name(), func(t *testing.T) { if scheme == nil { t.Fatal() @@ -122,7 +121,6 @@ func Example() { func BenchmarkGenerateKeyPair(b *testing.B) { allSchemes := schemes.All() for _, scheme := range allSchemes { - scheme := scheme b.Run(scheme.Name(), func(b *testing.B) { for i := 0; i < b.N; i++ { _, _, _ = scheme.GenerateKey() @@ -136,7 +134,6 @@ func BenchmarkSign(b *testing.B) { opts := &sign.SignatureOpts{} for _, scheme := range allSchemes { msg := []byte(fmt.Sprintf("Signing with %s", scheme.Name())) - scheme := scheme _, sk, _ := scheme.GenerateKey() b.Run(scheme.Name(), func(b *testing.B) { for i := 0; i < b.N; i++ { @@ -151,7 +148,6 @@ func BenchmarkVerify(b *testing.B) { opts := &sign.SignatureOpts{} for _, scheme := range allSchemes { msg := []byte(fmt.Sprintf("Signing with %s", scheme.Name())) - scheme := scheme pk, sk, _ := scheme.GenerateKey() sig := scheme.Sign(sk, msg, opts) b.Run(scheme.Name(), func(b *testing.B) {