Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make lint.sh to run golangci-lint only once in the best case #2062

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions lint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#!/bin/bash
set -euo pipefail
set -uo 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 --enable-only="gofmt,gofumpt,goimports" --fix $@
exec golangci-lint run --fix $@

golangci-lint run --fix "$@"
lint_exit_code=$?

if [ $lint_exit_code -ne 0 ]; then
# These linters work in presence of compilation issues when run alone, so let's get these fixes at least.
golangci-lint run --enable-only="gofmt,gofumpt,goimports" --fix "$@"
fi

exit $lint_exit_code
Loading