Skip to content

Commit dcfda72

Browse files
committed
chore: relint
* updated golangci rules & relinted tests * updated github actions * updated badge in README Signed-off-by: Frederic BIDON <[email protected]>
1 parent 447abe8 commit dcfda72

14 files changed

+260
-247
lines changed

.github/workflows/ci.yaml

-46
This file was deleted.

.github/workflows/go-test.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: go test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
lint:
7+
name: Lint
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
- uses: actions/setup-go@v4
12+
with:
13+
go-version: stable
14+
check-latest: true
15+
cache: true
16+
- name: golangci-lint
17+
uses: golangci/golangci-lint-action@v3
18+
with:
19+
version: latest
20+
only-new-issues: true
21+
22+
test:
23+
name: Unit tests
24+
runs-on: ${{ matrix.os }}
25+
26+
strategy:
27+
matrix:
28+
os: [ ubuntu-latest, macos-latest, windows-latest ]
29+
go_version: ['oldstable', 'stable' ]
30+
31+
steps:
32+
- name: Run unit tests
33+
uses: actions/setup-go@v4
34+
with:
35+
go-version: '${{ matrix.go_version }}'
36+
check-latest: true
37+
cache: true
38+
- uses: actions/checkout@v3
39+
40+
- run: go test -v -race -coverprofile="coverage-${{ matrix.os }}.${{ matrix.go_version }}.out" -covermode=atomic ./...
41+
42+
- name: Upload coverage to codecov
43+
uses: codecov/codecov-action@v3
44+
with:
45+
files: './coverage-${{ matrix.os }}.${{ matrix.go_version }}.out,./coverage-integration-${{ matrix.os }}.${{ matrix.go_version }}.out'
46+
flags: '${{ matrix.go_version }}'
47+
os: '${{ matrix.os }}'
48+
fail_ci_if_error: false
49+
verbose: true
50+

.golangci.yml

+47-45
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,58 @@ linters-settings:
44
golint:
55
min-confidence: 0
66
gocyclo:
7-
min-complexity: 31
7+
min-complexity: 45
88
maligned:
99
suggest-new: true
1010
dupl:
11-
threshold: 100
11+
threshold: 200
1212
goconst:
1313
min-len: 2
14-
min-occurrences: 4
14+
min-occurrences: 3
1515

