Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add golangci-lint #50

Merged
merged 3 commits into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ jobs:
with:
go-version-file: go.mod
cache: true
- id: lint
name: Lint Go Code
uses: golangci/golangci-lint-action@v3
with:
version: latest
- id: generate_docs
name: Generate Documentation
run: go generate
Expand Down
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-FileCopyrightText: The terraform-provider-git Authors
# SPDX-License-Identifier: 0BSD

run:
build-tags:
- testing
1 change: 1 addition & 0 deletions dev/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ FROM metio/devcontainers-go:latest

RUN go install github.com/hashicorp/terraform@main
RUN go install gotest.tools/gotestsum@latest
RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@master
7 changes: 7 additions & 0 deletions internal/provider/data_source_git_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ func (r *dataSourceGitLog) Read(ctx context.Context, req datasource.ReadRequest,
}
return nil
})
if err != nil {
resp.Diagnostics.AddError(
"Cannot read commits",
"Could not read commits because of: "+err.Error(),
)
return
}
if !inputs.Skip.IsNull() && !inputs.Skip.IsUnknown() {
if int64(len(hashes)) >= inputs.Skip.Value {
hashes = hashes[inputs.Skip.Value:]
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/resource_git_commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ func TestResourceGitCommit_Directory_Missing(t *testing.T) {
ProtoV6ProviderFactories: testutils.ProviderFactories(),
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
Config: `
resource "git_commit" "test" {
message = "committed with terraform"
}
`),
`,
ExpectError: regexp.MustCompile(`Missing required argument`),
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_git_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestResourceGitInit_Import(t *testing.T) {
{
ResourceName: "git_init.test",
ImportState: true,
ImportStateId: fmt.Sprintf("%s", directory),
ImportStateId: directory,
ImportStateVerify: true,
},
},
Expand Down
8 changes: 8 additions & 0 deletions project.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ out/go-format-sentinel: $(shell find . -type f -name '*.go')
gofmt -s -w -e .
touch $@

out/go-lint-sentinel: $(shell find . -type f -name '*.go')
mkdir --parents $(@D)
golangci-lint run
touch $@

out/tf-format-sentinel: $(shell find ./examples -type f -name '*.tf') $(shell find ./terratest -type f -name '*.tf')
mkdir --parents $(@D)
terraform fmt -recursive ./terratest
Expand Down Expand Up @@ -73,6 +78,9 @@ test: ## run specific unit tests
.PHONY: format
format: out/go-format-sentinel out/tf-format-sentinel ## format Go code and Terraform config

.PHONY: lint
lint: out/go-lint-sentinel ## lint all Go code

.PHONY: update
update: ## update all dependencies
go get -u
Expand Down