Skip to content

Commit

Permalink
ci: Configure golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmechlark committed Sep 16, 2023
1 parent d8867ff commit dd97894
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 62 deletions.
1 change: 0 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,5 @@
]
}
},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "vscode"
}
16 changes: 15 additions & 1 deletion .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ jobs:
labels: ['wip']
})
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ^1.17
cache: false

- name: Run Lint
uses: golangci/golangci-lint-action@v3

codespell:
runs-on: ubuntu-latest
steps:
Expand All @@ -67,7 +81,7 @@ jobs:

unit_test:
runs-on: ${{ matrix.os }}
needs: [setup_pr, codespell]
needs: [setup_pr, lint, codespell]
strategy:
fail-fast: false
matrix:
Expand Down
16 changes: 15 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ^1.17
cache: false

- name: Run Lint
uses: golangci/golangci-lint-action@v3

codespell:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -104,7 +118,7 @@ jobs:
permissions:
contents: write
pull-requests: write
needs: [codespell, integration_test]
needs: [lint, codespell, integration_test]
outputs:
release_created: ${{ steps.release.outputs.release_created }}
steps:
Expand Down
43 changes: 43 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
run:
timeout: 60m

issues:
max-per-linter: 0
max-same-issues: 0

linters:
disable-all: true
enable:
- asciicheck
- bidichk
- errcheck
- gocritic
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- nakedret
- misspell
#- nolintlint
#- nlreturn
- reassign
- staticcheck
- typecheck
- unused
- unconvert
- unparam
- vet
- vetshadow
# - wastedassign # disabled because of generics
# - whitespace # Disabled for performance reasons - Ignores cache and takes 12+ minutes to run on the repo for _any_ change

linters-settings:
errcheck:
ignore: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema:ForceNew|Set,fmt:.*,io:Close
misspell:
ignore-words:
- hdinsight
- exportfs
nakedret:
max-func-lines: 40
30 changes: 0 additions & 30 deletions .golintci.yml

This file was deleted.

16 changes: 14 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
TEST?=$$(go list ./...)
TEST?=$$(go list ./... |grep -v 'vendor'|grep -v 'examples')
GOFMT_FILES?=$$(find . -name '*.go')
WEBSITE_REPO=github.com/hashicorp/terraform-website
PKG_NAME=cloud66
VERSION=$(shell git describe --tags --always)

default: build

tools:
@echo "==> installing required tooling..."
@sh "$(CURDIR)/scripts/gogetcookie.sh"
go install github.com/client9/misspell/cmd/misspell@latest
go install github.com/bflad/tfproviderlint/cmd/tfproviderlint@latest
go install github.com/bflad/tfproviderdocs@latest
go install github.com/katbyte/terrafmt@latest
go install golang.org/x/tools/cmd/goimports@latest
go install mvdan.cc/gofumpt@latest
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH || $$GOPATH)/bin v1.51.1

build: vet fmt
go install

Expand All @@ -16,7 +27,8 @@ test: fmt
testacc: fmt
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m -covermode atomic -coverprofile=covprofile

lint: tools terraform-provider-lint golangci-lint
lint:
golangci-lint run ./...

vet:
@echo "==> Running go vet ."
Expand Down
2 changes: 1 addition & 1 deletion cloud66/data_source_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func dataSourceCloud66StackRead(d *schema.ResourceData, meta interface{}) error
stackEnv := d.Get("environment").(string)

