Skip to content

Commit 7bda92f

Browse files
authored
chore: relinted, updated (#162)
* chore: relinted, updated * updated go version to go1.19 * updated linting rules * updated dependencies, upgraded yaml.v2 to yaml.v3 * relinted code * doc: updated links and badges in README * ci: updated github actions Signed-off-by: Frederic BIDON <[email protected]> * removed empty comment lines Signed-off-by: Frederic BIDON <[email protected]> --------- Signed-off-by: Frederic BIDON <[email protected]>
1 parent b2d5112 commit 7bda92f

33 files changed

+449
-497
lines changed

.github/workflows/ci.yaml

-47
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+
39+
- uses: actions/checkout@v3
40+
41+
- run: go test -v -race -coverprofile="coverage-${{ matrix.os }}.${{ matrix.go_version }}.out" -covermode=atomic ./...
42+
43+
- name: Upload coverage to codecov
44+
uses: codecov/codecov-action@v3
45+
with:
46+
files: './coverage-${{ matrix.os }}.${{ matrix.go_version }}.out'
47+
flags: '${{ matrix.go_version }}'
48+
os: '${{ matrix.os }}'
49+
fail_ci_if_error: false
50+
verbose: true

.golangci.yml

+31-25
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
linters-settings:
22
govet:
33
check-shadowing: true
4+
golint:
5+
min-confidence: 0
46
gocyclo:
5-
min-complexity: 50
7+
min-complexity: 45
68
maligned:
79
suggest-new: true
810
dupl:
9-
threshold: 100
11+
threshold: 200
1012
goconst:
1113
min-len: 2
1214
min-occurrences: 3
@@ -15,41 +17,45 @@ linters:
1517
enable-all: true
1618
disable:
1719
- maligned
20+
- unparam
1821
- lll
22+
- gochecknoinits
23+
- gochecknoglobals
24+
- funlen
1925
- godox
2026
- gocognit
2127
- whitespace
2228
- wsl
23-
- funlen
24-
- gochecknoglobals
25-
- gochecknoinits
26-
- scopelint
2729
- wrapcheck
28-
- exhaustivestruct
29-
- exhaustive
30-
- nlreturn
3130
- testpackage
32-
- gci
33-
- gofumpt
34-
- goerr113
31+
- nlreturn
3532
- gomnd
36-
- tparallel
33+
- exhaustivestruct
34+
- goerr113
35+
- errorlint
3736
- nestif
3837
- godot
39-
- tparallel
38+
- gofumpt
4039
- paralleltest
41-
- cyclop # because we have gocyclo already
42-
- depguard # we do not add a config for this
43-
# TODO: review the linters below. We disabled them to make the CI pass first.
44-
- nonamedreturns
40+
- tparallel
41+
- thelper
42+
- ifshort
4543
- exhaustruct
46-
- nosnakecase
47-
- nolintlint
48-
- ireturn
4944
- varnamelen
45+
- gci
46+
- depguard
47+
- errchkjson
48+
- inamedparam
49+
- nonamedreturns
50+
- musttag
51+
- ireturn
5052
- forcetypeassert
51-
- thelper
52-
# Disable deprecated linters.
53-
# They will be removed from golangci-lint in future.
53+
- cyclop
54+
# deprecated linters
55+
- deadcode
5456
- interfacer
55-
- golint
57+
- scopelint
58+
- varcheck
59+
- structcheck
60+
- golint
61+
- nosnakecase

README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
# Validation helpers
2-
[![Build Status](https://travis-ci.org/go-openapi/validate.svg?branch=master)](https://travis-ci.org/go-openapi/validate)
3-
[![Build status](https://ci.appveyor.com/api/projects/status/d6epy6vipueyh5fs/branch/master?svg=true)](https://ci.appveyor.com/project/fredbi/validate/branch/master)
4-
[![codecov](https://codecov.io/gh/go-openapi/validate/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/validate)
1+
# Validation helpers [![Build Status](https://github.com/go-openapi/validate/actions/workflows/go-test.yml/badge.svg)](https://github.com/go-openapi/validate/actions?query=workflow%3A"go+test") [![codecov](https://codecov.io/gh/go-openapi/validate/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/validate)
2+
53
[![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io)
64
[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/validate/master/LICENSE)
75
[![Go Reference](https://pkg.go.dev/badge/github.com/go-openapi/validate.svg)](https://pkg.go.dev/github.com/go-openapi/validate)
@@ -24,7 +22,7 @@ Reference can be found here: https://github.com/OAI/OpenAPI-Specification/blob/m
2422
* Minimum, Maximum, MultipleOf
2523
* FormatOf
2624

27-
[Documentation](https://godoc.org/github.com/go-openapi/validate)
25+
[Documentation](https://pkg.go.dev/github.com/go-openapi/validate)
2826

2927
## FAQ
3028

debug_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package validate
1616

1717
import (
18-
"io/ioutil"
1918
"os"
2019
"sync"
2120
"testing"
@@ -32,7 +31,7 @@ func TestDebug(t *testing.T) {
3231
skipNotify(t)
3332
t.SkipNow()
3433
}
35-
tmpFile, _ := ioutil.TempFile("", "debug-test")
34+
tmpFile, _ := os.CreateTemp("", "debug-test")
3635
tmpName := tmpFile.Name()
3736
defer func() {
3837
Debug = false

default_validator.go

-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ func (d *defaultValidator) validateDefaultInResponse(resp *spec.Response, respon
170170

171171
responseName, responseCodeAsStr := responseHelp.responseMsgVariants(responseType, responseCode)
172172

173-
//nolint: dupl
174173
if response.Headers != nil { // Safeguard
175174
for nm, h := range response.Headers {
176175
// reset explored schemas to get depth-first recursive-proof exploration
@@ -263,7 +262,6 @@ func (d *defaultValidator) validateDefaultValueSchemaAgainstSchema(path, in stri
263262

264263
// TODO: Temporary duplicated code. Need to refactor with examples
265264

266-
// nolint: dupl
267265
func (d *defaultValidator) validateDefaultValueItemsAgainstSchema(path, in string, root interface{}, items *spec.Items) *Result {
268266
res := new(Result)
269267
s := d.SpecValidator

default_validator_test.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ import (
2626
"github.com/stretchr/testify/require"
2727
)
2828

29+
const (
30+
jsonExt = ".json"
31+
hasErrorMsg = " should have errors"
32+
noErrorMsg = " should not have errors"
33+
hasWarningMsg = " should have warnings"
34+
)
35+
2936
func TestDefault_ValidatePetStore(t *testing.T) {
3037
doc, _ := loads.Analyzed(PetStoreJSONMessage, "")
3138
validator := NewSpecValidator(spec.MustLoadSwagger20Schema(), strfmt.Default)
@@ -72,36 +79,36 @@ func TestDefault_ValidateDefaults(t *testing.T) {
7279
}
7380

7481
for _, tt := range tests {
75-
path := filepath.Join("fixtures", "validation", "default", "valid-default-value-"+tt+".json")
82+
path := filepath.Join("fixtures", "validation", "default", "valid-default-value-"+tt+jsonExt)
7683
if DebugTest {
7784
t.Logf("Testing valid default values for: %s", path)
7885
}
7986
validator := makeSpecValidator(t, path)
8087
myDefaultValidator := &defaultValidator{SpecValidator: validator}
8188
res := myDefaultValidator.Validate()
82-
assert.Empty(t, res.Errors, tt+" should not have errors")
89+
assert.Empty(t, res.Errors, tt+noErrorMsg)
8390

8491
// Special case: warning only
8592
if tt == "parameter-required" {
8693
warns := verifiedTestWarnings(res)
8794
assert.Contains(t, warns, "limit in query has a default value and is required as parameter")
8895
}
8996

90-
path = filepath.Join("fixtures", "validation", "default", "invalid-default-value-"+tt+".json")
97+
path = filepath.Join("fixtures", "validation", "default", "invalid-default-value-"+tt+jsonExt)
9198
if DebugTest {
9299
t.Logf("Testing invalid default values for: %s", path)
93100
}
94101

95102
validator = makeSpecValidator(t, path)
96103
myDefaultValidator = &defaultValidator{SpecValidator: validator}
97104
res = myDefaultValidator.Validate()
98-
assert.NotEmpty(t, res.Errors, tt+" should have errors")
105+
assert.NotEmpty(t, res.Errors, tt+hasErrorMsg)
99106

100107
// Update: now we have an additional message to explain it's all about a default value
101108
// Example:
102109
// - default value for limit in query does not validate its Schema
103110
// - limit in query must be of type integer: "string"]
104-
assert.True(t, len(res.Errors) >= 1, tt+" should have at least 1 error")
111+
assert.NotEmptyf(t, res.Errors, tt+" should have at least 1 error")
105112
}
106113
}
107114

doc_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package validate_test
1717
import (
1818
"encoding/json"
1919
"fmt"
20-
"io/ioutil"
20+
"os"
2121
"path/filepath"
2222
"testing"
2323

@@ -196,7 +196,7 @@ func Test_Issue102_Circular(t *testing.T) {
196196
filepath.Join("fixtures", "bugs", "123-validate", "fixture-123.json"),
197197
} {
198198
t.Run(fixture, func(t *testing.T) {
199-
filebytes, err := ioutil.ReadFile(fixture)
199+
filebytes, err := os.ReadFile(fixture)
200200
require.NoError(t, err)
201201

202202
openAPIv2Doc := json.RawMessage(filebytes)
@@ -207,7 +207,7 @@ func Test_Issue102_Circular(t *testing.T) {
207207
validator := validate.NewSpecValidator(doc.Schema(), strfmt.Default)
208208
validator.SetContinueOnErrors(true)
209209
res, _ := validator.Validate(doc)
210-
require.Lenf(t, res.Errors, 0, "unexpected validation erorrs: %v", res.Errors)
210+
require.Emptyf(t, res.Errors, "unexpected validation erorrs: %v", res.Errors)
211211
})
212212
}
213213
}

example_validator.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ func (ex *exampleValidator) validateExampleInResponse(resp *spec.Response, respo
145145

146146
responseName, responseCodeAsStr := responseHelp.responseMsgVariants(responseType, responseCode)
147147

148-
// nolint: dupl
149148
if response.Headers != nil { // Safeguard
150149
for nm, h := range response.Headers {
151150
// reset explored schemas to get depth-first recursive-proof exploration
@@ -250,7 +249,8 @@ func (ex *exampleValidator) validateExampleValueSchemaAgainstSchema(path, in str
250249
}
251250

252251
// TODO: Temporary duplicated code. Need to refactor with examples
253-
// nolint: dupl
252+
//
253+
254254
func (ex *exampleValidator) validateExampleValueItemsAgainstSchema(path, in string, root interface{}, items *spec.Items) *Result {
255255
res := new(Result)
256256
s := ex.SpecValidator

example_validator_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestExample_ValidateExamples(t *testing.T) {
6969
validator := makeSpecValidator(t, path)
7070
myExampleValidator := &exampleValidator{SpecValidator: validator}
7171
res := myExampleValidator.Validate()
72-
assert.Empty(t, res.Errors, tt+" should not have errors")
72+
assert.Empty(t, res.Errors, tt+noErrorMsg)
7373
/*
7474
// Special case: warning only
7575
if tt == "parameter-required" {
@@ -90,17 +90,17 @@ func TestExample_ValidateExamples(t *testing.T) {
9090
switch tt {
9191
case "header-badpattern":
9292
// This fixture exhibits real errors besides example values
93-
assert.NotEmpty(t, res.Errors, tt+" should have errors")
94-
assert.NotEmpty(t, res.Warnings, tt+" should have warnings")
93+
assert.NotEmpty(t, res.Errors, tt+hasErrorMsg)
94+
assert.NotEmpty(t, res.Warnings, tt+hasWarningMsg)
9595
default:
96-
assert.Empty(t, res.Errors, tt+" should not have errors")
97-
assert.NotEmpty(t, res.Warnings, tt+" should have warnings")
96+
assert.Empty(t, res.Errors, tt+noErrorMsg)
97+
assert.NotEmpty(t, res.Warnings, tt+hasWarningMsg)
9898
}
9999
// Update: now we have an additional message to explain it's all about a default value
100100
// Example:
101101
// - default value for limit in query does not validate its Schema
102102
// - limit in query must be of type integer: "string"]
103-
assert.True(t, len(res.Warnings) >= 1, tt+" should have at least 1 warning")
103+
assert.NotEmptyf(t, res.Warnings, tt+" should have at least 1 warning")
104104

105105
debugTest(t, path, res)
106106
if DebugTest && t.Failed() {

0 commit comments

Comments
 (0)