Go: x/tools/gopls: respect staticcheck config file

Created on 3 Jan 2020  路  9Comments  路  Source: golang/go

What version of Go are you using (go version)?

$ go version
go version go1.13 darwin/amd64

Does this issue reproduce with the latest release?

govim is using commit f13409bb, which is pretty new, and it reproduces

What operating system and processor architecture are you using (go env)?

go env Output

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users/llimllib/go/bin"
GOCACHE="/Users/llimllib/Library/Caches/go-build"
GOENV="/Users/llimllib/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/llimllib/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/llimllib/code/tools-golang/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/r4/mc760j7j6xjdgr5p5hxk_xrw0000gq/T/go-build877572449=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I don't know how to use gopls directly, so here's how to reproduce through govim

  1. Create a directory
  2. Create a staticcheck.conf file with these contents:
checks = ["all", "-ST1005"]
  1. Create a main.go file:
package main

import "fmt"

func main() error {
    return fmt.Errorf("This capitalized error should be ignored but isn't")
}
  1. Note that running staticcheck . or staticcheck main.go do not raise any errors
  2. Turn on vim, with govim installed and staticcheck enabled via call govim#config#Set("Staticcheck", 1)
  3. Note that govim flags error ST1005 on line 6

Reading the gopls logs from govim shows:

[Trace - 10:10:46.572 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {"uri":"file:///private/tmp/govim-bug/main.go","version":1,"diagnostics":[{"range":{"start":{"line":5,"character":18},"end":{"line":5,"character":18}},"severity":2,"source":"ST1005","message":"error strings should not be capitalized","tags":[1]}]}

As you can see from the config, ST1005 ought to be ignored for this file.

(I feel pretty certain that govim isn't doing anything wrong in how it launches or communicates with gopls? But if I've got this error filed on the wrong side of that divide, I apologize)

What did you expect to see?

No ST1005 errors flagged on main.go

What did you see instead?

An ST1005 error flagged on main.go

FeatureRequest Tools gopls

Most helpful comment

Not sure if vim supports json config for gopls, however the way to do this in vscode is:

    "gopls": {
        "experimentalDisabledAnalyses": ["ST1000", "ST1003"],
        "staticcheck": true
    }

Which is based on https://github.com/golang/tools/blob/master/gopls/doc/settings.md

All 9 comments

Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here.

Not sure if vim supports json config for gopls, however the way to do this in vscode is:

    "gopls": {
        "experimentalDisabledAnalyses": ["ST1000", "ST1003"],
        "staticcheck": true
    }

Which is based on https://github.com/golang/tools/blob/master/gopls/doc/settings.md

I read that page but missed that flag! I will look into setting that flag in govim.

It seems to me that the issue is still worthwhile because not checking the config file seems a surprising behavior?

It might be because gopls imports staticcheck directly rather than invoking the external binary, but not 100% sure.

Yes, gopls uses the static check analyzeers directly, and does not have or support all the features of the staticcheck binary. It runs the checkers in a very different way and will probably never fully overlap. There are some things in the config that it might be reasonable to converge, but it needs to be done in a way that works for non staticcheck analyzers too, so it needs some thought.

https://github.com/golang/go/issues/36373#issuecomment-570625113

this is not working anymore. Are there still ways to disable individual checks of staticcheck ?

@adityaU yep, the field was changed a little:

"gopls": {
        "staticcheck": true,
        "analyses": {
            "ST1000": false,
            "ST1003": false
        }
// other options
    }

@OneOfOne Thank you so much. :)

It also doesn't appear to respect line based directives, like https://staticcheck.io/docs/#line-based-linter-directives, or does it have a different syntax for that?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ianlancetaylor picture ianlancetaylor  路  519Comments

ianlancetaylor picture ianlancetaylor  路  138Comments

networkimprov picture networkimprov  路  194Comments

griesemer picture griesemer  路  808Comments

miekg picture miekg  路  314Comments