From e8151336008ade144852b1a16a15aa654ed72565 Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Sun, 5 Oct 2025 18:58:46 +0200 Subject: [PATCH] Update linter, fix code style --- .github/workflows/golangci-lint.yml | 4 +- .github/workflows/test-unit.yml | 5 +- .gitignore | 2 - .golangci.yml | 126 ++++++++++++++++------------ Makefile | 5 +- go.mod | 2 +- go.sum | 4 +- openapi3/entities.go | 1 - openapi3/example_misc_test.go | 2 +- openapi3/reflect.go | 1 + openapi31/entities.go | 1 - openapi31/example_misc_test.go | 2 +- openapi31/reflect.go | 1 + openapi31/reflect_test.go | 1 + 14 files changed, 86 insertions(+), 71 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index a3b265d..d9e1bb6 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -24,10 +24,10 @@ jobs: go-version: stable - uses: actions/checkout@v4 - name: golangci-lint - uses: golangci/golangci-lint-action@v6.5.0 + uses: golangci/golangci-lint-action@v8.0.0 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.64.5 + version: v2.5.0 # Optional: working directory, useful for monorepos # working-directory: somedir diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml index 013d8f2..1593f19 100644 --- a/.github/workflows/test-unit.yml +++ b/.github/workflows/test-unit.yml @@ -80,8 +80,9 @@ jobs: curl -sLO https://github.com/vearutop/gocovdiff/releases/download/v1.4.2/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz && rm linux_amd64.tar.gz gocovdiff_hash=$(git hash-object ./gocovdiff) [ "$gocovdiff_hash" == "c37862c73a677e5a9c069470287823ab5bbf0244" ] || (echo "::error::unexpected hash for gocovdiff, possible tampering: $gocovdiff_hash" && exit 1) - git fetch origin master ${{ github.event.pull_request.base.sha }} - REP=$(./gocovdiff -mod github.com/$GITHUB_REPOSITORY -cov unit.coverprofile -gha-annotations gha-unit.txt -delta-cov-file delta-cov-unit.txt -target-delta-cov ${TARGET_DELTA_COV}) + # Fetch PR diff from GitHub API. + curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3.diff" https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} > pull_request.diff + REP=$(./gocovdiff -diff pull_request.diff -mod github.com/$GITHUB_REPOSITORY -cov unit.coverprofile -gha-annotations gha-unit.txt -delta-cov-file delta-cov-unit.txt -target-delta-cov ${TARGET_DELTA_COV}) echo "${REP}" cat gha-unit.txt DIFF=$(test -e unit-base.txt && ./gocovdiff -mod github.com/$GITHUB_REPOSITORY -func-cov unit.txt -func-base-cov unit-base.txt || echo "Missing base coverage file") diff --git a/.gitignore b/.gitignore index 0dd7783..ed77e49 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,3 @@ /.vscode /bench-*.txt /vendor -go.work -go.work.sum diff --git a/.golangci.yml b/.golangci.yml index f3269dd..7cabaa2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,22 +1,9 @@ -# See https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml +# See https://golangci-lint.run/docs/linters/configuration/ +version: "2" run: tests: true - -linters-settings: - errcheck: - check-type-assertions: true - check-blank: true - gocyclo: - min-complexity: 20 - dupl: - threshold: 100 - misspell: - locale: US - unparam: - check-exported: true - linters: - enable-all: true + default: all disable: - nilnil - err113 @@ -26,48 +13,79 @@ linters: - gocognit - musttag - intrange + - noinlineerr + - wsl_v5 + - funcorder - copyloopvar - - lll - - gochecknoglobals - - wrapcheck - - paralleltest + - depguard + - dupword + - errname + - exhaustruct - forbidigo - forcetypeassert - - varnamelen - - tagliatelle - - errname + - gochecknoglobals + - intrange - ireturn - - exhaustruct + - lll + - mnd - nonamedreturns - - testableexamples - - dupword - - depguard + - paralleltest + - recvcheck - tagalign - - mnd + - tagliatelle + - testableexamples - testifylint - - recvcheck - -issues: - exclude-use-default: false - exclude-rules: - - linters: - - staticcheck - text: "SA1019: strings.Title .+ deprecated" - - - linters: - - mnd - - goconst - - noctx - - funlen - - dupl - - unused - - unparam - path: "_test.go" - - linters: - - errcheck # Error checking omitted for brevity. - - gosec - path: "example_" - - linters: - - revive - text: "unused-parameter: parameter" - + - varnamelen + - wrapcheck + settings: + dupl: + threshold: 100 + errcheck: + check-type-assertions: true + check-blank: true + gocyclo: + min-complexity: 20 + misspell: + locale: US + unparam: + check-exported: true + exclusions: + generated: lax + rules: + - linters: + - embeddedstructfieldcheck + - gosec + - dupl + - funlen + - goconst + - mnd + - noctx + - unparam + - unused + path: _test.go + - linters: + - errcheck + - gosec + path: example_ + - linters: + - revive + text: 'unused-parameter: parameter' + - linters: + - staticcheck + text: "SA1019: strings.Title .+ deprecated" + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gci + - gofmt + - gofumpt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index 4f4b2fa..3e67f39 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -#GOLANGCI_LINT_VERSION := "v1.64.5" # Optional configuration to pinpoint golangci-lint version. +#GOLANGCI_LINT_VERSION := "v2.5.0" # Optional configuration to pinpoint golangci-lint version. # The head of Makefile determines location of dev-go to include standard targets. GO ?= go @@ -27,9 +27,6 @@ ifeq ($(DEVGO_PATH),) endif endif -JSON_CLI_VERSION := "v1.8.6" -JSON_CLI_VERSION_31 := "v1.11.1" - -include $(DEVGO_PATH)/makefiles/main.mk -include $(DEVGO_PATH)/makefiles/lint.mk -include $(DEVGO_PATH)/makefiles/test-unit.mk diff --git a/go.mod b/go.mod index 615ab27..e308077 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/swaggest/openapi-go go 1.18 require ( - github.com/bool64/dev v0.2.39 + github.com/bool64/dev v0.2.43 github.com/stretchr/testify v1.8.2 github.com/swaggest/assertjson v1.9.0 github.com/swaggest/jsonschema-go v0.3.74 diff --git a/go.sum b/go.sum index 18c42e7..da9dc93 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/bool64/dev v0.2.39 h1:kP8DnMGlWXhGYJEZE/J0l/gVBdbuhoPGL+MJG4QbofE= -github.com/bool64/dev v0.2.39/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg= +github.com/bool64/dev v0.2.43 h1:yQ7qiZVef6WtCl2vDYU0Y+qSq+0aBrQzY8KXkklk9cQ= +github.com/bool64/dev v0.2.43/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg= github.com/bool64/shared v0.1.5 h1:fp3eUhBsrSjNCQPcSdQqZxxh9bBwrYiZ+zOKFkM0/2E= github.com/bool64/shared v0.1.5/go.mod h1:081yz68YC9jeFB3+Bbmno2RFWvGKv1lPKkMP6MHJlPs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/openapi3/entities.go b/openapi3/entities.go index 7142a4f..356433a 100644 --- a/openapi3/entities.go +++ b/openapi3/entities.go @@ -1,6 +1,5 @@ // Code generated by github.com/swaggest/json-cli v1.8.6, DO NOT EDIT. -// Package openapi3 contains JSON mapping structures. package openapi3 import ( diff --git a/openapi3/example_misc_test.go b/openapi3/example_misc_test.go index 3337482..ee059fe 100644 --- a/openapi3/example_misc_test.go +++ b/openapi3/example_misc_test.go @@ -14,7 +14,7 @@ func ExampleReflector_options() { r := openapi3.Reflector{} // Reflector embeds jsonschema.Reflector and it is possible to configure optional behavior. - r.Reflector.DefaultOptions = append(r.Reflector.DefaultOptions, + r.DefaultOptions = append(r.DefaultOptions, jsonschema.InterceptNullability(func(params jsonschema.InterceptNullabilityParams) { // Removing nullability from non-pointer slices (regardless of omitempty). if params.Type.Kind() != reflect.Ptr && params.Schema.HasType(jsonschema.Null) && params.Schema.HasType(jsonschema.Array) { diff --git a/openapi3/reflect.go b/openapi3/reflect.go index 03603a7..8f9d147 100644 --- a/openapi3/reflect.go +++ b/openapi3/reflect.go @@ -18,6 +18,7 @@ import ( // Reflector builds OpenAPI Schema with reflected structures. type Reflector struct { jsonschema.Reflector + Spec *Spec } diff --git a/openapi31/entities.go b/openapi31/entities.go index 35a128e..e84efa5 100644 --- a/openapi31/entities.go +++ b/openapi31/entities.go @@ -1,6 +1,5 @@ // Code generated by github.com/swaggest/json-cli v1.11.1, DO NOT EDIT. -// Package openapi31 contains JSON mapping structures. package openapi31 import ( diff --git a/openapi31/example_misc_test.go b/openapi31/example_misc_test.go index 79642bf..e5be0e1 100644 --- a/openapi31/example_misc_test.go +++ b/openapi31/example_misc_test.go @@ -14,7 +14,7 @@ func ExampleReflector_options() { r := openapi31.Reflector{} // Reflector embeds jsonschema.Reflector and it is possible to configure optional behavior. - r.Reflector.DefaultOptions = append(r.Reflector.DefaultOptions, + r.DefaultOptions = append(r.DefaultOptions, jsonschema.InterceptNullability(func(params jsonschema.InterceptNullabilityParams) { // Removing nullability from non-pointer slices (regardless of omitempty). if params.Type.Kind() != reflect.Ptr && params.Schema.HasType(jsonschema.Null) && params.Schema.HasType(jsonschema.Array) { diff --git a/openapi31/reflect.go b/openapi31/reflect.go index bf82ac1..4be25f9 100644 --- a/openapi31/reflect.go +++ b/openapi31/reflect.go @@ -18,6 +18,7 @@ import ( // Reflector builds OpenAPI Schema with reflected structures. type Reflector struct { jsonschema.Reflector + Spec *Spec } diff --git a/openapi31/reflect_test.go b/openapi31/reflect_test.go index 8cf65e1..4747569 100644 --- a/openapi31/reflect_test.go +++ b/openapi31/reflect_test.go @@ -27,6 +27,7 @@ type EmbeddedHeader struct { type Resp struct { EmbeddedHeader + Field1 int `json:"field1"` Field2 string `json:"field2"` Info struct {