From 1c99bcf82f3f231a9d0335f6e943c5db06858dd8 Mon Sep 17 00:00:00 2001 From: Joel Speed Date: Mon, 2 Dec 2024 14:52:26 +0000 Subject: [PATCH] Add vscode integration for golangci-kal --- .golangci.yaml | 5 +++++ .vscode/settings.json | 6 ++++++ Makefile | 9 ++++++++- hack/golangci-lint.sh | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json create mode 100755 hack/golangci-lint.sh diff --git a/.golangci.yaml b/.golangci.yaml index 02994f5b928..7f55bd1973a 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -9,3 +9,8 @@ linters: disable-all: true enable: - kal +issues: + # We have a lot of existing issues. + # Want to make sure that those adding new fields have an + # opportunity to fix them when running the linter locally. + max-issues-per-linter: 1000 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000000..78fd98cd6ef --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "go.lintTool": "golangci-lint", + "go.alternateTools": { + "golangci-lint": "${workspaceFolder}/hack/golangci-lint.sh", + } +} diff --git a/Makefile b/Makefile index 5e6a6b1312e..fb368194625 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,13 @@ update-codegen-crds: update-scripts # ##################### +# When not otherwise set, diff/lint against the local master branch +PULL_BASE_SHA ?= master + +.PHONY: lint +lint: + hack/golangci-lint.sh run --new-from-rev=${PULL_BASE_SHA} + .PHONY: verify-scripts verify-scripts: bash -x hack/verify-deepcopy.sh @@ -56,7 +63,7 @@ verify-scripts: hack/verify-promoted-features-pass-tests.sh .PHONY: verify -verify: verify-scripts verify-crd-schema verify-codegen-crds +verify: verify-scripts lint verify-crd-schema verify-codegen-crds .PHONY: verify-codegen-crds verify-codegen-crds: diff --git a/hack/golangci-lint.sh b/hack/golangci-lint.sh new file mode 100755 index 00000000000..0e9a45f2a37 --- /dev/null +++ b/hack/golangci-lint.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +source "$(dirname "${BASH_SOURCE}")/lib/init.sh" + +# Build codegen-crds when it's not present and not overriden for a specific file. +if [ -z "${GOLANGCI_LINT:-}" ];then + ${TOOLS_MAKE} golangci-kal + GOLANGCI_LINT="${TOOLS_OUTPUT}/golangci-kal" +fi + +# In CI, HOME is set to / and is not writable. +# Make sure golangci-lint can create its cache. +HOME=${HOME:-"/tmp"} +if [[ ${HOME} == "/" ]]; then + HOME="/tmp" +fi + +"${GOLANGCI_LINT}" $@