var stack api.Stack
if stackID != "" {
if stackID != "" { //nolint:golint,gocritic
stackResp, err := client.FindStackByUid(stackID)
if stackResp != nil {
stack = *stackResp
Expand Down
26 changes: 12 additions & 14 deletions cloud66/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ func TestProvider_impl(t *testing.T) {
var _ *schema.Provider = Provider()
}

type preCheckFunc = func(*testing.T)

func generateRandomResourceName() string {
return acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
}
Expand Down Expand Up @@ -139,7 +137,7 @@ func testAccCloud66Stack(uid string, name string) {
}

func testAccCloud66Servers(uid string) {
data := fmt.Sprintf(`
data := `
{
"response": [
{
Expand Down Expand Up @@ -199,7 +197,7 @@ func testAccCloud66Servers(uid string) {
"pages": 1
}
}
`)
`

httpmock.RegisterResponder("GET", "https://app.cloud66.com/api/3/stacks/"+uid+"/servers.json", httpmock.NewStringResponder(200, data))
}
Expand Down Expand Up @@ -239,7 +237,7 @@ func testAccCloud66SslCertificateLetsEncrypt(stackID string, uid string) {
}
}`, sslData)
deleteSslResponse := fmt.Sprintf(`{"response": %[1]s}`, sslData)
createSslResponse := fmt.Sprintf(`
createSslResponse := `
{
"response": {
"uuid": null,
Expand All @@ -259,7 +257,7 @@ func testAccCloud66SslCertificateLetsEncrypt(stackID string, uid string) {
"key": null,
"intermediate_certificate": null
}
}`)
}`

httpmock.RegisterResponder("POST", "https://app.cloud66.com/api/3/stacks/"+stackID+"/ssl_certificates.json", httpmock.NewStringResponder(200, createSslResponse))
httpmock.RegisterResponder("GET", "https://app.cloud66.com/api/3/stacks/"+stackID+"/ssl_certificates.json", httpmock.NewStringResponder(200, listSslResponse))
Expand Down Expand Up @@ -302,7 +300,7 @@ func testAccCloud66SslCertificateManual(stackID string, uid string) {
}
}`, sslData)
deleteSslResponse := fmt.Sprintf(`{"response": %[1]s}`, sslData)
createSslResponse := fmt.Sprintf(`
createSslResponse := `
{
"response": {
"uuid": null,
Expand All @@ -322,7 +320,7 @@ func testAccCloud66SslCertificateManual(stackID string, uid string) {
"key": null,
"intermediate_certificate": null
}
}`)
}`

httpmock.RegisterResponder("POST", "https://app.cloud66.com/api/3/stacks/"+stackID+"/ssl_certificates.json", httpmock.NewStringResponder(200, createSslResponse))
httpmock.RegisterResponder("GET", "https://app.cloud66.com/api/3/stacks/"+stackID+"/ssl_certificates.json", httpmock.NewStringResponder(200, listSslResponse))
Expand Down Expand Up @@ -356,7 +354,7 @@ func testAccCloud66EnvVariable(stackID string, key string, value string) {
"pages": 1
}
}`, envVarData)
createEnvVarResponse := fmt.Sprint(`
createEnvVarResponse := `
{
"response": {
"id": 3360669,
Expand All @@ -371,7 +369,7 @@ func testAccCloud66EnvVariable(stackID string, key string, value string) {
"finished_message": null,
"finished_result": null
}
}`)
}`
updateEnvVarResponse := createEnvVarResponse
deleteEnvVarResponse := createEnvVarResponse

Expand All @@ -382,7 +380,7 @@ func testAccCloud66EnvVariable(stackID string, key string, value string) {
}

func testAccCloud66FirewallRequest(stackID string) {
firewallData := fmt.Sprintf(`
firewallData := `
{
"id": 168806136,
"from_ip": "0.0.0.0/0",
Expand All @@ -397,7 +395,7 @@ func testAccCloud66FirewallRequest(stackID string) {
"comments": null,
"created_at": "2022-04-13T04:21:46Z",
"updated_at": "2022-04-13T04:21:46Z"
}`)
}`

listFirewallResponse := fmt.Sprintf(`
{
Expand All @@ -412,7 +410,7 @@ func testAccCloud66FirewallRequest(stackID string) {
"pages": 1
}
}`, firewallData)
createFirewallResponse := fmt.Sprint(`
createFirewallResponse := `
{
"response": {
"id": 3360669,
Expand All @@ -427,7 +425,7 @@ func testAccCloud66FirewallRequest(stackID string) {
"finished_message": null,
"finished_result": null
}
}`)
}`
getFirewallResponse := fmt.Sprintf(`{ "response": %[1]s }`, firewallData)

httpmock.RegisterResponder("POST", "https://app.cloud66.com/api/3/stacks/"+stackID+"/firewalls.json", httpmock.NewStringResponder(200, createFirewallResponse))
Expand Down
2 changes: 1 addition & 1 deletion cloud66/resource_cloud66_env_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func resourceCloud66EnvVariableImport(d *schema.ResourceData, meta interface{})
d.Set("stack_id", stackID)
d.SetId(key)

resourceCloud66EnvVariableRead(d, meta)
resourceCloud66EnvVariableRead(d, meta) //nolint:golint,errcheck

return []*schema.ResourceData{d}, nil
}
Expand Down
6 changes: 3 additions & 3 deletions cloud66/resource_cloud66_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func resourceCloud66FirewallCreate(d *schema.ResourceData, meta interface{}) err
fromIp := d.Get("from_ip").(string)
fromGroupId := d.Get("from_group_id").(int)
fromServerId := d.Get("from_server_id").(int)
if fromIp != "" {
if fromIp != "" { //nolint:golint,gocritic
newRecord.FromIp = fromIp
} else if fromGroupId != 0 {
newRecord.FromGroupId = fromGroupId
Expand All @@ -54,7 +54,7 @@ func resourceCloud66FirewallCreate(d *schema.ResourceData, meta interface{}) err
toIp := d.Get("to_ip").(string)
toGroupId := d.Get("to_group_id").(int)
toServerId := d.Get("to_server_id").(int)
if toIp != "" {
if toIp != "" { //nolint:golint,gocritic
newRecord.ToIp = toIp
} else if toGroupId != 0 {
newRecord.ToGroupId = toGroupId
Expand Down Expand Up @@ -127,7 +127,7 @@ func resourceCloud66FirewallImport(d *schema.ResourceData, meta interface{}) ([]
d.Set("stack_id", stackID)
d.SetId(id)

resourceCloud66FirewallRead(d, meta)
resourceCloud66FirewallRead(d, meta) //nolint:golint,errcheck

return []*schema.ResourceData{d}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion cloud66/resource_cloud66_ssl_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func resourceCloud66SslCertificateImport(d *schema.ResourceData, meta interface{
d.Set("sha256_fingerprint", sha256Fingerprint)
d.SetId(stackID)

resourceCloud66SslCertificateRead(d, meta)
resourceCloud66SslCertificateRead(d, meta) //nolint:golint,errcheck

return []*schema.ResourceData{d}, nil
}
Expand Down
17 changes: 10 additions & 7 deletions cloud66/schema_cloud66_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,27 @@ type Firewall struct {
}

func (firewall *Firewall) Protocol() string {
if firewall.ProtocolCode == "1" {
switch firewall.ProtocolCode {
case "1":
return "tcp"
} else if firewall.ProtocolCode == "2" {
case "2":
return "udp"
} else if firewall.ProtocolCode == "3" {
case "3":
return "icmp"
} else {
default:
return firewall.ProtocolCode
}
}

func (firewall *Firewall) SetProtocol(protocol string) {
if protocol == "tcp" {
switch protocol {
case "tcp":
firewall.ProtocolCode = "1"
} else if protocol == "udp" {
case "udp":
firewall.ProtocolCode = "2"
} else if protocol == "icmp" {
case "icmp":
firewall.ProtocolCode = "3"
default:
}
}

Expand Down

0 comments on commit dd97894

Please sign in to comment.