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

chore: relint #108

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions .github/workflows/ci.yaml

This file was deleted.

50 changes: 50 additions & 0 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: go test

on: [push, pull_request]

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: stable
check-latest: true
cache: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
only-new-issues: true

test:
name: Unit tests
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
go_version: ['oldstable', 'stable' ]

steps:
- name: Run unit tests
uses: actions/setup-go@v4
with:
go-version: '${{ matrix.go_version }}'
check-latest: true
cache: true
- uses: actions/checkout@v3

- run: go test -v -race -coverprofile="coverage-${{ matrix.os }}.${{ matrix.go_version }}.out" -covermode=atomic ./...

- name: Upload coverage to codecov
uses: codecov/codecov-action@v3
with:
files: './coverage-${{ matrix.os }}.${{ matrix.go_version }}.out,./coverage-integration-${{ matrix.os }}.${{ matrix.go_version }}.out'
flags: '${{ matrix.go_version }}'
os: '${{ matrix.os }}'
fail_ci_if_error: false
verbose: true

92 changes: 47 additions & 45 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,58 @@ linters-settings:
golint:
min-confidence: 0
gocyclo:
min-complexity: 31
min-complexity: 45
maligned:
suggest-new: true
dupl:
threshold: 100
threshold: 200
goconst:
min-len: 2
min-occurrences: 4
min-occurrences: 3

linters:
enable:
- revive
- goimports
- gosec
enable-all: true
disable:
- maligned
- unparam
- unconvert
- predeclared
- prealloc
- misspell

# disable:
# - maligned
# - lll
# - gochecknoinits
# - gochecknoglobals
# - godox
# - gocognit
# - whitespace
# - wsl
# - funlen
# - wrapcheck
# - testpackage
# - nlreturn
# - gofumpt
# - goerr113
# - gci
# - gomnd
# - godot
# - exhaustivestruct
# - paralleltest
# - varnamelen
# - ireturn
# - exhaustruct
# #- thelper

issues:
exclude-rules:
- path: bson.go
text: "should be .*ObjectID"
linters:
- golint
- stylecheck

- lll
- gochecknoinits
- gochecknoglobals
- funlen
- godox
- gocognit
- whitespace
- wsl
- wrapcheck
- testpackage
- nlreturn
- gomnd
- exhaustivestruct
- goerr113
- errorlint
- nestif
- godot
- gofumpt
- paralleltest
- tparallel
- thelper
- ifshort
- exhaustruct
- varnamelen
- gci
- depguard
- errchkjson
- inamedparam
- nonamedreturns
- musttag
- ireturn
- forcetypeassert
- cyclop
# deprecated linters
- deadcode
- interfacer
- scopelint
- varcheck
- structcheck
- golint
- nosnakecase
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# 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)

# 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)
[![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io)
[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/strfmt/master/LICENSE)
[![GoDoc](https://godoc.org/github.com/go-openapi/strfmt?status.svg)](http://godoc.org/github.com/go-openapi/strfmt)
[![GolangCI](https://golangci.com/badges/github.com/go-openapi/strfmt.svg)](https://golangci.com)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-openapi/strfmt)](https://goreportcard.com/report/github.com/go-openapi/strfmt)

This package exposes a registry of data types to support string formats in the go-openapi toolkit.
Expand Down
4 changes: 2 additions & 2 deletions bson.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func IsBSONObjectID(str string) bool {
// ObjectId represents a BSON object ID (alias to go.mongodb.org/mongo-driver/bson/primitive.ObjectID)
//
// swagger:strfmt bsonobjectid
type ObjectId bsonprim.ObjectID //nolint:revive
type ObjectId bsonprim.ObjectID //nolint:revive,stylecheck

// NewObjectId creates a ObjectId from a Hex String
func NewObjectId(hex string) ObjectId { //nolint:revive
func NewObjectId(hex string) ObjectId { //nolint:revive,stylecheck
oid, err := bsonprim.ObjectIDFromHex(hex)
if err != nil {
panic(err)
Expand Down
15 changes: 8 additions & 7 deletions bson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,37 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mongodb.org/mongo-driver/bson"
)

func TestBSONObjectId_fullCycle(t *testing.T) {
id := NewObjectId("507f1f77bcf86cd799439011")
bytes, err := id.MarshalText()
assert.NoError(t, err)
require.NoError(t, err)

var idCopy ObjectId

err = idCopy.Scan(bytes)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, id, idCopy)

err = idCopy.UnmarshalText(bytes)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, id, idCopy)

jsonBytes, err := id.MarshalJSON()
assert.NoError(t, err)
require.NoError(t, err)

err = idCopy.UnmarshalJSON(jsonBytes)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, id, idCopy)

bsonBytes, err := bson.Marshal(&id)
assert.NoError(t, err)
require.NoError(t, err)

err = bson.Unmarshal(bsonBytes, &idCopy)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, id, idCopy)
}

Expand Down
3 changes: 2 additions & 1 deletion conv/ulid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/go-openapi/strfmt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

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

value := strfmt.ULID{}
err := value.UnmarshalText([]byte(testUlid))
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, value, ULIDValue(&value))

ulidRef := ULID(value)
Expand Down
31 changes: 16 additions & 15 deletions date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mongodb.org/mongo-driver/bson"
)

Expand All @@ -32,43 +33,43 @@ var _ driver.Valuer = Date{}
func TestDate(t *testing.T) {
pp := Date{}
err := pp.UnmarshalText([]byte{})
assert.NoError(t, err)
require.NoError(t, err)
err = pp.UnmarshalText([]byte("yada"))
assert.Error(t, err)
require.Error(t, err)

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

txt, err := pp.MarshalText()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, orig, string(txt))

err = pp.UnmarshalJSON(bj)
assert.NoError(t, err)
require.NoError(t, err)
assert.EqualValues(t, orig, pp.String())

err = pp.UnmarshalJSON([]byte(`"1972/01/01"`))
assert.Error(t, err)
require.Error(t, err)

b, err := pp.MarshalJSON()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, bj, b)

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

bsonData, err := bson.Marshal(&dateOriginal)
assert.NoError(t, err)
require.NoError(t, err)

var dateCopy Date
err = bson.Unmarshal(bsonData, &dateCopy)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, dateOriginal, dateCopy)

var dateZero Date
err = dateZero.UnmarshalJSON([]byte(jsonNull))
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, Date{}, dateZero)
}

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

dd := Date{}
err := dd.Scan(nil)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, Date{}, dd)

err = dd.Scan(19700101)
assert.Error(t, err)
require.Error(t, err)
}

func TestDate_Value(t *testing.T) {
ref := time.Now().Truncate(24 * time.Hour).UTC()
date := Date(ref)
dbv, err := date.Value()
assert.NoError(t, err)
require.NoError(t, err)
assert.EqualValues(t, dbv, ref.Format("2006-01-02"))
}

Expand Down Expand Up @@ -148,14 +149,14 @@ func TestGobEncodingDate(t *testing.T) {
b := bytes.Buffer{}
enc := gob.NewEncoder(&b)
err := enc.Encode(Date(now))
assert.NoError(t, err)
require.NoError(t, err)
assert.NotEmpty(t, b.Bytes())

var result Date

dec := gob.NewDecoder(&b)
err = dec.Decode(&result)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, now.Year(), time.Time(result).Year())
assert.Equal(t, now.Month(), time.Time(result).Month())
assert.Equal(t, now.Day(), time.Time(result).Day())
Expand Down
Loading
Loading