Skip to content

Commit b59e589

Browse files
committed
chore: updated and relinted
* updated required go version to 1.19 * update lint config * relinted code * ci: updated github actions * doc: updated README badges Signed-off-by: Frederic BIDON <[email protected]>
1 parent 7df7a46 commit b59e589

File tree

6 files changed

+309
-202
lines changed

6 files changed

+309
-202
lines changed

.github/workflows/go-test.yml

+36-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,50 @@
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+
39+
- uses: actions/checkout@v3
2040

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

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

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
linters-settings:
2+
govet:
3+
check-shadowing: true
4+
golint:
5+
min-confidence: 0
6+
gocyclo:
7+
min-complexity: 45
8+
maligned:
9+
suggest-new: true
10+
dupl:
11+
threshold: 200
12+
goconst:
13+
min-len: 2
14+
min-occurrences: 3
15+
16+
linters:
17+
enable-all: true
18+
disable:
19+
- maligned
20+
- unparam
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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
# gojsonpointer [![Build Status](https://travis-ci.org/go-openapi/jsonpointer.svg?branch=master)](https://travis-ci.org/go-openapi/jsonpointer) [![codecov](https://codecov.io/gh/go-openapi/jsonpointer/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/jsonpointer) [![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io)
1+
# gojsonpointer [![Build Status](https://github.com/go-openapi/jsonpointer/actions/workflows/go-test.yml/badge.svg)](https://github.com/go-openapi/jsonpointer/actions?query=workflow%3A"go+test") [![codecov](https://codecov.io/gh/go-openapi/jsonpointer/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/jsonpointer)
2+
3+
[![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io)
4+
[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/jsonpointer/master/LICENSE)
5+
[![Go Reference](https://pkg.go.dev/badge/github.com/go-openapi/jsonpointer.svg)](https://pkg.go.dev/github.com/go-openapi/jsonpointer)
6+
[![Go Report Card](https://goreportcard.com/badge/github.com/go-openapi/jsonpointer)](https://goreportcard.com/report/github.com/go-openapi/jsonpointer)
27

3-
[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/jsonpointer/master/LICENSE) [![GoDoc](https://godoc.org/github.com/go-openapi/jsonpointer?status.svg)](http://godoc.org/github.com/go-openapi/jsonpointer)
48
An implementation of JSON Pointer - Go language
59

610
## Status

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
module github.com/go-openapi/jsonpointer
22

3-
go 1.18
4-
53
require (
64
github.com/go-openapi/swag v0.22.4
75
github.com/stretchr/testify v1.8.4
@@ -15,3 +13,5 @@ require (
1513
github.com/pmezard/go-difflib v1.0.0 // indirect
1614
gopkg.in/yaml.v3 v3.0.1 // indirect
1715
)
16+
17+
go 1.19

pointer.go

+22-22
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func getSingleImpl(node any, decodedToken string, nameProvider *swag.NameProvide
122122
return r, kind, nil
123123
}
124124

125-
switch kind {
125+
switch kind { //nolint:exhaustive
126126
case reflect.Struct:
127127
nm, ok := nameProvider.GetGoNameForType(rValue.Type(), decodedToken)
128128
if !ok {
@@ -170,7 +170,7 @@ func setSingleImpl(node, data any, decodedToken string, nameProvider *swag.NameP
170170
return node.(JSONSetable).JSONSet(decodedToken, data)
171171
}
172172

173-
switch rValue.Kind() {
173+
switch rValue.Kind() { //nolint:exhaustive
174174
case reflect.Struct:
175175
nm, ok := nameProvider.GetGoNameForType(rValue.Type(), decodedToken)
176176
if !ok {
@@ -231,8 +231,7 @@ func (p *Pointer) get(node any, nameProvider *swag.NameProvider) (any, reflect.K
231231
if err != nil {
232232
return nil, knd, err
233233
}
234-
node, kind = r, knd
235-
234+
node = r
236235
}
237236

238237
rValue := reflect.ValueOf(node)
@@ -284,7 +283,7 @@ func (p *Pointer) set(node, data any, nameProvider *swag.NameProvider) error {
284283
continue
285284
}
286285

287-
switch kind {
286+
switch kind { //nolint:exhaustive
288287
case reflect.Struct:
289288
nm, ok := nameProvider.GetGoNameForType(rValue.Type(), decodedToken)
290289
if !ok {
@@ -405,11 +404,11 @@ func offsetSingleObject(dec *json.Decoder, decodedToken string) (int64, error) {
405404
case json.Delim:
406405
switch tk {
407406
case '{':
408-
if err := drainSingle(dec); err != nil {
407+
if err = drainSingle(dec); err != nil {
409408
return 0, err
410409
}
411410
case '[':
412-
if err := drainSingle(dec); err != nil {
411+
if err = drainSingle(dec); err != nil {
413412
return 0, err
414413
}
415414
}
@@ -435,48 +434,49 @@ func offsetSingleArray(dec *json.Decoder, decodedToken string) (int64, error) {
435434
if err != nil {
436435
return 0, err
437436
}
438-
switch tk := tk.(type) {
439-
case json.Delim:
440-
switch tk {
437+
438+
if delim, isDelim := tk.(json.Delim); isDelim {
439+
switch delim {
441440
case '{':
442-
if err := drainSingle(dec); err != nil {
441+
if err = drainSingle(dec); err != nil {
443442
return 0, err
444443
}
445444
case '[':
446-
if err := drainSingle(dec); err != nil {
445+
if err = drainSingle(dec); err != nil {
447446
return 0, err
448447
}
449448
}
450449
}
451450
}
451+
452452
if !dec.More() {
453453
return 0, fmt.Errorf("token reference %q not found", decodedToken)
454454
}
455455
return dec.InputOffset(), nil
456456
}
457457

458458
// drainSingle drains a single level of object or array.
459-
// The decoder has to guarantee the begining delim (i.e. '{' or '[') has been consumed.
459+
// The decoder has to guarantee the beginning delim (i.e. '{' or '[') has been consumed.
460460
func drainSingle(dec *json.Decoder) error {
461461
for dec.More() {
462462
tk, err := dec.Token()
463463
if err != nil {
464464
return err
465465
}
466-
switch tk := tk.(type) {
467-
case json.Delim:
468-
switch tk {
466+
if delim, isDelim := tk.(json.Delim); isDelim {
467+
switch delim {
469468
case '{':
470-
if err := drainSingle(dec); err != nil {
469+
if err = drainSingle(dec); err != nil {
471470
return err
472471
}
473472
case '[':
474-
if err := drainSingle(dec); err != nil {
473+
if err = drainSingle(dec); err != nil {
475474
return err
476475
}
477476
}
478477
}
479478
}
479+
480480
// Consumes the ending delim
481481
if _, err := dec.Token(); err != nil {
482482
return err
@@ -498,14 +498,14 @@ const (
498498

499499
// Unescape unescapes a json pointer reference token string to the original representation
500500
func Unescape(token string) string {
501-
step1 := strings.Replace(token, encRefTok1, decRefTok1, -1)
502-
step2 := strings.Replace(step1, encRefTok0, decRefTok0, -1)
501+
step1 := strings.ReplaceAll(token, encRefTok1, decRefTok1)
502+
step2 := strings.ReplaceAll(step1, encRefTok0, decRefTok0)
503503
return step2
504504
}
505505

506506
// Escape escapes a pointer reference token string
507507
func Escape(token string) string {
508-
step1 := strings.Replace(token, decRefTok0, encRefTok0, -1)
509-
step2 := strings.Replace(step1, decRefTok1, encRefTok1, -1)
508+
step1 := strings.ReplaceAll(token, decRefTok0, encRefTok0)
509+
step2 := strings.ReplaceAll(step1, decRefTok1, encRefTok1)
510510
return step2
511511
}

0 commit comments

Comments
 (0)