From f92f88187733cc62254922647c99cbace8361467 Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Tue, 16 Aug 2022 21:03:29 +0100 Subject: [PATCH] Add linting with golangci-lint To give a bit more consistency across the project with the Go ecosystem, as well as picking up on some common errors that new contributions can bring, enable golangci-lint, with default configuration. --- .github/workflows/lint.yml | 20 ++++++++++++++++++++ Makefile | 12 ++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000000..6757ff953e --- /dev/null +++ b/.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 diff --git a/Makefile b/Makefile index 146075bc82..f76755631c 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +GOBASE=$(shell pwd) +GOBIN=$(GOBASE)/bin + help: @echo "This is a helper makefile for oapi-codegen" @echo "Targets:" @@ -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 ./...