From e088d0d996979ddd56dd9ce10d3d1becbdc771f6 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 30 Dec 2024 16:18:57 +0100 Subject: [PATCH] Add lint.sh to run golanci-lint in 2 stages (#2051) First stage is to run goimports and formatter, second is full suite. This ensures that imports and formatting are fixed even in presence of other issues. Otherwise golanci-lint refuses to fix anything https://github.com/golangci/golangci-lint/issues/5257 This helpful when running aider with config like this - aider will use that to autofix what it can after every update: ``` % cat .aider.conf.yml lint-cmd: - "go: ./lint.sh" ``` --- Makefile | 2 +- lint.sh | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100755 lint.sh diff --git a/Makefile b/Makefile index f8e7834a5..7dca3b2cf 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ default: build lint: vendor @echo "✓ Linting source code with https://golangci-lint.run/ (with --fix)..." - @golangci-lint run --fix ./... + @./lint.sh ./... lintcheck: vendor @echo "✓ Linting source code with https://golangci-lint.run/ ..." diff --git a/lint.sh b/lint.sh new file mode 100755 index 000000000..c93d04c66 --- /dev/null +++ b/lint.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -euo pipefail +# With golangci-lint, if there are any compliation issues, then formatters' autofix won't be applied. +# https://github.com/golangci/golangci-lint/issues/5257 +# However, running goimports first alone will actually fix some of the compilation issues. +# Fixing formatting is also reasonable thing to do. +# For this reason, this script runs golangci-lint in two stages: +golangci-lint run --fix --no-config --disable-all --enable gofumpt,goimports $@ +exec golangci-lint run --fix $@