hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.65k stars 9.55k forks source link

Suggestion: Implement golangci on terraform? #18251

Open JonKohler opened 6 years ago

JonKohler commented 6 years ago

Hey Terraform community, We've been working on a terraform provider, which has driven us to investigate the current "state of the state" of static code analysis tools to help with code quality, style guidance, and so on.

I've been looking around for the past ~1-2 weeks, trying out things like code climate, codefactor, codacy, hound, scrutinizer, and all of them "do stuff", but none of them take it to the next level like golangci does, specifically for go based code.

As with many online, github integrated tools, golangci is free for open source projects, and hooks right into the repo. It helps with PR's, and seems to catch a lot of really good stuff, not just styling and duplication like most tools, but actual code level issues.

Note: I've got no position/advantage in golangci at all, just have fallen in love with it, and I truly think that it would benefit the terraform project at large.

I'd love to see this become a standard for both the terraform project, as well as the terraform providers organization so that everyone can be playing by the same coding rules.

apparentlymart commented 6 years ago

Hi @JonKohler! Thanks for sharing the pointer to golangci.

At the moment we are not planning to make any significant changes to our CI and release strategy, because our team's focus is elsewhere. However, over time we will continue to iterate on how both Terraform Core and the providers in the terraform-providers organization are managed, and I agree that golangci looks like a nice curated collection of linters to investigate.

Thanks again!

JonKohler commented 6 years ago

@apparentlymart - Hey Martin, thanks for responding quickly and my apologies on not being clear before.

golangci isn't a CI (like travis, etc), but rather a code analysis and pull request tool, like codacy, hound, codefactor, code climate etc.

The goal here is to help increase the quality and review of PRs for go based code.

Literally all you need to do is go to https://golangci.com/repos/github, turn on the appropriate repos, and commit a .golangci.yml file to the root of the repo to control your preferences.

Here's an example from our in-development provider: https://github.com/nutanix/terraform-provider-nutanix/pull/146

You can see it makes very nice inline comments, and leverages the github API's to inject go/no-go for status/checks on the PR

You can see the configuration we're using for the .golangci.yml on our provider, here: https://github.com/nutanix/terraform-provider-nutanix/blob/develop/.golangci.yml