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

[PROPOSAL] Switch from gometalinter to golangci-lint #7457

Merged
merged 4 commits into from
Feb 6, 2019
Merged

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Feb 6, 2019

Our TravisCI implementation with gometalinter has been a successful experiment in utilizing the various Go community linting tools to help improve the codebase quality and prevent common pull request review items. Recently though, we have consistently been having performance and functionality issues, especially after the switch from govendor to Go modules. Errantly failing TravisCI runs due to the linting timeouts distracts from useful review and feedback. Certain linting issues also appear to be missing occassionally from the output.

The choice of gometalinter at the time of the initial implementation was based purely on gometalinter having a well established base and golangci-lint being new to the scene. Since then, golangci-lint has grown in usage and appears to reflect Go language/tooling updates in a timely manner. It seems to work out of the box with our Go modules setup outside the GOPATH.

While the Terraform AWS Provider and the Terraform Azure* Providers have been leading the experimentation with Go linting among actively maintained HashiCorp Terraform Providers, there are no currently defined Terraform provider development standards for code quality based on specific tooling. Given this, we should feel free to swap the implementation either temporarily to workaround the current issues or more permanently should it make sense.

By example, here is the performance improvement for me locally when working outside the GOPATH (2.8 GHz Intel Core i7):

# gometalinter
$ time make lint
==> Checking source code against linters...
make lint  412.87s user 371.90s system 476% cpu 2:44.75 total

# golangci-lint
$ time make lint
==> Checking source code against linters...
make lint  74.04s user 7.21s system 355% cpu 22.842 total

The previous commits in this pull request fix new linting issues found from the updated linters in golangci-lint. They can be cherry-picked into the codebase outside the lint tooling changes as necessary.

$ make lint
==> Checking source code against linters...
aws/resource_aws_iam_user_test.go:639:85: unnecessary conversion (unconvert)
    authenticationCode1, err := totp.GenerateCode(secret, time.Now().Add(time.Duration(-30*time.Second)))
                                                                                      ^
aws/config_test.go:49:15: Error return value of `buf.ReadFrom` is not checked (errcheck)
    buf.ReadFrom(r.Body)
                ^
aws/resource_aws_budgets_budget_test.go:331:11: Error return value of `t.Execute` is not checked (errcheck)
  t.Execute(&doc, budgetConfig)
           ^
aws/resource_aws_budgets_budget_test.go:351:11: Error return value of `t.Execute` is not checked (errcheck)
  t.Execute(&doc, budgetConfig)
           ^
aws/resource_aws_budgets_budget_test.go:377:11: Error return value of `t.Execute` is not checked (errcheck)
  t.Execute(&doc, budgetConfig)
           ^
aws/resource_aws_budgets_budget_test.go:397:11: Error return value of `t.Execute` is not checked (errcheck)
  t.Execute(&doc, budgetConfig)
           ^
aws/resource_aws_budgets_budget_test.go:423:11: Error return value of `t.Execute` is not checked (errcheck)
  t.Execute(&doc, budgetConfig)
           ^
aws/resource_aws_ecs_task_definition_test.go:438:32: Error return value of `conn.DeregisterTaskDefinition` is not checked (errcheck)
    conn.DeregisterTaskDefinition(&ecs.DeregisterTaskDefinitionInput{
                                 ^
aws/resource_aws_iam_access_key.go:172:9: Error return value of `h.Write` is not checked (errcheck)
  h.Write(message)
         ^
aws/resource_aws_lambda_function_test.go:472:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func_modified.js": "lambda.js"}, zipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:917:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func.js": "lambda.js"}, zipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:929:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func_modified.js": "lambda.js"}, zipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:973:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func.js": "lambda.js"}, zipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:985:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func_modified.js": "lambda.js"}, updatedZipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:1023:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func.js": "lambda.js"}, zipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:1036:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func_modified.js": "lambda.js"}, zipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:1075:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func.js": "lambda.js"}, zipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:1088:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func_modified.js": "lambda.js"}, zipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:1488:18: Error return value of `zipFile.Truncate` is not checked (errcheck)
  zipFile.Truncate(0)
                  ^
aws/resource_aws_lambda_function_test.go:1489:14: Error return value of `zipFile.Seek` is not checked (errcheck)
  zipFile.Seek(0, 0)
              ^
aws/resource_aws_s3_bucket_test.go:2085:11: Error return value of `t.Execute` is not checked (errcheck)
  t.Execute(&doc, struct{ GUID int }{GUID: randInt})
           ^
aws/resource_aws_autoscaling_group.go:515:49: `Identifer` is a misspelling of `Identifier` (misspell)
  // Availability Zones are optional if VPC Zone Identifer(s) are specified
                                                 ^
aws/resource_aws_route53_record.go:265:10: `resouce` is a misspelling of `resource` (misspell)
    // for resouce update here we simply fall through to
           ^
aws/resource_aws_db_instance_test.go:1289:56: `identifer` is a misspelling of `identifier` (misspell)
// This acceptance test explicitly tests when snapshot_identifer is set,
                                                       ^
aws/resource_aws_rds_cluster_test.go:1263:56: `identifer` is a misspelling of `identifier` (misspell)
// This acceptance test explicitly tests when snapshot_identifer is set,
                                                       ^
make: *** [lint] Error 1

bflad added 4 commits February 6, 2019 01:33
Previous output from linting:

