diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3a74615..e226136 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,7 +9,7 @@ on: - main env: - GOLANGCI_LINT_VERSION: v1.55 + GOLANGCI_LINT_VERSION: v1.58 jobs: test: diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..4d7ac44 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,158 @@ +run: + timeout: 5m + +issues: + max-issues-per-linter: 0 + max-same-issues: 0 + exclude-rules: + - path: _test\.go + linters: + - bodyclose + - dupl + - errcheck + - errorlint + - funlen + - goconst + - gocyclo + - goerr113 + - gosec + - lll + - noctx + - prealloc + - unparam + +output: + uniq-by-line: true + sort-results: true + +linters: + disable-all: true + enable: + - asciicheck + - depguard + - durationcheck + - errcheck + - errorlint + - exhaustive + - exportloopref + - gocritic + - gofmt + - goimports + - gomoddirectives + - goprintffuncname + - gosec + - gosimple + - govet + - ineffassign + - makezero + - megacheck + - misspell + - nakedret + - nakedret + - nilerr + - noctx + - nolintlint + - prealloc + - revive + - staticcheck + - stylecheck + - testifylint + - thelper + - tparallel + - typecheck + - unconvert + - unparam + - usestdlibvars + - unused + - wastedassign + - whitespace + +linters-settings: + depguard: + rules: + main: + deny: + - pkg: github.com/pkg/errors + desc: Use "errors" from std lib instead. + - pkg: golang.org/x/exp/slices + desc: Use "slices" from std lib instead. + - pkg: golang.org/x/exp/maps + desc: Use "maps" from std lib instead. + errorlint: + errorf: true + asserts: false + comparison: true + errcheck: + check-type-assertions: true + check-blank: false + exhaustive: + default-signifies-exhaustive: true + gci: + sections: + - standard + - default + - prefix(github.com/sumup/x) + - dot + skip-generated: false + gocritic: + disabled-checks: + - sloppyReassign + - whyNoLint + enabled-tags: + - diagnostic + - style + - performance + settings: + hugeParam: + sizeThreshold: 512 + gofmt: + simplify: true + goimports: + local-prefixes: github.com/sumup/x + gomoddirectives: + replace-local: true + gosimple: + checks: ["all"] + govet: + enable-all: true + disable: + - fieldalignment + nakedret: + max-func-lines: 10 + misspell: + locale: US + prealloc: + simple: true + range-loops: true + for-loops: false + revive: + rules: + - name: blank-imports + disabled: true + nolintlint: + allow-unused: false + require-explanation: true + require-specific: true + staticcheck: + checks: ['all'] + stylecheck: + checks: ['all'] + unparam: + check-exported: false + unused: {} + whitespace: + multi-if: false + multi-func: false + testifylint: + enable: + - bool-compare + - compares + - empty + - error-is-as + - error-nil + - expected-actual + - float-compare + - len + - suite-dont-use-pkg + - suite-extra-assert-call + - suite-thelper diff --git a/base32/base32.go b/base32/base32.go index 3cbb9b7..fcc249d 100644 --- a/base32/base32.go +++ b/base32/base32.go @@ -80,7 +80,7 @@ func EncodeTo(dst []byte, src [16]byte, alphabet string) { // Encode encodes the src [16]byte into a base32 string with the given alphabet. // The alphabet must be 32 bytes long. If the alphabet is shorter, the function -// will panic. It's the callers responsiblity to ensure the alphabet is valid. +// will panic. It's the callers responsibility to ensure the alphabet is valid. // // Direct usage is discouraged. Use EncodeUpper or EncodeLower instead. func Encode(src [16]byte, alphabet string) string { @@ -163,7 +163,7 @@ func DecodeLower(s string) ([]byte, error) { } // Decode decodes a given base32 string into a 16-byte slice. The second argument is a index lookup table, that -// must be 256 bytes long. If the table is shorter, the function will panic. It's the callers responsiblity to +// must be 256 bytes long. If the table is shorter, the function will panic. It's the callers responsibility to // ensure the table is valid. // // Direct usage is discouraged. Use DecodeUpper or DecodeLower instead. diff --git a/encoding_test.go b/encoding_test.go index 250dcce..39cbb5a 100644 --- a/encoding_test.go +++ b/encoding_test.go @@ -21,6 +21,8 @@ func TestTypeID_Pgx_Scan(t *testing.T) { codec := pgtype.TextCodec{} t.Run("pgx binary scan", func(t *testing.T) { + t.Parallel() + t.Run("valid string bytes", func(t *testing.T) { var target UserID err := codec.PlanScan(pgtypeMap, pgtype.TextOID, pgtype.BinaryFormatCode, &target). @@ -44,6 +46,8 @@ func TestTypeID_Pgx_Scan(t *testing.T) { }) t.Run("pgx text scan", func(t *testing.T) { + t.Parallel() + var target UserID err := codec.PlanScan(pgtypeMap, pgtype.TextOID, pgtype.TextFormatCode, &target). Scan([]byte(userIDStr), &target) @@ -55,6 +59,8 @@ func TestTypeID_Pgx_Scan(t *testing.T) { } }) t.Run("error on invalid byte count", func(t *testing.T) { + t.Parallel() + var target UserID err := codec.PlanScan(pgtypeMap, pgtype.UUIDOID, pgtype.BinaryFormatCode, &target). Scan([]byte("2345-2222-111-222"), &target) @@ -64,6 +70,8 @@ func TestTypeID_Pgx_Scan(t *testing.T) { }) t.Run("error on nil scan", func(t *testing.T) { + t.Parallel() + var target UserID err := codec.PlanScan(pgtypeMap, pgtype.UUIDOID, pgtype.BinaryFormatCode, &target). Scan(nil, &target) @@ -88,6 +96,8 @@ func TestTypeID_Pgx_Value(t *testing.T) { codec := pgtype.TextCodec{} t.Run("binary encoding", func(t *testing.T) { + t.Parallel() + var buf []byte newBuf, err := codec.PlanEncode(pgtypeMap, pgtype.TextOID, pgtype.BinaryFormatCode, original). Encode(original, buf) @@ -100,6 +110,8 @@ func TestTypeID_Pgx_Value(t *testing.T) { }) t.Run("text encoding", func(t *testing.T) { + t.Parallel() + var buf []byte newBuf, err := codec.PlanEncode(pgtypeMap, pgtype.TextOID, pgtype.TextFormatCode, original). Encode(original, buf) diff --git a/generate.go b/generate.go index 1c20643..6cf9811 100644 --- a/generate.go +++ b/generate.go @@ -16,7 +16,7 @@ type processor struct { b32EncodeTo func([]byte, uuid.UUID) // b32Decode decode a UUID using the resp. base32 decoding. b32Decode func(string) (uuid.UUID, error) - // Generates a new universal unique identifer. + // Generates a new universal unique identifier. generateUUID func() (uuid.UUID, error) } diff --git a/typeid_test.go b/typeid_test.go index a2807d9..7af39ae 100644 --- a/typeid_test.go +++ b/typeid_test.go @@ -91,6 +91,7 @@ func TestTypeID_ToFrom(t *testing.T) { } func runToFromQuickTests[T idImplementation[P], P Prefix](t *testing.T) { + t.Helper() t.Parallel() t.Run("from string", func(t *testing.T) { @@ -123,6 +124,7 @@ func runToFromQuickTests[T idImplementation[P], P Prefix](t *testing.T) { } func fromStringTester[T idImplementation[P], P Prefix](t *testing.T) func(wid wrappedID[T, P]) bool { + t.Helper() return func(wid wrappedID[T, P]) bool { parsedID, err := FromString[T](wid.ID().String()) if err != nil { @@ -133,6 +135,7 @@ func fromStringTester[T idImplementation[P], P Prefix](t *testing.T) func(wid wr } func fromUUIDTester[T idImplementation[P], P Prefix](t *testing.T) func(wid wrappedID[T, P]) bool { + t.Helper() return func(wid wrappedID[T, P]) bool { parsedID, err := FromUUID[T](wid.ID().UUID()) if err != nil { @@ -143,6 +146,7 @@ func fromUUIDTester[T idImplementation[P], P Prefix](t *testing.T) func(wid wrap } func fromUUIDStringTester[T idImplementation[P], P Prefix](t *testing.T) func(wid wrappedID[T, P]) bool { + t.Helper() return func(wid wrappedID[T, P]) bool { parsedID, err := FromUUIDStr[T](wid.ID().UUID().String()) if err != nil { @@ -153,6 +157,7 @@ func fromUUIDStringTester[T idImplementation[P], P Prefix](t *testing.T) func(wi } func fromUUIDBytesTester[T idImplementation[P], P Prefix](t *testing.T) func(wid wrappedID[T, P]) bool { + t.Helper() return func(wid wrappedID[T, P]) bool { parsedID, err := FromUUIDBytes[T](wid.id.UUID().Bytes()) if err != nil { @@ -172,7 +177,7 @@ func (w wrappedID[T, P]) ID() T { return w.id } -func (w wrappedID[T, P]) Generate(rand *rand.Rand, _ int) reflect.Value { +func (w wrappedID[T, P]) Generate(rnd *rand.Rand, _ int) reflect.Value { // gen the processor to determine the UUID version to use procGenUUID, err := (T{}).processor().generateUUID() if err != nil { @@ -180,18 +185,19 @@ func (w wrappedID[T, P]) Generate(rand *rand.Rand, _ int) reflect.Value { } version := procGenUUID.Version() - uuidGen := uuid.NewGenWithOptions(uuid.WithRandomReader(rand)) + uuidGen := uuid.NewGenWithOptions(uuid.WithRandomReader(rnd)) var uid uuid.UUID - if version == uuid.V4 { + switch version { + case uuid.V4: if uid, err = uuidGen.NewV4(); err != nil { panic("failed to generate uuid v4") } - } else if version == uuid.V7 { + case uuid.V7: if uid, err = uuidGen.NewV7(); err != nil { panic("failed to generate uuid v7") } - } else { + default: panic("unknown uuid version") }