From 6715d9e9bf099bc6001c90b617d5713f09b2594e Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Sat, 23 Sep 2023 15:40:04 +0100 Subject: [PATCH] (Linter Enhancements): use specific version and check with github actions --- .github/workflows/lint.yml | 20 ++++++++++++++++++++ .golangci.yml | 3 +++ Makefile | 19 ++++++++++++++++--- subcommands/keys/ca_show.go | 3 +++ 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .golangci.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..d97eef2b --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,20 @@ +name: Lint +on: + push: + pull_request: + +jobs: + lint: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: '~1.21' + - name: Clone the code + uses: actions/checkout@v4 + - name: Run linter + uses: golangci/golangci-lint-action@v3 + with: + version: v1.54 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..b9ab9064 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,3 @@ +run: + deadline: 5m + allow-parallel-runners: true \ No newline at end of file diff --git a/Makefile b/Makefile index 8ba1a593..61e14429 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,6 @@ COMMIT?=$(shell git describe HEAD)$(shell git diff --quiet || echo '+dirty') # Use linker flags to provide commit info LDFLAGS=-ldflags "-X=github.com/foundriesio/fioctl/subcommands/version.Commit=$(COMMIT)" -linter:=$(shell which golangci-lint 2>/dev/null || echo $(HOME)/go/bin/golangci-lint) - build: fioctl-linux-amd64 fioctl-linux-arm64 fioctl-windows-amd64 fioctl-darwin-amd64 fioctl-darwin-arm64 @true @@ -24,12 +22,27 @@ fioctl-%: go build $(LDFLAGS) -o bin/$@ main.go @if [ "$@" = "fioctl-windows-amd64" ]; then mv bin/$@ bin/$@.exe; fi +GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint +golangci-lint: + @[ -f $(GOLANGCI_LINT) ] || { \ + set -e ;\ + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) v1.54.2 ;\ + } + +.PHONY: lint +lint: golangci-lint ## Run linter + $(GOLANGCI_LINT) run --timeout=5m + +.PHONY: lint-fix +lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes + $(GOLANGCI_LINT) run --fix + format: @gofmt -l -w ./ check: @test -z $(shell gofmt -l ./ | tee /dev/stderr) || echo "[WARN] Fix formatting issues with 'make format'" @test -x $(linter) || (echo "Please install linter from https://github.com/golangci/golangci-lint/releases/tag/v1.51.2 to $(HOME)/go/bin") - $(linter) run + make lint # Use the image for Dockerfile.build to build and install the tool. container-init: diff --git a/subcommands/keys/ca_show.go b/subcommands/keys/ca_show.go index 9b1ba47f..6eaeb3ae 100644 --- a/subcommands/keys/ca_show.go +++ b/subcommands/keys/ca_show.go @@ -169,6 +169,9 @@ func prettyPrint(cert string) { case *ecdsa.PublicKey: fmt.Println("\t\tNIST CURVE:", pub.Curve.Params().Name) fmt.Print("\t\t\t") + + //FIXME: Fix deprecation and remove the nolint + //nolint: staticcheck: SA1019: elliptic.Marshal has been deprecated since Go 1.21: for ECDH, use the crypto/ecdh package. This function returns an encoding equivalent to that of PublicKey.Bytes in crypto/ecdh. (staticcheck) for idx, b := range elliptic.Marshal(pub.Curve, pub.X, pub.Y) { fmt.Printf("%02x:", b) if (idx+1)%15 == 0 {