Skip to content

Commit

Permalink
Add golangci-lint v1.62.2 (#1953)
Browse files Browse the repository at this point in the history
  • Loading branch information
denik authored Dec 4, 2024
1 parent 0da17f6 commit 0a36681
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 7 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ 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: |
make vendor
pip3 install wheel
- name: Run tests
run: make test
run: make testonly

- name: Publish test coverage
uses: codecov/codecov-action@v4
Expand Down Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -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/
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...

Expand Down
2 changes: 1 addition & 1 deletion bundle/deploy/terraform/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0a36681

Please sign in to comment.