Skip to content

Commit

Permalink
Updated linting (#46)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
fredbi committed Dec 5, 2023
1 parent b780aa6 commit 8dae707
Show file tree
Hide file tree
Showing 18 changed files with 320 additions and 570 deletions.
44 changes: 35 additions & 9 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
name: Go Test
name: go test

on: [push]
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: Test
name: Unit tests
runs-on: ${{ matrix.os }}

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

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

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

- run: go test
- 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
49 changes: 33 additions & 16 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,58 @@ linters-settings:
golint:
min-confidence: 0
gocyclo:
min-complexity: 30
min-complexity: 45
maligned:
suggest-new: true
dupl:
threshold: 100
threshold: 200
goconst:
min-len: 2
min-occurrences: 4
min-occurrences: 3

linters:
enable-all: true
disable:
- maligned
- unparam
- lll
- gochecknoglobals
- gochecknoinits
- gochecknoglobals
- funlen
- godox
- gocognit
- whitespace
- wsl
- funlen
- gochecknoglobals
- gochecknoinits
- scopelint
- wrapcheck
- exhaustivestruct
- exhaustive
- nlreturn
- testpackage
- gci
- gofumpt
- goerr113
- nlreturn
- gomnd
- tparallel
- exhaustivestruct
- goerr113
- errorlint
- nestif
- godot
- errorlint
- 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 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")
# 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)

[![license](https://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)](https://godoc.org/github.com/go-openapi/loads)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-openapi/loads)](https://goreportcard.com/report/github.com/go-openapi/loads)
Expand Down
3 changes: 3 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[x] why not filepath in JSONDoc()
[] integration tests package
[] relint
9 changes: 3 additions & 6 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

/*
Package loads provides document loading methods for swagger (OAI) specifications.
It is used by other go-openapi packages to load and run analysis on local or remote spec documents.
*/
// Package loads provides document loading methods for swagger (OAI) specifications.
//
// It is used by other go-openapi packages to load and run analysis on local or remote spec documents.
package loads
6 changes: 3 additions & 3 deletions doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package loads_test
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"

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

func ExampleOption() {
func ExampleLoaderOption() {
// Example with custom loaders passed as options

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

// a simpler version of loads.JSONDoc
jsonLoader := loads.NewDocLoaderWithMatch(
func(pth string) (json.RawMessage, error) {
buf, err := ioutil.ReadFile(pth)
buf, err := os.ReadFile(pth)
return json.RawMessage(buf), err
},
func(pth string) bool {
Expand Down
1 change: 1 addition & 0 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package loads
Loading

0 comments on commit 8dae707

Please sign in to comment.