Skip to content

Commit 8dae707

Browse files
authored
Updated linting (#46)
* Updated linting & dependencies * updated golangci lint rules * updated github actions * update required go version to go 1.19, in line with other go-openapi packages * updated dependencies * adapted YAMLToJSON tests to yaml/v3 (with new version of go-openapi/swag) * fixed dead links/badges in README * relinted (tests and docstrings) * removed unexecuted integration tests Signed-off-by: Frederic BIDON <[email protected]> * fixed typo in badge link Signed-off-by: Frederic BIDON <[email protected]> --------- Signed-off-by: Frederic BIDON <[email protected]>
1 parent b780aa6 commit 8dae707

18 files changed

+320
-570
lines changed

.github/workflows/go-test.yml

+35-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,49 @@
1-
name: Go Test
1+
name: go test
22

3-
on: [push]
3+
on: [push, pull_request]
44

55
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
621

722
test:
8-
9-
name: Test
23+
name: Unit tests
1024
runs-on: ${{ matrix.os }}
1125

1226
strategy:
1327
matrix:
1428
os: [ ubuntu-latest, macos-latest, windows-latest ]
15-
steps:
29+
go_version: ['oldstable', 'stable' ]
1630

17-
- uses: actions/setup-go@v2
31+
steps:
32+
- name: Run unit tests
33+
uses: actions/setup-go@v4
1834
with:
19-
go-version: 1.x
35+
go-version: '${{ matrix.go_version }}'
36+
check-latest: true
37+
cache: true
38+
- uses: actions/checkout@v3
2039

21-
- uses: actions/checkout@v2
40+
- run: go test -v -race -coverprofile="coverage-${{ matrix.os }}.${{ matrix.go_version }}.out" -covermode=atomic ./...
2241

23-
- run: go test
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

.golangci.yml

+33-16
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,58 @@ linters-settings:
44
golint:
55
min-confidence: 0
66
gocyclo:
7-
min-complexity: 30
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:
1717
enable-all: true
1818
disable:
1919
- maligned
20+
- unparam
2021
- lll
21-
- gochecknoglobals
2222
- gochecknoinits
23+
- gochecknoglobals
24+
- funlen
2325
- godox
2426
- gocognit
2527
- whitespace
2628
- wsl
27-
- funlen
28-
- gochecknoglobals
29-
- gochecknoinits
30-
- scopelint
3129
- wrapcheck
32-
- exhaustivestruct
33-
- exhaustive
34-
- nlreturn
3530
- testpackage
36-
- gci
37-
- gofumpt
38-
- goerr113
31+
- nlreturn
3932
- gomnd
40-
- tparallel
33+
- exhaustivestruct
34+
- goerr113
35+
- errorlint
4136
- nestif
4237
- godot
43-
- errorlint
38+
- gofumpt
4439
- 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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Loads OAI specs [![Build Status](https://travis-ci.org/go-openapi/loads.svg?branch=master)](https://travis-ci.org/go-openapi/loads) [![codecov](https://codecov.io/gh/go-openapi/loads/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/loads) [![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io) [![Actions/Go Test Status](https://github.com/go-openapi/loads/workflows/Go%20Test/badge.svg)](https://github.com/go-openapi/loads/actions?query=workflow%3A"Go+Test")
1+
# Loads OAI specs [![Build Status](https://github.com/go-openapi/loads/actions/workflows/go-test.yml/badge.svg)](https://github.com/go-openapi/loads/actions?query=workflow%3A"go+test") [![codecov](https://codecov.io/gh/go-openapi/loads/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/lods)
22

33
[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/loads/master/LICENSE) [![GoDoc](https://godoc.org/github.com/go-openapi/loads?status.svg)](http://godoc.org/github.com/go-openapi/loads)
44
[![Go Report Card](https://goreportcard.com/badge/github.com/go-openapi/loads)](https://goreportcard.com/report/github.com/go-openapi/loads)

TODO.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[x] why not filepath in JSONDoc()
2+
[] integration tests package
3+
[] relint

doc.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
/*
16-
Package loads provides document loading methods for swagger (OAI) specifications.
17-
18-
It is used by other go-openapi packages to load and run analysis on local or remote spec documents.
19-
20-
*/
15+
// Package loads provides document loading methods for swagger (OAI) specifications.
16+
//
17+
// It is used by other go-openapi packages to load and run analysis on local or remote spec documents.
2118
package loads

doc_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package loads_test
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
6+
"os"
77
"path/filepath"
88

99
"github.com/go-openapi/loads"
@@ -25,15 +25,15 @@ func ExampleSpec() {
2525
// Output: Spec loaded: "api.example.com"
2626
}
2727

28-
func ExampleOption() {
28+
func ExampleLoaderOption() {
2929
// Example with custom loaders passed as options
3030

3131
path := "fixtures/yaml/swagger/spec.yml"
3232

3333
// a simpler version of loads.JSONDoc
3434
jsonLoader := loads.NewDocLoaderWithMatch(
3535
func(pth string) (json.RawMessage, error) {
36-
buf, err := ioutil.ReadFile(pth)
36+
buf, err := os.ReadFile(pth)
3737
return json.RawMessage(buf), err
3838
},
3939
func(pth string) bool {

example_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package loads

0 commit comments

Comments
 (0)