Created
June 26, 2025 12:57
-
-
Save maciej/666679a34f755943ffa43d5c3c2854d6 to your computer and use it in GitHub Desktop.
golangci-lint setup script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
# Step 1: Extract the last element of the module name from go.mod | |
if [[ ! -f "go.mod" ]]; then | |
echo "Error: go.mod not found in current directory." >&2 | |
exit 1 | |
fi | |
module_name=$(awk '/^module / {print $2}' go.mod) | |
if [[ -z "$module_name" ]]; then | |
echo "Error: Unable to extract module name." >&2 | |
exit 1 | |
fi | |
# Step 2: Create tools directory if missing | |
mkdir -p tools | |
# Step 3: Create tools/golangci-lint.mod if it doesn't exist | |
modfile="tools/golangci-lint.mod" | |
if [[ ! -f "$modfile" ]]; then | |
go mod init -modfile=tools/golangci-lint.mod "${module_name}/tools/golangci-lint" | |
fi | |
# Step 4: Add golangci-lint | |
go get -tool -modfile="$modfile" github.com/golangci/golangci-lint/v2/cmd/[email protected] | |
# Step 5: Tidy the tools module | |
go mod tidy -modfile="$modfile" | |
echo "golangci-lint tool module setup complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assuming you use
~/.local/bin
; install by: