Add golangci-lint v1.62.2 (#1953)

This commit is contained in:
Denis Bilenko 2024-12-04 18:40:19 +01:00 committed by GitHub
parent 0da17f6ec6
commit 0a36681bef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 49 additions and 7 deletions

View File

@ -45,7 +45,6 @@ jobs:
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
go install gotest.tools/gotestsum@latest go install gotest.tools/gotestsum@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Pull external libraries - name: Pull external libraries
run: | run: |
@ -53,7 +52,7 @@ jobs:
pip3 install wheel pip3 install wheel
- name: Run tests - name: Run tests
run: make test run: make testonly
- name: Publish test coverage - name: Publish test coverage
uses: codecov/codecov-action@v4 uses: codecov/codecov-action@v4
@ -90,6 +89,20 @@ jobs:
# Exit with status code 1 if there are differences (i.e. unformatted files) # Exit with status code 1 if there are differences (i.e. unformatted files)
git diff --exit-code 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: validate-bundle-schema:
runs-on: ubuntu-latest runs-on: ubuntu-latest

19
.golangci.yaml Normal file
View File

@ -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/

View File

@ -3,6 +3,10 @@
"editor.insertSpaces": false, "editor.insertSpaces": false,
"editor.formatOnSave": true "editor.formatOnSave": true
}, },
"go.lintTool": "golangci-lint",
"go.lintFlags": [
"--fast"
],
"files.trimTrailingWhitespace": true, "files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true, "files.insertFinalNewline": true,
"files.trimFinalNewlines": true, "files.trimFinalNewlines": true,

View File

@ -7,10 +7,16 @@ fmt:
@gofmt -w $(shell find . -type f -name '*.go' -not -path "./vendor/*") @gofmt -w $(shell find . -type f -name '*.go' -not -path "./vendor/*")
lint: vendor lint: vendor
@echo "✓ Linting source code with https://staticcheck.io/ ..." @echo "✓ Linting source code with https://golangci-lint.run/ ..."
@staticcheck ./... @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 ..." @echo "✓ Running tests ..."
@gotestsum --format pkgname-and-test-fails --no-summary=skipped --raw-command go test -v -json -short -coverprofile=coverage.txt ./... @gotestsum --format pkgname-and-test-fails --no-summary=skipped --raw-command go test -v -json -short -coverprofile=coverage.txt ./...

View File

@ -56,7 +56,7 @@ func (m *importResource) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagn
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
tf.SetStdout(buf) 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)) changed, err := tf.Plan(ctx, tfexec.State(tmpState), tfexec.Target(importAddress))
if err != nil { if err != nil {
return diag.Errorf("terraform plan: %v", err) return diag.Errorf("terraform plan: %v", err)

View File

@ -250,7 +250,7 @@ func (t *cobraTestRunner) RunBackground() {
// Reset context on command for the next test. // 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. // 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 // 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) cli.SetContext(nil)
// Make caller aware of error. // Make caller aware of error.