Configure revive Go linter in GoLand
Tags: go, goland, linters, configuration
Published: 2021-03-05 11:55:35

> Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. Revive provides a framework for development of custom rules, and lets you define a strict preset for enhancing your development & code review processes.

Let’s configure [revive linter](https://revive.run/) and implement it into GoLand. First of all, we need to download the package using `go get` action.

```
go get -u github.com/mgechev/revive
```

After that, navigate to `$GOPATH/bin` and try to execute `./revive` to make sure that it works as expected. There is shouldn’t be any errors.

So, the main advantage of revive is easy configurable configs. Go to our project directory and add a new one. I create `config.toml` file with the recommended configuration from [docs](https://revive.run/docs#recommended-configuration). Install [Toml plugin](https://plugins.jetbrains.com/plugin/8195-toml) if you are interested in syntax highlighting.

```config.toml
ignoreGeneratedHeader = false
severity = "warning"
confidence = 0.8
errorCode = 0
warningCode = 0

[rule.blank-imports]
[rule.context-as-argument]
[rule.context-keys-type]
[rule.dot-imports]
[rule.error-return]
[rule.error-strings]
[rule.error-naming]
[rule.exported]
[rule.if-return]
[rule.increment-decrement]
[rule.var-naming]
[rule.var-declaration]
[rule.package-comments]
[rule.range]
[rule.receiver-naming]
[rule.time-naming]
[rule.unexported-return]
[rule.indent-error-flow]
[rule.errorf]
[rule.empty-block]
[rule.superfluous-else]
[rule.unused-parameter]
[rule.unreachable-code]
[rule.redefines-builtin-id]
```

Configuration and installation steps are completed. Now is time to configure [File Watcher](https://www.jetbrains.com/help/go/using-file-watchers.html) in GoLand.

> File Watcher is a GoLand tool that allows you to automatically run a command-line tool like compilers, formatters, or linters when you change or save a file in the IDE.

Go to the IDE settings (`Preferences / Settings | Tools | File Watchers`) and add a new file watcher, select custom template.

![Select <custom> template option](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ak5wjl6773x16ktgtr5l.png)

Add a name, e.g. revive linter, then set File type to Go files. Scope option should be Project Files. The next step is to fill out Tool to Run on Changes:

- Program: path to revive linter (`$GOPATH/bin`), e.g. `/Users/user.name/go/bin/revive`.
- Arguments: `-config config.toml -formatter unix ./…`
  - `-config` path to our config that we created previously.
  - `-formatter` type of formatter. I prefer Unix.
  - `./..` to check all Go files inside the project directory.
- Output path to refresh: empty.
- Working directory: `$ProjectFileDir$` macro.
- Environment variables: empty.

Expand Advanced Options and select Show console to Always and select/unselect other checkboxes if needed. The result of the configuration is presented in the screenshot below.

![New File Watcher configure settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6xw8dqrotre76axodr0m.png)

That’s it. Save changes, then try to create a simple file and save changes. Congrats! 🎉

![Example of revive inspection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qw3g26tentnwgkd50m2b.png)