```
aws/config_test.go:49:15: Error return value of `buf.ReadFrom` is not checked (errcheck)
    buf.ReadFrom(r.Body)
                ^
aws/resource_aws_budgets_budget_test.go:331:11: Error return value of `t.Execute` is not checked (errcheck)
  t.Execute(&doc, budgetConfig)
           ^
aws/resource_aws_budgets_budget_test.go:351:11: Error return value of `t.Execute` is not checked (errcheck)
  t.Execute(&doc, budgetConfig)
           ^
aws/resource_aws_budgets_budget_test.go:377:11: Error return value of `t.Execute` is not checked (errcheck)
  t.Execute(&doc, budgetConfig)
           ^
aws/resource_aws_budgets_budget_test.go:397:11: Error return value of `t.Execute` is not checked (errcheck)
  t.Execute(&doc, budgetConfig)
           ^
aws/resource_aws_budgets_budget_test.go:423:11: Error return value of `t.Execute` is not checked (errcheck)
  t.Execute(&doc, budgetConfig)
           ^
aws/resource_aws_ecs_task_definition_test.go:438:32: Error return value of `conn.DeregisterTaskDefinition` is not checked (errcheck)
    conn.DeregisterTaskDefinition(&ecs.DeregisterTaskDefinitionInput{
                                 ^
aws/resource_aws_iam_access_key.go:172:9: Error return value of `h.Write` is not checked (errcheck)
  h.Write(message)
         ^
aws/resource_aws_lambda_function_test.go:472:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func_modified.js": "lambda.js"}, zipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:917:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func.js": "lambda.js"}, zipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:929:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func_modified.js": "lambda.js"}, zipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:973:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func.js": "lambda.js"}, zipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:985:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func_modified.js": "lambda.js"}, updatedZipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:1023:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func.js": "lambda.js"}, zipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:1036:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func_modified.js": "lambda.js"}, zipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:1075:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func.js": "lambda.js"}, zipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:1088:31: Error return value of `testAccCreateZipFromFiles` is not checked (errcheck)
          testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func_modified.js": "lambda.js"}, zipFile)
                                   ^
aws/resource_aws_lambda_function_test.go:1488:18: Error return value of `zipFile.Truncate` is not checked (errcheck)
  zipFile.Truncate(0)
                  ^
aws/resource_aws_lambda_function_test.go:1489:14: Error return value of `zipFile.Seek` is not checked (errcheck)
  zipFile.Seek(0, 0)
              ^
aws/resource_aws_s3_bucket_test.go:2085:11: Error return value of `t.Execute` is not checked (errcheck)
  t.Execute(&doc, struct{ GUID int }{GUID: randInt})
           ^
```
Previous output from linting:

```
aws/resource_aws_autoscaling_group.go:515:49: `Identifer` is a misspelling of `Identifier` (misspell)
  // Availability Zones are optional if VPC Zone Identifer(s) are specified
                                                 ^
aws/resource_aws_route53_record.go:265:10: `resouce` is a misspelling of `resource` (misspell)
    // for resouce update here we simply fall through to
           ^
aws/resource_aws_db_instance_test.go:1289:56: `identifer` is a misspelling of `identifier` (misspell)
// This acceptance test explicitly tests when snapshot_identifer is set,
                                                       ^
aws/resource_aws_rds_cluster_test.go:1263:56: `identifer` is a misspelling of `identifier` (misspell)
// This acceptance test explicitly tests when snapshot_identifer is set,
                                                       ^
```
Previous output from linting:

```
aws/resource_aws_iam_user_test.go:639:85: unnecessary conversion (unconvert)
    authenticationCode1, err := totp.GenerateCode(secret, time.Now().Add(time.Duration(-30*time.Second)))
                                                                                      ^
```
Our TravisCI implementation with [`gometalinter`](https://github.com/alecthomas/gometalinter) has been a successful experiment in utilizing the various Go community linting tools to help improve the codebase quality and prevent common pull request review items. Recently though, we have consistently been having performance and functionality issues, especially after the switch from `govendor` to Go modules. Errantly failing TravisCI runs due to the linting timeouts distracts from useful review and feedback. Certain linting issues also appear to be missing occassionally from the output.

The choice of `gometalinter` at the time of the initial implementation was based purely on `gometalinter` having a well established base and [`golangci-lint`](https://github.com/golangci/golangci-lint) being new to the scene. Since then, `golangci-lint` has grown in usage and appears to reflect Go language/tooling updates in a timely manner. It seems to work out of the box with our Go modules setup outside the `GOPATH`.

While the Terraform AWS Provider and the Terraform Azure* Providers have been leading the experimentation with Go linting among actively maintained HashiCorp Terraform Providers, there are no currently defined Terraform provider development standards for code quality based on specific tooling. Given this, we should feel free to swap the implementation either temporarily to workaround the current issues or more permanently should it make sense.

By example, here is the performance improvement for me locally when working outside the `GOPATH` (2.8 GHz Intel Core i7):

```console
# gometalinter
$ time make lint
==> Checking source code against linters...
make lint  412.87s user 371.90s system 476% cpu 2:44.75 total

# golangci-lint
$ time make lint
==> Checking source code against linters...
make lint  74.04s user 7.21s system 355% cpu 22.842 total
```
@bflad bflad added proposal Proposes new design or functionality. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. provider Pertains to the provider itself, rather than any interaction with AWS. hashibot/ignore labels Feb 6, 2019
@bflad bflad requested a review from a team February 6, 2019 06:45
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Feb 6, 2019
@bflad bflad merged commit 75a9ebb into master Feb 6, 2019
@bflad bflad deleted the t-golangci-lint branch February 6, 2019 17:07
@bflad
Copy link
Contributor Author

bflad commented Feb 6, 2019

I'm going to re-run all the failed TravisCI jobs I can find.

@github-actions
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 issues.
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 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
proposal Proposes new design or functionality. provider Pertains to the provider itself, rather than any interaction with AWS. size/L Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants