---
title: Go, Hound, and Code Review Comments
teaser: You should be linting your Go code with Hound.
tags: go,hound,style guides,web
author: Bernerd Schaefer
published_on: 2015-10-09
---

![](https://images.thoughtbot.com/go-hound-and-code-review-comments/q5ZQ5LJQRAGeOXUnAb1s_go-hound-demo-receiver-names.png)

Go has a vibrant ecosystem of tools for writing better code,
from the standard [go fmt] command for automatically formatting your code and
[go vet] for detecting incorrect constructs not caught by the compilers,
to community projects like [safesql] for finding SQL injection points
and [many, many more][gometalinter].

  [safesql]: https://github.com/stripe/safesql
  [go fmt]: https://blog.golang.org/go-fmt-your-code
  [go vet]: https://golang.org/cmd/vet/
  [gometalinter]: https://github.com/alecthomas/gometalinter#supported-linters

One thing most of these tools have in common
is that they have binary outcomes:
code is correctly formatted after running `go fmt`;
code which is flagged by `go vet` is incorrect.
This means they can be run automatically.
Some, like `go fmt`, after saving in an editor,
others as a part of the build or CI process.

But not all tools have such strong guarantees.

## Golint

[Golint] is a linter for Go source code.
Where other tools are concerned with formatting or correctness,
Golint is concerned with **style**.

Golint automates many of the suggestions found
in [Effective Go] and the [CodeReviewComments wiki page].

For example, if you run Golint against the following code:

```go
package request

func RequestFromJSON(data []byte) (Request, error) {
  // ...
}
```

It will note that:

> func name will be used as `request.RequestFromJSON`
> by other packages, and that stutters;
> consider calling this `FromJSON`.

It will also check that
exported methods and types have properly formatted comments,
receiver names are consistent across methods definitions,
initialisms like JSON and HTTP are capitalized for consistency with other packages,
and much more.

Golint is a valuable tool
for helping to maintain a consistent style
both within a package,
and with the larger Go ecosystem.

It's good to keep in mind, though, that [Golint is not perfect]:

> The suggestions made by golint are exactly that: suggestions.
> Golint is not perfect, and has both false positives and false negatives.
> this tool is not, and will never be, trustworthy enough for its suggestions
> to be enforced automatically, for example as part of a build process.

This makes it a bit awkward to use:
it can't be run on CI
but most developers won't want it to run on save, either.
Also for projects that accept changes from a large number of developers,
particulary open source projects,
it's problematic to rely on a particular local development environment.

  [Golint]: https://github.com/golang/lint
  [Golint is not perfect]: https://github.com/golang/lint#purpose
  [CodeReviewComments wiki page]: https://github.com/golang/go/wiki/CodeReviewComments
  [Effective Go]: https://golang.org/doc/effective_go.html

## Enter Hound

What does [Hound] have to do with all this?

We recently added [support for Go][Go config] and Golint
with a [service written in Go][hound-go]!

  [Hound]: https://houndci.com
  [Go config]: https://houndci.com/configuration#go
  [hound-go]: https://github.com/thoughtbot/hound-go

Hound is a great way to lint your Go code,
because that's what it's built for:
it's continuous integration for style!

Hound integrates with your existing GitHub Pull Request workflow,
adding Golint suggestions as comments on the files in a PR.

![](https://images.thoughtbot.com/go-hound-and-code-review-comments/u6Q3rVmtRXm7OocVtida_go-hound-demo-json-field.png)

This turns out to be a great place for style suggestions to go:

  * It doesn't rely on any particular local setup.
  * It's where you would discuss style if Golint didn't exist.
  * If you disagree, you can talk about it inline.
  * If you update the PR to adopt a suggestion, the comment will be marked as outdated.

We think Hound is the best way
to add style-checking to your workflow.
And since it's free for open source projects,
it couldn't be easier to [get started][Hound].

Let us know what you think!
