diff --git a/.golangci.yml b/.golangci.yml index 400abe6ea..afbcf0018 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,6 +11,7 @@ linters: - exportloopref #https://github.com/kyoh86/exportloopref - bodyclose #https://github.com/timakin/bodyclose - goconst #https://github.com/jgautheron/goconst + - gofmt - errcheck #https://github.com/kisielk/errcheck - stylecheck #https://github.com/dominikh/go-tools/tree/master/stylecheck - revive #golint is deprecated and golangci-lint recommends to use revive instead https://github.com/mgechev/revive diff --git a/Makefile b/Makefile index d06781ee7..c5dd89765 100644 --- a/Makefile +++ b/Makefile @@ -6,13 +6,11 @@ generate: check-resource go mod tidy; \ go run . $(RESOURCE) ; -fmt: - vet: go vet fmt: - go fmt ./... + gofmt -s -l -w . lint: golangci-lint run . diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index ddaaacd6a..1141e92f8 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -18,10 +18,11 @@ There are instances where several new resources being added (i.e Workspace Run T ## Linting -Linting is not necessarily required for a change to be merged, but it helps smooth the review process and catch common mistakes early. If you'd like to run the linters manually, follow these steps: +After opening a PR, our CI system will perform a series of code checks, one of which is linting. Linting is not strictly required for a change to be merged, but it helps smooth the review process and catch common mistakes early. If you'd like to run the linters manually, follow these steps: 1. Ensure you have [installed golangci-lint](https://golangci-lint.run/usage/install/#local-installation) -2. From the CLI, run `make lint` +2. Format your code by running `make fmt` +3. Run lint checks using `make lint` ## Writing Tests diff --git a/tfe_test.go b/tfe_test.go index 1fe614cf8..d39eaaeb4 100644 --- a/tfe_test.go +++ b/tfe_test.go @@ -119,14 +119,14 @@ func Test_unmarshalResponse(t *testing.T) { func Test_EncodeQueryParams(t *testing.T) { t.Run("with no listOptions and therefore no include field defined", func(t *testing.T) { urlVals := map[string][]string{ - "include": []string{}, + "include": {}, } requestURLquery := encodeQueryParams(urlVals) assert.Equal(t, requestURLquery, "") }) t.Run("with listOptions setting multiple include options", func(t *testing.T) { urlVals := map[string][]string{ - "include": []string{"workspace", "cost_estimate"}, + "include": {"workspace", "cost_estimate"}, } requestURLquery := encodeQueryParams(urlVals) assert.Equal(t, requestURLquery, "include=workspace%2Ccost_estimate")