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"
```
This commit is contained in:
Denis Bilenko 2024-12-30 16:18:57 +01:00 committed by GitHub
parent a002475a6a
commit e088d0d996
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -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/ ..."

9
lint.sh Executable file
View File

@ -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 $@