1616
linters:
17-
enable:
18-
- revive
19-
- goimports
20-
- gosec
17+
enable-all: true
18+
disable:
19+
- maligned
2120
- unparam
22-
- unconvert
23-
- predeclared
24-
- prealloc
25-
- misspell
26-
27-
# disable:
28-
# - maligned
29-
# - lll
30-
# - gochecknoinits
31-
# - gochecknoglobals
32-
# - godox
33-
# - gocognit
34-
# - whitespace
35-
# - wsl
36-
# - funlen
37-
# - wrapcheck
38-
# - testpackage
39-
# - nlreturn
40-
# - gofumpt
41-
# - goerr113
42-
# - gci
43-
# - gomnd
44-
# - godot
45-
# - exhaustivestruct
46-
# - paralleltest
47-
# - varnamelen
48-
# - ireturn
49-
# - exhaustruct
50-
# #- thelper
51-
52-
issues:
53-
exclude-rules:
54-
- path: bson.go
55-
text: "should be .*ObjectID"
56-
linters:
57-
- golint
58-
- stylecheck
59-
21+
- lll
22+
- gochecknoinits
23+
- gochecknoglobals
24+
- funlen
25+
- godox
26+
- gocognit
27+
- whitespace
28+
- wsl
29+
- wrapcheck
30+
- testpackage
31+
- nlreturn
32+
- gomnd
33+
- exhaustivestruct
34+
- goerr113
35+
- errorlint
36+
- nestif
37+
- godot
38+
- gofumpt
39+
- paralleltest
40+
- tparallel
41+
- thelper
42+
- ifshort
43+
- exhaustruct
44+
- varnamelen
45+
- gci
46+
- depguard
47+
- errchkjson
48+
- inamedparam
49+
- nonamedreturns
50+
- musttag
51+
- ireturn
52+
- forcetypeassert
53+
- cyclop
54+
# deprecated linters
55+
- deadcode
56+
- interfacer
57+
- scopelint
58+
- varcheck
59+
- structcheck
60+
- golint
61+
- nosnakecase

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# Strfmt [![Build Status](https://travis-ci.org/go-openapi/strfmt.svg?branch=master)](https://travis-ci.org/go-openapi/strfmt) [![codecov](https://codecov.io/gh/go-openapi/strfmt/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/strfmt) [![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io)
2-
1+
# Strfmt [![Build Status](https://github.com/go-openapi/strfmt/actions/workflows/go-test.yaml/badge.svg)](https://github.com/go-openapi/strfmt/actions?query=workflow%3A"go+test") [![codecov](https://codecov.io/gh/go-openapi/strfmt/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/strfmt)
2+
[![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io)
33
[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/strfmt/master/LICENSE)
44
[![GoDoc](https://godoc.org/github.com/go-openapi/strfmt?status.svg)](http://godoc.org/github.com/go-openapi/strfmt)
5-
[![GolangCI](https://golangci.com/badges/github.com/go-openapi/strfmt.svg)](https://golangci.com)
65
[![Go Report Card](https://goreportcard.com/badge/github.com/go-openapi/strfmt)](https://goreportcard.com/report/github.com/go-openapi/strfmt)
76

87
This package exposes a registry of data types to support string formats in the go-openapi toolkit.

bson.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ func IsBSONObjectID(str string) bool {
3939
// ObjectId represents a BSON object ID (alias to go.mongodb.org/mongo-driver/bson/primitive.ObjectID)
4040
//
4141
// swagger:strfmt bsonobjectid
42-
type ObjectId bsonprim.ObjectID //nolint:revive
42+
type ObjectId bsonprim.ObjectID //nolint:revive,stylecheck
4343

4444
// NewObjectId creates a ObjectId from a Hex String
45-
func NewObjectId(hex string) ObjectId { //nolint:revive
45+
func NewObjectId(hex string) ObjectId { //nolint:revive,stylecheck
4646
oid, err := bsonprim.ObjectIDFromHex(hex)
4747
if err != nil {
4848
panic(err)

bson_test.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,37 @@ import (
1818
"testing"
1919

2020
"github.com/stretchr/testify/assert"
21+
"github.com/stretchr/testify/require"
2122
"go.mongodb.org/mongo-driver/bson"
2223
)
2324

2425
func TestBSONObjectId_fullCycle(t *testing.T) {
2526
id := NewObjectId("507f1f77bcf86cd799439011")
2627
bytes, err := id.MarshalText()
27-
assert.NoError(t, err)
28+
require.NoError(t, err)
2829

2930
var idCopy ObjectId
3031

3132
err = idCopy.Scan(bytes)
32-
assert.NoError(t, err)
33+
require.NoError(t, err)
3334
assert.Equal(t, id, idCopy)
3435

3536
err = idCopy.UnmarshalText(bytes)
36-
assert.NoError(t, err)
37+
require.NoError(t, err)
3738
assert.Equal(t, id, idCopy)
3839

3940
jsonBytes, err := id.MarshalJSON()
40-
assert.NoError(t, err)
41+
require.NoError(t, err)
4142

4243
err = idCopy.UnmarshalJSON(jsonBytes)
43-
assert.NoError(t, err)
44+
require.NoError(t, err)
4445
assert.Equal(t, id, idCopy)
4546

4647
bsonBytes, err := bson.Marshal(&id)
47-
assert.NoError(t, err)
48+
require.NoError(t, err)
4849

4950
err = bson.Unmarshal(bsonBytes, &idCopy)
50-
assert.NoError(t, err)
51+
require.NoError(t, err)
5152
assert.Equal(t, id, idCopy)
5253
}
5354

conv/ulid_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/go-openapi/strfmt"
77
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
89
)
910

1011
const testUlid = string("01EYXZVGBHG26MFTG4JWR4K558")
@@ -14,7 +15,7 @@ func TestULIDValue(t *testing.T) {
1415

1516
value := strfmt.ULID{}
1617
err := value.UnmarshalText([]byte(testUlid))
17-
assert.NoError(t, err)
18+
require.NoError(t, err)
1819
assert.Equal(t, value, ULIDValue(&value))
1920

2021
ulidRef := ULID(value)

date_test.go

+16-15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"time"
2424

2525
"github.com/stretchr/testify/assert"
26+
"github.com/stretchr/testify/require"
2627
"go.mongodb.org/mongo-driver/bson"
2728
)
2829

@@ -32,43 +33,43 @@ var _ driver.Valuer = Date{}
3233
func TestDate(t *testing.T) {
3334
pp := Date{}
3435
err := pp.UnmarshalText([]byte{})
35-
assert.NoError(t, err)
36+
require.NoError(t, err)
3637
err = pp.UnmarshalText([]byte("yada"))
37-
assert.Error(t, err)
38+
require.Error(t, err)
3839

3940
orig := "2014-12-15"
4041
bj := []byte("\"" + orig + "\"")
4142
err = pp.UnmarshalText([]byte(orig))
42-
assert.NoError(t, err)
43+
require.NoError(t, err)
4344

4445
txt, err := pp.MarshalText()
45-
assert.NoError(t, err)
46+
require.NoError(t, err)
4647
assert.Equal(t, orig, string(txt))
4748

4849
err = pp.UnmarshalJSON(bj)
49-
assert.NoError(t, err)
50+
require.NoError(t, err)
5051
assert.EqualValues(t, orig, pp.String())
5152

5253
err = pp.UnmarshalJSON([]byte(`"1972/01/01"`))
53-
assert.Error(t, err)
54+
require.Error(t, err)
5455

5556
b, err := pp.MarshalJSON()
56-
assert.NoError(t, err)
57+
require.NoError(t, err)
5758
assert.Equal(t, bj, b)
5859

5960
dateOriginal := Date(time.Date(2014, 10, 10, 0, 0, 0, 0, time.UTC))
6061

6162
bsonData, err := bson.Marshal(&dateOriginal)
62-
assert.NoError(t, err)
63+
require.NoError(t, err)
6364

6465
var dateCopy Date
6566
err = bson.Unmarshal(bsonData, &dateCopy)
66-
assert.NoError(t, err)
67+
require.NoError(t, err)
6768
assert.Equal(t, dateOriginal, dateCopy)
6869

6970
var dateZero Date
7071
err = dateZero.UnmarshalJSON([]byte(jsonNull))
71-
assert.NoError(t, err)
72+
require.NoError(t, err)
7273
assert.Equal(t, Date{}, dateZero)
7374
}
7475

@@ -85,18 +86,18 @@ func TestDate_Scan(t *testing.T) {
8586

8687
dd := Date{}
8788
err := dd.Scan(nil)
88-
assert.NoError(t, err)
89+
require.NoError(t, err)
8990
assert.Equal(t, Date{}, dd)
9091

9192
err = dd.Scan(19700101)
92-
assert.Error(t, err)
93+
require.Error(t, err)
9394
}
9495

9596
func TestDate_Value(t *testing.T) {
9697
ref := time.Now().Truncate(24 * time.Hour).UTC()
9798
date := Date(ref)
9899
dbv, err := date.Value()
99-
assert.NoError(t, err)
100+
require.NoError(t, err)
100101
assert.EqualValues(t, dbv, ref.Format("2006-01-02"))
101102
}
102103

@@ -148,14 +149,14 @@ func TestGobEncodingDate(t *testing.T) {
148149
b := bytes.Buffer{}
149150
enc := gob.NewEncoder(&b)
150151
err := enc.Encode(Date(now))
151-
assert.NoError(t, err)
152+
require.NoError(t, err)
152153
assert.NotEmpty(t, b.Bytes())
153154

154155
var result Date
155156

156157
dec := gob.NewDecoder(&b)
157158
err = dec.Decode(&result)
158-
assert.NoError(t, err)
159+
require.NoError(t, err)
159160
assert.Equal(t, now.Year(), time.Time(result).Year())
160161
assert.Equal(t, now.Month(), time.Time(result).Month())
161162
assert.Equal(t, now.Day(), time.Time(result).Day())

0 commit comments

Comments
 (0)