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

QoL: Enabling Golang static code analysis with golangci-lint #155

Merged
merged 3 commits into from
Mar 1, 2022

Conversation

detro
Copy link
Contributor

@detro detro commented Feb 24, 2022

Context: https://github.com/hashicorp/terraform-providers-devex-internal/issues/94

Description

I'm setting up golangci-lint with the all the defaults enabled, plus some extras. Follows a list of errors that were fixed, separated by "what caught them".

Default linters (defined here)

internal/provider/data_source_public_key.go:82:7: Error return value of `d.Set` is not checked (errcheck)
	d.Set("algorithm", keyAlgo)
	     ^
internal/provider/resource_cert_request.go:137:7: Error return value of `d.Set` is not checked (errcheck)
	d.Set("cert_request_pem", certReqPem)
	     ^
internal/provider/resource_certificate.go:199:7: Error return value of `d.Set` is not checked (errcheck)
	d.Set("cert_pem", certPem)
	     ^
internal/openssh/lib_test.go:29:17: ineffectual assignment to err (ineffassign)
	rawPrivateKey, err := ssh.ParseRawPrivateKey(pemOpenSSHPrvKeyBytes)
	               ^
internal/openssh/lib_test.go:61:17: ineffectual assignment to err (ineffassign)
	rawPrivateKey, err := ssh.ParseRawPrivateKey(pemOpenSSHPrvKeyBytes)
	               ^
internal/openssh/lib_test.go:88:17: ineffectual assignment to err (ineffassign)
	rawPrivateKey, err := ssh.ParseRawPrivateKey(pemOpenSSHPrvKeyBytes)
	               ^
internal/provider/data_source_public_key.go:56:2: SA4006: this value of `bytes` is never used (staticcheck)
	bytes := []byte("")
...

deadcode, exportloopref, godot, gofmt, gosimple, govet, ineffassign, makezero, misspell, nilerr, staticcheck, structcheck, unconvert, unparam, unused, varcheck

internal/provider/resource_private_key.go:21:22: Comment should end in a period (godot)
// selected algorithm
                     ^
internal/provider/resource_private_key.go:25:39: Comment should end in a period (godot)
// according to the selected algorithm
                                      ^
internal/provider/types.go:3:56: Comment should end in a period (godot)
// Algorithm represents a type of private key algorithm
                                                       ^
internal/provider/resource_certificate.go:135: File is not `gofmt`-ed with `-s` (gofmt)
		"set_subject_key_id": &schema.Schema{
internal/provider/provider.go:35:72: nameFromResourceData - result 1 (error) is always nil (unparam)
func nameFromResourceData(nameMap map[string]interface{}) (*pkix.Name, error) {
                                                                       ^

predeclared, durationcheck, errcheck

internal/provider/resource_certificate.go:148:45: Multiplication of durations: `time.Duration(d.Get("validity_period_hours").(int)) * time.Hour` (durationcheck)
	template.NotAfter = template.NotBefore.Add(time.Duration(d.Get("validity_period_hours").(int)) * time.Hour)
	                                           ^
internal/provider/resource_certificate.go:234:25: Multiplication of durations: `time.Duration(-d.Get("early_renewal_hours").(int)) * time.Hour` (durationcheck)
		earlyRenewalPeriod := time.Duration(-d.Get("early_renewal_hours").(int)) * time.Hour

Links

@detro detro requested a review from a team as a code owner February 24, 2022 17:53
@detro detro added enhancement github_actions Pull requests that update Github_actions code go Pull requests that update Go code QoL Quality of Life and removed size/M labels Feb 24, 2022
Copy link
Contributor

@bookshelfdave bookshelfdave left a comment

Choose a reason for hiding this comment

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

lgtm 👍 , just a few misc questions

.golangci.yml Show resolved Hide resolved
internal/provider/util.go Show resolved Hide resolved
internal/provider/provider.go Show resolved Hide resolved
@github-actions github-actions bot added the size/M label Mar 1, 2022
@detro detro merged commit 06b10c1 into main Mar 1, 2022
@detro detro deleted the detro/QoL-golangci-lint branch March 1, 2022 15:08
@detro detro added this to the v3.2.0 milestone Mar 16, 2022
@detro detro self-assigned this Mar 30, 2022
jackivanov pushed a commit to jackivanov/terraform-provider-tls that referenced this pull request Aug 4, 2022
…corp#155)

* Enabling golangci-lint (default + extra linters) and wire-up GH Action before acceptance tests

* Fix all the issues found by the new `golanci-lint` configuration

* Error message format typo
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement github_actions Pull requests that update Github_actions code go Pull requests that update Go code QoL Quality of Life size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants