diff --git a/.golangci.yml b/.golangci.yml index 72d46eeca..e1b60f6f3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -107,8 +107,7 @@ linters: - dupl - durationcheck - errcheck - # errname is only available in golangci-lint v1.42.0+ - wait until v1.43 is available to settle - #- errname + - errname - errorlint - exhaustive - exportloopref @@ -137,7 +136,7 @@ linters: - nolintlint - predeclared # disabling for the initial iteration of the linting tool - #- promlinter + # - promlinter - revive - rowserrcheck - sqlclosecheck diff --git a/.yamllint b/.yamllint new file mode 100644 index 000000000..9a08ad176 --- /dev/null +++ b/.yamllint @@ -0,0 +1,16 @@ +--- +extends: default + +rules: + braces: + max-spaces-inside: 1 + brackets: + max-spaces-inside: 1 + comments: disable + comments-indentation: disable + document-start: disable + line-length: + level: warning + max: 160 + allow-non-breakable-inline-mappings: true + truthy: disable diff --git a/lint.mk b/lint.mk index b7a7ad112..6f66b9bdf 100644 --- a/lint.mk +++ b/lint.mk @@ -2,9 +2,10 @@ # BEGIN: lint-install --dockerfile=warn -makefile=lint.mk . # http://github.com/tinkerbell/lint-install -GOLINT_VERSION ?= v1.42.0 +GOLINT_VERSION ?= v1.42.1 HADOLINT_VERSION ?= v2.7.0 SHELLCHECK_VERSION ?= v0.7.2 +YAMLLINT_VERSION ?= 1.26.3 LINT_OS := $(shell uname) LINT_ARCH := $(shell uname -m) LINT_ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) @@ -16,31 +17,43 @@ ifeq ($(LINT_OS),Darwin) endif endif -LINT_LOWER_OS = $(shell echo $(LINT_OS) | tr '[:upper:]' '[:lower:]') -GOLINT_CONFIG:=$(LINT_ROOT)/.golangci.yml +LINT_LOWER_OS = $(shell echo $(LINT_OS) | tr '[:upper:]' '[:lower:]') +GOLINT_CONFIG = $(LINT_ROOT)/.golangci.yml +YAMLLINT_ROOT = out/linters/yamllint-$(YAMLLINT_VERSION) -lint: out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)/shellcheck out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH) out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH) +.PHONY: lint +lint: out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)/shellcheck out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH) out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH) $(YAMLLINT_ROOT)/dist/bin/yamllint out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH) run out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH) --no-fail $(shell find . -name "*Dockerfile") out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)/shellcheck $(shell find . -name "*.sh") + PYTHONPATH=$(YAMLLINT_ROOT)/dist $(YAMLLINT_ROOT)/dist/bin/yamllint . +.PHONY: fix fix: out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)/shellcheck out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH) out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH) run --fix out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)/shellcheck $(shell find . -name "*.sh") -f diff | git apply -p2 - out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)/shellcheck: mkdir -p out/linters + rm -rf out/linters/shellcheck-* curl -sSfL https://github.com/koalaman/shellcheck/releases/download/$(SHELLCHECK_VERSION)/shellcheck-$(SHELLCHECK_VERSION).$(LINT_LOWER_OS).$(LINT_ARCH).tar.xz | tar -C out/linters -xJf - mv out/linters/shellcheck-$(SHELLCHECK_VERSION) out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH) out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH): mkdir -p out/linters + rm -rf out/linters/hadolint-* curl -sfL https://github.com/hadolint/hadolint/releases/download/v2.6.1/hadolint-$(LINT_OS)-$(LINT_ARCH) > out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH) chmod u+x out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH) out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH): mkdir -p out/linters + rm -rf out/linters/golangci-lint-* curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b out/linters $(GOLINT_VERSION) mv out/linters/golangci-lint out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH) +$(YAMLLINT_ROOT)/dist/bin/yamllint: + mkdir -p out/linters + rm -rf out/linters/yamllint-* + curl -sSfL https://github.com/adrienverge/yamllint/archive/refs/tags/v$(YAMLLINT_VERSION).tar.gz | tar -C out/linters -zxf - + cd $(YAMLLINT_ROOT) && pip3 install . -t dist # END: lint-install --dockerfile=warn -makefile=lint.mk .