Skip to content

Commit

Permalink
Updates golangci-lint to v1.61.0 and fixes code.
Browse files Browse the repository at this point in the history
  • Loading branch information
armfazh committed Oct 7, 2024
1 parent 12a9881 commit 49369bd
Show file tree
Hide file tree
Showing 15 changed files with 16 additions and 29 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions .etc/golangci.yml → .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion abe/cpabe/tkn20/internal/dsl/lexer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dsl

import (
"errors"
"fmt"
"strings"
)
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion group/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
Expand Down
1 change: 0 additions & 1 deletion group/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand Down
2 changes: 1 addition & 1 deletion internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion kem/frodo/kat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
1 change: 0 additions & 1 deletion kem/kyber/kat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
4 changes: 0 additions & 4 deletions kem/schemes/schemes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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++ {
Expand All @@ -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) {
Expand All @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions math/wnaf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion oprf/vectors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions pke/kyber/internal/common/poly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion pki/pki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion sign/ed448/ed448.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 0 additions & 4 deletions sign/schemes/schemes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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++ {
Expand All @@ -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) {
Expand Down

0 comments on commit 49369bd

Please sign in to comment.