Skip to content

Commit

Permalink
Merge pull request deepmap#722 from jamietanna/chore/golangci-lint
Browse files Browse the repository at this point in the history
Add linting with golangci-lint
  • Loading branch information
jamietanna committed Nov 23, 2022
2 parents 5dc40eb + 2a62eb7 commit b40b341
Show file tree
Hide file tree
Showing 47 changed files with 190 additions and 150 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/lint.yml
@@ -0,0 +1,20 @@
name: Lint project
on: [push, pull_request]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Make sure this matches the version we've got in our `Makefile`
version: v1.50.1
12 changes: 12 additions & 0 deletions Makefile
@@ -1,3 +1,6 @@
GOBASE=$(shell pwd)
GOBIN=$(GOBASE)/bin

help:
@echo "This is a helper makefile for oapi-codegen"
@echo "Targets:"
Expand All @@ -6,6 +9,15 @@ help:
@echo " gin_example generate gin example server code"
@echo " tidy tidy go mod"

$(GOBIN)/golangci-lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.50.1

.PHONY: tools
tools: $(GOBIN)/golangci-lint

lint: tools
$(GOBIN)/golangci-lint run ./...

generate:
go generate ./...

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -12,6 +12,7 @@ require (
github.com/lestrrat-go/jwx v1.2.25
github.com/matryer/moq v0.2.7
github.com/stretchr/testify v1.8.1
golang.org/x/text v0.4.0
golang.org/x/tools v0.2.0
gopkg.in/yaml.v2 v2.4.0
)
Expand Down Expand Up @@ -54,7 +55,6 @@ require (
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
google.golang.org/protobuf v1.28.1 // indirect
Expand Down
2 changes: 1 addition & 1 deletion internal/test/all_of/doc.go
@@ -1,4 +1,4 @@
package all_of
package allof

//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --config=config1.yaml openapi.yaml
//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --config=config2.yaml openapi.yaml
2 changes: 1 addition & 1 deletion internal/test/components/components_test.go
Expand Up @@ -87,7 +87,7 @@ func TestOneOf(t *testing.T) {
assert.NoError(t, err)
v2, err := dst.AsOneOfVariant2()
assert.NoError(t, err)
assert.Equal(t, OneOfVariant2([]int{1, 2, 3}), v2)
assert.Equal(t, []int{1, 2, 3}, v2)

err = json.Unmarshal([]byte(variant3), &dst)
assert.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions internal/test/externalref/imports_test.go
Expand Up @@ -3,8 +3,8 @@ package externalref
import (
"testing"

"github.com/deepmap/oapi-codegen/internal/test/externalref/packageA"
"github.com/deepmap/oapi-codegen/internal/test/externalref/packageB"
packageA "github.com/deepmap/oapi-codegen/internal/test/externalref/packageA"
packageB "github.com/deepmap/oapi-codegen/internal/test/externalref/packageB"
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/test/externalref/packageA/config.yaml
@@ -1,4 +1,4 @@
package: packageA
package: packagea
generate:
models: true
embedded-spec: true
Expand Down
2 changes: 1 addition & 1 deletion internal/test/externalref/packageA/doc.go
@@ -1,3 +1,3 @@
package packageA
package packagea

//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --config=config.yaml spec.yaml
4 changes: 2 additions & 2 deletions internal/test/externalref/packageA/externalref.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/test/externalref/packageB/config.yaml
@@ -1,4 +1,4 @@
package: packageB
package: packageb
generate:
models: true
embedded-spec: true
Expand Down
2 changes: 1 addition & 1 deletion internal/test/externalref/packageB/doc.go
@@ -1,3 +1,3 @@
package packageB
package packageb

//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --config=config.yaml spec.yaml
4 changes: 2 additions & 2 deletions internal/test/externalref/packageB/externalref.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/test/issues/issue-312/config.yaml
@@ -1,4 +1,4 @@
package: issue_312
package: issue312
generate:
echo-server: true
client: true
Expand Down
2 changes: 1 addition & 1 deletion internal/test/issues/issue-312/doc.go
@@ -1,3 +1,3 @@
package issue_312
package issue312

//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --config=config.yaml spec.yaml
4 changes: 2 additions & 2 deletions internal/test/issues/issue-312/issue.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions internal/test/issues/issue-312/issue_test.go
@@ -1,4 +1,4 @@
package issue_312
package issue312

import (
"context"
Expand Down Expand Up @@ -26,7 +26,8 @@ func TestClient_WhenPathHasColon_RequestHasCorrectPath(t *testing.T) {
assert.Equal(t, "http://host/pets:validate", req.URL.String())
})

client.ValidatePetsWithResponse(context.Background(), ValidatePetsJSONRequestBody{
// TODO: this err should be checked, but it defaults to returning the "something went wrong", so we should refactor accordingly
_, _ = client.ValidatePetsWithResponse(context.Background(), ValidatePetsJSONRequestBody{
Names: []string{"fido"},
})
doer.AssertExpectations(t)
Expand All @@ -43,7 +44,8 @@ func TestClient_WhenPathHasId_RequestHasCorrectPath(t *testing.T) {
assert.Equal(t, "/pets/id", req.URL.Path)
})
petID := "id"
client.GetPetWithResponse(context.Background(), petID)
// TODO: this err should be checked, but it defaults to returning the "something went wrong", so we should refactor accordingly
_, _ = client.GetPetWithResponse(context.Background(), petID)
doer.AssertExpectations(t)
}

Expand All @@ -58,7 +60,8 @@ func TestClient_WhenPathHasIdContainingReservedCharacter_RequestHasCorrectPath(t
assert.Equal(t, "http://host/pets/id1%2Fid2", req.URL.String())
})
petID := "id1/id2"
client.GetPetWithResponse(context.Background(), petID)
// TODO: this err should be checked, but it defaults to returning the "something went wrong", so we should refactor accordingly
_, _ = client.GetPetWithResponse(context.Background(), petID)
doer.AssertExpectations(t)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/test/issues/issue-52/config.yaml
@@ -1,4 +1,4 @@
package: issue_52
package: issue52
generate:
echo-server: true
client: true
Expand Down
2 changes: 1 addition & 1 deletion internal/test/issues/issue-52/doc.go
@@ -1,3 +1,3 @@
package issue_52
package issue52

//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --config=config.yaml spec.yaml
4 changes: 2 additions & 2 deletions internal/test/issues/issue-52/issue.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/test/issues/issue-52/issue_test.go
@@ -1,4 +1,4 @@
package issue_52
package issue52

import (
_ "embed"
Expand All @@ -17,7 +17,7 @@ func TestIssue(t *testing.T) {
require.NoError(t, err)

opts := codegen.Configuration{
PackageName: "issue_52",
PackageName: "issue52",
Generate: codegen.GenerateOptions{
EchoServer: true,
Client: true,
Expand Down
4 changes: 2 additions & 2 deletions internal/test/issues/issue-579/gen.go
@@ -1,3 +1,3 @@
package issue_579
package issue579

//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --package=issue_579 --generate=types,skip-prune --alias-types -o issue.gen.go spec.yaml
//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --package=issue579 --generate=types,skip-prune --alias-types -o issue.gen.go spec.yaml
4 changes: 2 additions & 2 deletions internal/test/issues/issue-579/issue.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/test/issues/issue-579/issue_test.go
@@ -1,4 +1,4 @@
package issue_579
package issue579

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion internal/test/issues/issue-grab_import_names/config.yaml
@@ -1,4 +1,4 @@
package: grab_import_names
package: grabimportnames
generate:
echo-server: true
client: true
Expand Down
2 changes: 1 addition & 1 deletion internal/test/issues/issue-grab_import_names/doc.go
@@ -1,3 +1,3 @@
package grab_import_names
package grabimportnames

//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --config=config.yaml spec.yaml
4 changes: 2 additions & 2 deletions internal/test/issues/issue-grab_import_names/issue.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/test/issues/issue-grab_import_names/issue_test.go
@@ -1,4 +1,4 @@
package grab_import_names
package grabimportnames

import (
"testing"
Expand All @@ -13,7 +13,7 @@ func TestLineComments(t *testing.T) {
require.NoError(t, err)

opts := codegen.Configuration{
PackageName: "grab_import_names",
PackageName: "grabimportnames",
Generate: codegen.GenerateOptions{
EchoServer: true,
Client: true,
Expand Down
@@ -1,5 +1,5 @@
---
package: head_digit_of_httpheader
package: headdigitofhttpheader
generate:
strict-server: true
output: issue.gen.go
Expand Down
2 changes: 1 addition & 1 deletion internal/test/issues/issue-head-digit-of-httpheader/doc.go
@@ -1,3 +1,3 @@
package head_digit_of_httpheader
package headdigitofhttpheader

//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --config=config.yaml spec.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/test/issues/issue-illegal_enum_names/config.yaml
@@ -1,4 +1,4 @@
package: illegal_enum_names
package: illegalenumnames
generate:
echo-server: true
client: true
Expand Down
2 changes: 1 addition & 1 deletion internal/test/issues/issue-illegal_enum_names/doc.go
@@ -1,3 +1,3 @@
package illegal_enum_names
package illegalenumnames

//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --config=config.yaml spec.yaml
4 changes: 2 additions & 2 deletions internal/test/issues/issue-illegal_enum_names/issue.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/test/issues/issue-illegal_enum_names/issue_test.go
@@ -1,4 +1,4 @@
package illegal_enum_names
package illegalenumnames

import (
"go/ast"
Expand All @@ -16,7 +16,7 @@ func TestIllegalEnumNames(t *testing.T) {
require.NoError(t, err)

opts := codegen.Configuration{
PackageName: "illegal_enum_names",
PackageName: "illegalenumnames",
Generate: codegen.GenerateOptions{
EchoServer: true,
Client: true,
Expand Down
2 changes: 1 addition & 1 deletion internal/test/strict-server/echo/server.go
Expand Up @@ -94,7 +94,7 @@ func (s StrictServer) URLEncodedExample(ctx context.Context, request URLEncodedE
}

func (s StrictServer) HeadersExample(ctx context.Context, request HeadersExampleRequestObject) (HeadersExampleResponseObject, error) {
return HeadersExample200JSONResponse{Body: Example(*request.Body), Headers: HeadersExample200ResponseHeaders{Header1: request.Params.Header1, Header2: *request.Params.Header2}}, nil
return HeadersExample200JSONResponse{Body: *request.Body, Headers: HeadersExample200ResponseHeaders{Header1: request.Params.Header1, Header2: *request.Params.Header2}}, nil
}

func (s StrictServer) ReusableResponses(ctx context.Context, request ReusableResponsesRequestObject) (ReusableResponsesResponseObject, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/test/strict-server/strict_test.go
@@ -1,4 +1,4 @@
package strict_server
package strictserver

import (
"bytes"
Expand Down

0 comments on commit b40b341

Please sign in to comment.