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

[Chore] Add go fmt check to linter #606

Merged
merged 2 commits into from Dec 8, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions Makefile
Expand Up @@ -6,13 +6,11 @@ generate: check-resource
go mod tidy; \
go run . $(RESOURCE) ;

fmt:

vet:
go vet

fmt:
go fmt ./...
gofmt -s -l -w .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context:
-s tells gofmt to simplify your code
-l tells gofmt to list the files that changed due to formatting
-w tells gofmt to write the formatting changes to the source file

Run gofmt -help for more info!


lint:
golangci-lint run .
Expand Down
5 changes: 3 additions & 2 deletions docs/CONTRIBUTING.md
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions tfe_test.go
Expand Up @@ -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")
Expand Down