Skip to content

x/tools/gopls: unusedparams analysis does not check exported functions #65401

@ruilya

Description

@ruilya

gopls version

v0.14.2

go env

GO111MODULE=''
GOARCH='amd64'
GOBIN='/home/rusyanov/go/bin'
GOCACHE='/home/rusyanov/.cache/go-build'
GOENV='/home/rusyanov/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/rusyanov/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/rusyanov/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go-1.21'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go-1.21/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.5'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/rusyanov/src/proj/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3362930225=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Defining a function that does something (for e.g. fmt.Println("sometext")) but is not using it's arguments does not raise a warning.

func F(a int) { // << no warning is raised here, although a is clearly not used and the function has body
	fmt.Printf("test")
}

What did you see happen?

No diagnostic is generated about unused function parameter. Other analyses are ran and displayed as expected.

What did you expect to see?

Warning about unused parameter.

Editor and settings

nvim v0.9.5

local capabilities = require('cmp_nvim_lsp').default_capabilities()

local lspconfig = require("lspconfig")
-- Setup language servers.
lspconfig.gopls.setup({
  capabilities = capabilities,
  settings = {
    gopls = {
      analyses = {
        unusedparams = true,
        shadow = true,
        unusedwrite = true,
        unusedvariable = true,
      },
      staticcheck = true,
      gofumpt = true,
    },
  },
})
require'lspconfig'.clangd.setup{
  capabilities = capabilities
}

full configuration: https://github.com/ilya-rusyanov/nvim-config

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions