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 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. Install Toml plugin if you are interested in syntax highlighting.
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 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.
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 (
-config config.toml -formatter unix ./…
-configpath to our config that we created previously.
-formattertype of formatter. I prefer Unix.
./..to check all Go files inside the project directory.
- Output path to refresh: empty.
- Working directory:
- 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.
That’s it. Save changes, then try to create a simple file and save changes. Congrats! 🎉