Skip to content

Commit 414e296

Browse files
committed
[lint] add make lint-fix command to fix lint issues
Add exit 1 to fail make command when container_runtime is not present. Signed-off-by: Nadia Pinaeva <[email protected]>
1 parent f392ef0 commit 414e296

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

go-controller/Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,17 @@ clean:
9393

9494
lint:
9595
ifeq ($(CONTAINER_RUNNABLE), 0)
96-
@GOPATH=${GOPATH} ./hack/lint.sh $(CONTAINER_RUNTIME)
96+
@GOPATH=${GOPATH} ./hack/lint.sh $(CONTAINER_RUNTIME) || { echo "lint failed! Try running 'make lint-fix'"; exit 1; }
9797
else
98-
echo "linter can only be run within a container since it needs a specific golangci-lint version"
98+
echo "linter can only be run within a container since it needs a specific golangci-lint version"; exit 1
99+
endif
100+
101+
lint-fix:
102+
ifeq ($(CONTAINER_RUNNABLE), 0)
103+
@GOPATH=${GOPATH} ./hack/lint.sh $(CONTAINER_RUNTIME) fix || { echo "ERROR: lint fix failed! There is a bug that changes file ownership to root \
104+
when this happens. To fix it, simply run 'chown -R <user>:<group> *' from the repo root."; exit 1; }
105+
else
106+
echo "linter can only be run within a container since it needs a specific golangci-lint version"; exit 1
99107
endif
100108

101109
gofmt:

go-controller/hack/lint.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#!/usr/bin/env bash
2-
32
VERSION=v1.60.3
3+
extra_flags=""
44
if [ "$#" -ne 1 ]; then
5+
if [ "$#" -eq 2 ] && [ "$2" == "fix" ]; then
6+
extra_flags="--fix"
7+
else
58
echo "Expected command line argument - container runtime (docker/podman) got $# arguments: $@"
69
exit 1
10+
fi
711
fi
812

913
$1 run --security-opt label=disable --rm \
1014
-v ${HOME}/.cache/golangci-lint:/cache -e GOLANGCI_LINT_CACHE=/cache \
1115
-v $(pwd):/app -w /app -e GO111MODULE=on docker.io/golangci/golangci-lint:${VERSION} \
1216
golangci-lint run --verbose --print-resources-usage \
13-
--modules-download-mode=vendor --timeout=15m0s && \
14-
echo "lint OK!"
17+
--modules-download-mode=vendor --timeout=15m0s ${extra_flags} && \
18+
echo "lint OK!"

0 commit comments

Comments
 (0)