From 53a020787017c28175440b940eabeb13d821e2bc Mon Sep 17 00:00:00 2001 From: ashmrtn <3891298+ashmrtn@users.noreply.github.com> Date: Fri, 12 Aug 2022 08:46:15 -0700 Subject: [PATCH] Make rules to check for linter and run it (#519) Explicitly check for the linter version as different versions can return different results. Currently the desired version is hard-coded, but may be sourced from the github workflow file in the future. --- src/Makefile | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/Makefile diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 000000000..ebb59cd01 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,24 @@ +# This must match the version defined in .github/workflows/lint.yaml. +WANTED_LINT_VERSION := 1.45.2 +LINT_VERSION := $(shell golangci-lint version | cut -d' ' -f4) +HAS_LINT := $(shell which golangci-lint) + +INSTALL_LINT_PAGE := "https://golangci-lint.run/usage/install/" +BAD_LINT_MSG := "Missing golangci-lint version $(WANTED_LINT_VERSION). Visit $(INSTALL_LINT_PAGE) for instructions on how to install" + +.PHONY: check-lint check-lint-version lint + +lint: check-lint-version + golangci-lint run + +check-lint-version: check-lint + @if [ "$(LINT_VERSION)" != "$(WANTED_LINT_VERSION)" ]; then \ + echo >&2 $(BAD_LINT_MSG); \ + false; \ + fi + +check-lint: + @if [ -z "$(HAS_LINT)" ]; then \ + echo >&2 $(BAD_LINT_MSG); \ + false; \ + fi