From bec064d0b714e4a1a8d45db45908628fc56d52b1 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 11 Nov 2025 22:32:21 +0200 Subject: [PATCH] fix: refactor Makefile to fix checkmake maxbodylength violations (#95) --- Makefile | 88 +++------------------------------------- scripts/deps-check.sh | 9 ++++ scripts/deps-update.sh | 12 ++++++ scripts/install-tools.sh | 30 ++++++++++++++ scripts/lint-fix.sh | 25 ++++++++++++ scripts/lint-verbose.sh | 11 +++++ scripts/test-coverage.sh | 11 +++++ 7 files changed, 104 insertions(+), 82 deletions(-) create mode 100755 scripts/deps-check.sh create mode 100755 scripts/deps-update.sh create mode 100755 scripts/install-tools.sh create mode 100755 scripts/lint-fix.sh create mode 100755 scripts/lint-verbose.sh create mode 100755 scripts/test-coverage.sh diff --git a/Makefile b/Makefile index e9f2873..7dac462 100644 --- a/Makefile +++ b/Makefile @@ -16,34 +16,7 @@ help: # Install required tools install-tools: - @echo "Installing golangci-lint..." - @go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest - @echo "Installing gofumpt..." - @go install mvdan.cc/gofumpt@latest - @echo "Installing golines..." - @go install github.com/segmentio/golines@latest - @echo "Installing goimports..." - @go install golang.org/x/tools/cmd/goimports@latest - @echo "Installing staticcheck..." - @go install honnef.co/go/tools/cmd/staticcheck@latest - @echo "Installing gosec..." - @go install github.com/securego/gosec/v2/cmd/gosec@latest - @echo "Installing gocyclo..." - @go install github.com/fzipp/gocyclo/cmd/gocyclo@latest - @echo "Installing revive..." - @go install github.com/mgechev/revive@latest - @echo "Installing checkmake..." - @go install github.com/checkmake/checkmake/cmd/checkmake@latest - @echo "Installing shellcheck..." - @go install github.com/koalaman/shellcheck/cmd/shellcheck@latest - @echo "Installing shfmt..." - @go install mvdan.cc/sh/v3/cmd/shfmt@latest - @echo "Installing yamllint (Go-based)..." - @go install github.com/excilsploft/yamllint@latest - @echo "Installing editorconfig-checker..." - @go install github.com/editorconfig-checker/editorconfig-checker/\ - cmd/editorconfig-checker@latest - @echo "All tools installed successfully!" + @./scripts/install-tools.sh # Run linters lint: @@ -51,40 +24,11 @@ lint: # Run linters with auto-fix lint-fix: - @echo "Running gofumpt..." - @gofumpt -l -w . - @echo "Running golines..." - @golines -w -m 120 --base-formatter="gofumpt" --shorten-comments . - @echo "Running goimports..." - @goimports -w -local github.com/ivuorinen/gibidify . - @echo "Running go fmt..." - @go fmt ./... - @echo "Running go mod tidy..." - @go mod tidy - @echo "Running shfmt formatting..." - @shfmt -w -i 0 -ci . - @echo "Running golangci-lint with --fix..." - @golangci-lint run --fix ./... - @echo "Auto-fix completed. Running final lint check..." - @golangci-lint run ./... - @echo "Running revive..." - @revive -config revive.toml -formatter friendly ./... - @echo "Running checkmake..." - @checkmake --config=.checkmake Makefile - @echo "Running yamllint..." - @yamllint . + @./scripts/lint-fix.sh # Run linters with verbose output lint-verbose: - @echo "Running golangci-lint (verbose)..." - @golangci-lint run -v ./... - @echo "Running checkmake (verbose)..." - @checkmake --config=.checkmake \ - --format="{{.Line}}:{{.Rule}}:{{.Violation}}" Makefile - @echo "Running shfmt check (verbose)..." - @shfmt -d . - @echo "Running yamllint (verbose)..." - @yamllint . + @./scripts/lint-verbose.sh # Run tests test: @@ -93,14 +37,7 @@ test: # Run tests with coverage output test-coverage: - @echo "Running tests with coverage..." - @go test -race -v -coverprofile=coverage.out -covermode=atomic ./... - @echo "" - @echo "Coverage summary:" - @go tool cover -func=coverage.out | grep total: - @echo "" - @echo "Full coverage report saved to: coverage.out" - @echo "To view HTML report, run: make coverage" + @./scripts/test-coverage.sh # Run tests with coverage coverage: @@ -173,23 +110,10 @@ vuln-check: # Dependency management targets deps-check: - @echo "Checking for available dependency updates..." - @echo "" - @echo "Direct dependencies:" - @go list -u -m all | grep -v "indirect" | column -t - @echo "" - @echo "Note: Run 'make deps-update' to update all dependencies" + @./scripts/deps-check.sh deps-update: - @echo "Updating all dependencies to latest versions..." - @go get -u ./... - @go mod tidy - @echo "" - @echo "Dependencies updated successfully!" - @echo "Running tests to verify compatibility..." - @go test ./... - @echo "" - @echo "Update complete. Run 'make lint-fix && make test' to verify." + @./scripts/deps-update.sh deps-tidy: @echo "Cleaning up dependencies..." diff --git a/scripts/deps-check.sh b/scripts/deps-check.sh new file mode 100755 index 0000000..314fb30 --- /dev/null +++ b/scripts/deps-check.sh @@ -0,0 +1,9 @@ +#!/bin/sh +set -eu + +echo "Checking for available dependency updates..." +echo "" +echo "Direct dependencies:" +go list -u -m all | grep -v "indirect" | column -t +echo "" +echo "Note: Run 'make deps-update' to update all dependencies" diff --git a/scripts/deps-update.sh b/scripts/deps-update.sh new file mode 100755 index 0000000..de0c833 --- /dev/null +++ b/scripts/deps-update.sh @@ -0,0 +1,12 @@ +#!/bin/sh +set -eu + +echo "Updating all dependencies to latest versions..." +go get -u ./... +go mod tidy +echo "" +echo "Dependencies updated successfully!" +echo "Running tests to verify compatibility..." +go test ./... +echo "" +echo "Update complete. Run 'make lint-fix && make test' to verify." diff --git a/scripts/install-tools.sh b/scripts/install-tools.sh new file mode 100755 index 0000000..c8e409c --- /dev/null +++ b/scripts/install-tools.sh @@ -0,0 +1,30 @@ +#!/bin/sh +set -eu + +echo "Installing golangci-lint..." +go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest +echo "Installing gofumpt..." +go install mvdan.cc/gofumpt@latest +echo "Installing golines..." +go install github.com/segmentio/golines@latest +echo "Installing goimports..." +go install golang.org/x/tools/cmd/goimports@latest +echo "Installing staticcheck..." +go install honnef.co/go/tools/cmd/staticcheck@latest +echo "Installing gosec..." +go install github.com/securego/gosec/v2/cmd/gosec@latest +echo "Installing gocyclo..." +go install github.com/fzipp/gocyclo/cmd/gocyclo@latest +echo "Installing revive..." +go install github.com/mgechev/revive@latest +echo "Installing checkmake..." +go install github.com/checkmake/checkmake/cmd/checkmake@latest +echo "Installing shellcheck..." +go install github.com/koalaman/shellcheck/cmd/shellcheck@latest +echo "Installing shfmt..." +go install mvdan.cc/sh/v3/cmd/shfmt@latest +echo "Installing yamllint (Go-based)..." +go install github.com/excilsploft/yamllint@latest +echo "Installing editorconfig-checker..." +go install github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@latest +echo "All tools installed successfully!" diff --git a/scripts/lint-fix.sh b/scripts/lint-fix.sh new file mode 100755 index 0000000..668b1f0 --- /dev/null +++ b/scripts/lint-fix.sh @@ -0,0 +1,25 @@ +#!/bin/sh +set -eu + +echo "Running gofumpt..." +gofumpt -l -w . +echo "Running golines..." +golines -w -m 120 --base-formatter="gofumpt" --shorten-comments . +echo "Running goimports..." +goimports -w -local github.com/ivuorinen/gibidify . +echo "Running go fmt..." +go fmt ./... +echo "Running go mod tidy..." +go mod tidy +echo "Running shfmt formatting..." +shfmt -w -i 0 -ci . +echo "Running golangci-lint with --fix..." +golangci-lint run --fix ./... +echo "Auto-fix completed. Running final lint check..." +golangci-lint run ./... +echo "Running revive..." +revive -config revive.toml -formatter friendly ./... +echo "Running checkmake..." +checkmake --config=.checkmake Makefile +echo "Running yamllint..." +yamllint . diff --git a/scripts/lint-verbose.sh b/scripts/lint-verbose.sh new file mode 100755 index 0000000..a17dd14 --- /dev/null +++ b/scripts/lint-verbose.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -eu + +echo "Running golangci-lint (verbose)..." +golangci-lint run -v ./... +echo "Running checkmake (verbose)..." +checkmake --config=.checkmake --format="{{.Line}}:{{.Rule}}:{{.Violation}}" Makefile +echo "Running shfmt check (verbose)..." +shfmt -d . +echo "Running yamllint (verbose)..." +yamllint . diff --git a/scripts/test-coverage.sh b/scripts/test-coverage.sh new file mode 100755 index 0000000..a906799 --- /dev/null +++ b/scripts/test-coverage.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -eu + +echo "Running tests with coverage..." +go test -race -v -coverprofile=coverage.out -covermode=atomic ./... +echo "" +echo "Coverage summary:" +go tool cover -func=coverage.out | grep total: +echo "" +echo "Full coverage report saved to: coverage.out" +echo "To view HTML report, run: make coverage"