| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
.PHONY: lint |
| 5 |
lint: _lint |
| 6 |
|
| 7 |
LINT_ARCH := $(shell uname -m) |
| 8 |
LINT_OS := $(shell uname) |
| 9 |
LINT_OS_LOWER := $(shell echo $(LINT_OS) | tr '[:upper:]' '[:lower:]') |
| 10 |
LINT_ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) |
| 11 |
|
| 12 |
|
| 13 |
ifeq ($(LINT_OS),Darwin) |
| 14 |
ifeq ($(LINT_ARCH),arm64) |
| 15 |
LINT_ARCH=x86_64 |
| 16 |
endif |
| 17 |
endif |
| 18 |
|
| 19 |
LINTERS := |
| 20 |
FIXERS := |
| 21 |
|
| 22 |
SHELLCHECK_VERSION ?= v0.8.0 |
| 23 |
SHELLCHECK_BIN := out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH) |
| 24 |
$(SHELLCHECK_BIN): |
| 25 |
mkdir -p out/linters |
| 26 |
rm -rf out/linters/shellcheck-* |
| 27 |
curl -sSfL https://github.com/koalaman/shellcheck/releases/download/$(SHELLCHECK_VERSION)/shellcheck-$(SHELLCHECK_VERSION).$(LINT_OS_LOWER).$(LINT_ARCH).tar.xz | tar -C out/linters -xJf - |
| 28 |
mv out/linters/shellcheck-$(SHELLCHECK_VERSION)/shellcheck $@ |
| 29 |
rm -rf out/linters/shellcheck-$(SHELLCHECK_VERSION)/shellcheck |
| 30 |
|
| 31 |
LINTERS += shellcheck-lint |
| 32 |
shellcheck-lint: $(SHELLCHECK_BIN) |
| 33 |
$(SHELLCHECK_BIN) $(shell find . -name "*.sh") |
| 34 |
|
| 35 |
FIXERS += shellcheck-fix |
| 36 |
shellcheck-fix: $(SHELLCHECK_BIN) |
| 37 |
$(SHELLCHECK_BIN) $(shell find . -name "*.sh") -f diff | { read -t 1 line || exit 0; { echo "$$line" && cat; } | git apply -p2; } |
| 38 |
|
| 39 |
GOLANGCI_LINT_CONFIG := $(LINT_ROOT)/.golangci.yml |
| 40 |
GOLANGCI_LINT_VERSION ?= v1.43.0 |
| 41 |
GOLANGCI_LINT_BIN := out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH) |
| 42 |
$(GOLANGCI_LINT_BIN): |
| 43 |
mkdir -p out/linters |
| 44 |
rm -rf out/linters/golangci-lint-* |
| 45 |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b out/linters $(GOLANGCI_LINT_VERSION) |
| 46 |
mv out/linters/golangci-lint $@ |
| 47 |
|
| 48 |
LINTERS += golangci-lint-lint |
| 49 |
golangci-lint-lint: $(GOLANGCI_LINT_BIN) |
| 50 |
find . -name go.mod -execdir "$(GOLANGCI_LINT_BIN)" run -c "$(GOLINT_CONFIG)" \; |
| 51 |
|
| 52 |
FIXERS += golangci-lint-fix |
| 53 |
golangci-lint-fix: $(GOLANGCI_LINT_BIN) |
| 54 |
find . -name go.mod -execdir "$(GOLANGCI_LINT_BIN)" run -c "$(GOLINT_CONFIG)" --fix \; |
| 55 |
|
| 56 |
YAMLLINT_VERSION ?= 1.26.3 |
| 57 |
YAMLLINT_ROOT := out/linters/yamllint-$(YAMLLINT_VERSION) |
| 58 |
YAMLLINT_BIN := $(YAMLLINT_ROOT)/dist/bin/yamllint |
| 59 |
$(YAMLLINT_BIN): |
| 60 |
mkdir -p out/linters |
| 61 |
rm -rf out/linters/yamllint-* |
| 62 |
curl -sSfL https://github.com/adrienverge/yamllint/archive/refs/tags/v$(YAMLLINT_VERSION).tar.gz | tar -C out/linters -zxf - |
| 63 |
cd $(YAMLLINT_ROOT) && pip3 install --target dist . |
| 64 |
|
| 65 |
LINTERS += yamllint-lint |
| 66 |
yamllint-lint: $(YAMLLINT_BIN) |
| 67 |
PYTHONPATH=$(YAMLLINT_ROOT)/dist $(YAMLLINT_ROOT)/dist/bin/yamllint . |
| 68 |
|
| 69 |
.PHONY: _lint $(LINTERS) |
| 70 |
_lint: $(LINTERS) |
| 71 |
|
| 72 |
.PHONY: fix $(FIXERS) |
| 73 |
fix: $(FIXERS) |
| 74 |
|
| 75 |
|