Using golint in Goland

Context: Ubuntu 18.04, GoLand 2020.1.4, go version go1.14.6 linux/amd64

I decided to enable golint for GoLand. It was a little difficult.

  • There is no pre-configured file watcher for golint (though it is possible to configure it manually).
  • The pre-configured golangci-lint tool did not “just work” for me. When I enabled it GoLand downloaded golangci-lint automatically (which took a while) but then gave me runtime errors.
  • When I finally got golangci-lint to work it didn’t actually run golint (disabled by default).
  • Having the tool run on auto-save is annoying.
  • Having the tool only show errors filters a lot of stuff.

On the golangci-lint tool site it recommends downloading the binary instead of using go get. When I did that it started to work. My guess is that GoLand downloads using go get -u.

Then I found out that golint is not enabled by default in golangci-lint. I enabled it but still didn’t get some of the messages I expected.

Turns out there’s a “magic” flag in golangci-lint that enables all of golint's messaging. Seems like there’s a filter that excludes some messages and a flag to turn off that filter.

My file watcher setting arguments for golangci-lint are now:

run --disable=typecheck --enable=golint --exclude-use-default=false $FileDir$

  • --disable=typecheck is configured by default by GoLand (IIRC, I deleted and re-created it some minutes apart and I think I got it right :wink:
  • --enable=golint turns on golint
  • --exclude-use-default=false turns off the filter that blocks messaging I was expecting

I also turned off Auto-save edited files to trigger the watcher and set Show console to Always. These are personal preferences, YMMV.

So my file watcher for golangci-lint now looks like this:

Hopefully this will save others a little time.

As a side note, I did this after an abortive attempt to use vscode for Go. It has golint built in and I saw a bunch of irritating messages pointing out things I was too lazy to do. The notes above were my attempt to get the same lint behavior from GoLand after I came back to the fold.

I’ve been using Goland for several years (got that full continuity discount, thanks!) but people kept talking about how great vscode is (and how it’s, y’know, free). So I tried it. It’s OK but in the end it didn’t seem to do all of the things Goland did (e.g. refactoring package directory didn’t work so well for me) so I’m back with the IDE that really seems to understand the language.

If you Google “vscode vs GoLand” it seems like I’m in good company. As with so many things, you get what you pay for!

I sent this post to the nice folks at JetBrains and they pointed out a few things:

  • golint is frozen and deprecated (no changes since 2018)
  • GoLand includes some of the checks from golint
  • Access them via File | Settings | Editor | Inspections | Go / Go Modules / Go Template
  • GoLand users can critique/request inspections via YouTrack

At this point I’m going to turn off all linters and explore the built-in inspections.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.