Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Configure revive Go linter in GoLand
John Doe
John Doe

Posted on

     

Configure revive Go linter in GoLand

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 configurerevive linter and implement it into GoLand. First of all, we need to download the package usinggo get action.

go get -u github.com/mgechev/revive
Enter fullscreen modeExit fullscreen mode

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 createconfig.toml file with the recommended configuration fromdocs. InstallToml plugin if you are interested in syntax highlighting.

ignoreGeneratedHeader = falseseverity = "warning"confidence = 0.8errorCode = 0warningCode = 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]
Enter fullscreen modeExit fullscreen mode

Configuration and installation steps are completed. Now is time to configureFile 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.

Select <custom> template option

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

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

Example of revive inspection

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

404 bio or critical bugs found.
  • Joined

More fromJohn Doe

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp