Skip to content

Commit

Permalink
Optimize linting (argoproj#2479)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec authored Oct 11, 2019
1 parent d06df74 commit 213ba36
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 20 deletions.
5 changes: 0 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,6 @@ jobs:
- run:
name: Generate code
command: make codegen
- run:
name: Lint code
# use GOGC to limit memory usage in exchange for CPU usage, https://github.com/golangci/golangci-lint#memory-usage-of-golangci-lint
# we have 8GB RAM, 2CPUs https://circleci.com/docs/2.0/executor-types/#using-machine
command: LINT_GOGC=20 LINT_CONCURRENCY=1 LINT_DEADLINE=4m0s make lint
- run:
name: Check nothing has changed
command: |
Expand Down
10 changes: 8 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ run:
skip-files:
- ".*\\.pb\\.go"
skip-dirs:
- pkg/client
- vendor
- pkg/client/
- vendor/
linters:
enable:
- vet
- deadcode
- goimports
- varcheck
- structcheck
- ineffassign
- unconvert
- unparam
linters-settings:
goimports:
local-prefixes: github.com/argoproj/argo-cd
service:
golangci-lint-version: 1.18.0
18 changes: 6 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ IMAGE_TAG?=
STATIC_BUILD?=true
# build development images
DEV_IMAGE?=false
# lint is memory and CPU intensive, so we can limit on CI to mitigate OOM
LINT_GOGC?=off
LINT_CONCURRENCY?=8
# Set timeout for linter
LINT_DEADLINE?=1m0s

override LDFLAGS += \
-X ${PACKAGE}.version=${VERSION} \
Expand Down Expand Up @@ -159,15 +154,14 @@ dep:
dep-ensure:
dep ensure -no-vendor

.PHONY: lint-local
lint-local: build
# golangci-lint does not do a good job of formatting imports
goimports -local github.com/argoproj/argo-cd -w `find . ! -path './vendor/*' ! -path './pkg/client/*' ! -path '*.pb.go' ! -path '*.gw.go' -type f -name '*.go'`
GOGC=$(LINT_GOGC) golangci-lint run --fix --verbose --concurrency $(LINT_CONCURRENCY) --deadline $(LINT_DEADLINE)
.PHONY: install-lint-tools
install-lint-tools:
./hack/install.sh lint-tools

.PHONY: lint
lint: dev-tools-image
$(call run-in-dev-tool,make lint-local LINT_CONCURRENCY=$(LINT_CONCURRENCY) LINT_DEADLINE=$(LINT_DEADLINE) LINT_GOGC=$(LINT_GOGC))
lint:
golangci-lint --version
golangci-lint run --fix --verbose

.PHONY: build
build:
Expand Down
1 change: 1 addition & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Ensure dependencies are up to date first:

```shell
dep ensure
make install-lint-tools
```

Build `cli`, `image`, and `argocd-util` as default targets by running make:
Expand Down
1 change: 0 additions & 1 deletion hack/Dockerfile.dev-tools
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ RUN GO111MODULE=on go get sigs.k8s.io/controller-tools/cmd/[email protected]
GO111MODULE=on go get github.com/gogo/protobuf/[email protected] && \
GO111MODULE=on go get sigs.k8s.io/controller-tools/cmd/[email protected] && \
GO111MODULE=on go get github.com/golang/protobuf/[email protected] && \
GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/[email protected] && \
GO111MODULE=on go get github.com/grpc-ecosystem/grpc-gateway/[email protected] && \
GO111MODULE=on go get github.com/grpc-ecosystem/grpc-gateway/[email protected] && \
GO111MODULE=on go get github.com/jstemmer/[email protected] && \
Expand Down
11 changes: 11 additions & 0 deletions hack/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -eux -o pipefail

export DOWNLOADS=/tmp/dl
export BIN=${BIN:-/usr/local/bin}

mkdir -p $DOWNLOADS

for product in $*; do
"$(dirname $0)/installers/install-${product}.sh"
done
8 changes: 8 additions & 0 deletions hack/installers/install-lint-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -eux -o pipefail

mkdir -p $DOWNLOADS/lint-tools
cd $DOWNLOADS/lint-tools

# later versions seem to need go1.13
GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/[email protected]

0 comments on commit 213ba36

Please sign in to comment.