From 9346e328ef8616a85d10031419ecf8488dc8c265 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Wed, 18 Dec 2019 14:55:52 +0100 Subject: [PATCH 1/2] Add golangci linter --- .github/workflows/ci.yml | 3 +++ .golangci.yml | 45 ++++++++++++++++++++++++++++++++++++++++ Makefile | 23 +++++++++++++++++--- 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3027be5f..46c9c928 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,6 +71,9 @@ jobs: - name: Run Kubernetes tests run: ./scripts/test-k8s.sh + - name: Run linter + run: make lint + # Ensure proto generation doesn't depend on external packages. - name: Verify proto run: make verify-proto diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..824484d6 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,45 @@ +run: + skip-dirs: + - vendor + +linters-settings: + golint: + min-confidence: 0.1 + goimports: + local-prefixes: github.com/dexidp/dex + +linters: + enable-all: true + disable: + - funlen + - maligned + - wsl + + # TODO: fix me + - unused + - structcheck + - stylecheck + - deadcode + - misspell + - unparam + - goimports + - golint + - whitespace + - goconst + - unconvert + - bodyclose + - staticcheck + - nakedret + - ineffassign + - errcheck + - gosec + - gochecknoinits + - gochecknoglobals + - prealloc + - scopelint + - lll + - dupl + - gocritic + - gocyclo + - gocognit + - godox diff --git a/Makefile b/Makefile index 820e7ea3..c1c6d788 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,9 @@ export GOBIN=$(PWD)/bin LD_FLAGS="-w -X $(REPO_PATH)/version.Version=$(VERSION)" +# Dependency versions +GOLANGCI_VERSION = 1.21.0 + build: bin/dex bin/example-app bin/grpc-client bin/dex: @@ -45,13 +48,27 @@ test: testrace: @go test -v --race ./... +bin/golangci-lint: bin/golangci-lint-${GOLANGCI_VERSION} + @ln -sf golangci-lint-${GOLANGCI_VERSION} bin/golangci-lint +bin/golangci-lint-${GOLANGCI_VERSION}: + curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | BINARY=golangci-lint bash -s -- v${GOLANGCI_VERSION} + @mv bin/golangci-lint $@ + +.PHONY: lint +lint: bin/golangci-lint ## Run linter + bin/golangci-lint run + +.PHONY: fix +fix: bin/golangci-lint ## Fix lint violations + bin/golangci-lint run --fix + vet: @go vet ./... fmt: @./scripts/gofmt ./... -lint: bin/golint +oldlint: bin/golint @./bin/golint -set_exit_status $(shell go list ./...) .PHONY: docker-image @@ -79,8 +96,8 @@ bin/golint: clean: @rm -rf bin/ -testall: testrace vet fmt lint +testall: testrace vet fmt oldlint FORCE: -.PHONY: test testrace vet fmt lint testall +.PHONY: test testrace vet fmt oldlint testall From bcd47fc6f37c7d51222faf248ed7a08e58448b81 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Wed, 18 Dec 2019 15:07:53 +0100 Subject: [PATCH 2/2] Remove old lint targets --- Makefile | 17 ++--------------- scripts/gofmt | 7 ------- 2 files changed, 2 insertions(+), 22 deletions(-) delete mode 100755 scripts/gofmt diff --git a/Makefile b/Makefile index c1c6d788..2c041408 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,6 @@ PROJ=dex ORG_PATH=github.com/dexidp REPO_PATH=$(ORG_PATH)/$(PROJ) export PATH := $(PWD)/bin:$(PATH) -THIS_DIRECTORY:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) VERSION ?= $(shell ./scripts/git-version) @@ -62,15 +61,6 @@ lint: bin/golangci-lint ## Run linter fix: bin/golangci-lint ## Fix lint violations bin/golangci-lint run --fix -vet: - @go vet ./... - -fmt: - @./scripts/gofmt ./... - -oldlint: bin/golint - @./bin/golint -set_exit_status $(shell go list ./...) - .PHONY: docker-image docker-image: @sudo docker build -t $(DOCKER_IMAGE) . @@ -90,14 +80,11 @@ bin/protoc: scripts/get-protoc bin/protoc-gen-go: @go install -v $(REPO_PATH)/vendor/github.com/golang/protobuf/protoc-gen-go -bin/golint: - @go install -v $(THIS_DIRECTORY)/vendor/golang.org/x/lint/golint - clean: @rm -rf bin/ -testall: testrace vet fmt oldlint +testall: testrace FORCE: -.PHONY: test testrace vet fmt oldlint testall +.PHONY: test testrace testall diff --git a/scripts/gofmt b/scripts/gofmt deleted file mode 100755 index 8851bdab..00000000 --- a/scripts/gofmt +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -e - -result=$( go fmt $@ ) -if [[ $result != "" ]]; then - >&2 echo "The following files are not formatted correctly: $result" - exit 1 -fi