diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 8aea95494..ebb3e75d4 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -45,7 +45,6 @@ jobs: echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV echo "$(go env GOPATH)/bin" >> $GITHUB_PATH go install gotest.tools/gotestsum@latest - go install honnef.co/go/tools/cmd/staticcheck@latest - name: Pull external libraries run: | @@ -53,7 +52,7 @@ jobs: pip3 install wheel - name: Run tests - run: make test + run: make testonly - name: Publish test coverage uses: codecov/codecov-action@v4 @@ -90,6 +89,20 @@ jobs: # Exit with status code 1 if there are differences (i.e. unformatted files) git diff --exit-code + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: 1.23.2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.62.2 + args: --timeout=15m + validate-bundle-schema: runs-on: ubuntu-latest diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 000000000..ef2596206 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,19 @@ +linters: + disable-all: true + enable: + # errcheck and govet are part of default setup and should be included but give too many errors now + # once errors are fixed, they should be enabled here: + #- errcheck + - gosimple + #- govet + - ineffassign + - staticcheck + - unused + - gofmt +linters-settings: + gofmt: + rewrite-rules: + - pattern: 'a[b:len(a)]' + replacement: 'a[b:]' +issues: + exclude-dirs-use-default: false # recommended by docs https://golangci-lint.run/usage/false-positives/ diff --git a/.vscode/settings.json b/.vscode/settings.json index 9697e221d..853e84de8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,10 @@ "editor.insertSpaces": false, "editor.formatOnSave": true }, + "go.lintTool": "golangci-lint", + "go.lintFlags": [ + "--fast" + ], "files.trimTrailingWhitespace": true, "files.insertFinalNewline": true, "files.trimFinalNewlines": true, diff --git a/Makefile b/Makefile index 243a91191..13787fdda 100644 --- a/Makefile +++ b/Makefile @@ -7,10 +7,16 @@ fmt: @gofmt -w $(shell find . -type f -name '*.go' -not -path "./vendor/*") lint: vendor - @echo "✓ Linting source code with https://staticcheck.io/ ..." - @staticcheck ./... + @echo "✓ Linting source code with https://golangci-lint.run/ ..." + @golangci-lint run ./... -test: lint +lintfix: vendor + @echo "✓ Linting source code with 'golangci-lint run --fix' ..." + @golangci-lint run --fix ./... + +test: lint testonly + +testonly: @echo "✓ Running tests ..." @gotestsum --format pkgname-and-test-fails --no-summary=skipped --raw-command go test -v -json -short -coverprofile=coverage.txt ./... diff --git a/bundle/deploy/terraform/import.go b/bundle/deploy/terraform/import.go index dfe60a581..0a1d1b9ce 100644 --- a/bundle/deploy/terraform/import.go +++ b/bundle/deploy/terraform/import.go @@ -56,7 +56,7 @@ func (m *importResource) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagn buf := bytes.NewBuffer(nil) tf.SetStdout(buf) - //lint:ignore SA1019 We use legacy -state flag for now to plan the import changes based on temporary state file + //nolint:staticcheck // SA1019 We use legacy -state flag for now to plan the import changes based on temporary state file changed, err := tf.Plan(ctx, tfexec.State(tmpState), tfexec.Target(importAddress)) if err != nil { return diag.Errorf("terraform plan: %v", err) diff --git a/internal/helpers.go b/internal/helpers.go index 3e4b4e97c..7cd2b578b 100644 --- a/internal/helpers.go +++ b/internal/helpers.go @@ -250,7 +250,7 @@ func (t *cobraTestRunner) RunBackground() { // Reset context on command for the next test. // These commands are globals so we have to clean up to the best of our ability after each run. // See https://github.com/spf13/cobra/blob/a6f198b635c4b18fff81930c40d464904e55b161/command.go#L1062-L1066 - //lint:ignore SA1012 cobra sets the context and doesn't clear it + //nolint:staticcheck // cobra sets the context and doesn't clear it cli.SetContext(nil) // Make caller aware of error.