ray-x / go.nvim

G'day Nvimer, Joyful Gopher: Discover the Feature-Rich Go Plugin for Neovim
MIT License
2.02k stars 121 forks source link

question: how to disable golangci-lint linters? #491

Closed vegerot closed 1 month ago

vegerot commented 1 month ago

On my system, I only have a few golangci-lint linters selected:

$ golangci-lint linters
Enabled by your configuration linters:
errcheck: errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false]
gosimple: Linter for Go source code that specializes in simplifying code [fast: false, auto-fix: false]
govet: Vet examines Go source code and reports suspicious constructs. It is roughly the same as 'go vet' and uses its passes. [fast: false, auto-fix: false]
ineffassign: Detects when assignments to existing variables are not used [fast: true, auto-fix: false]
staticcheck: It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary. The author of staticcheck doesn't support or approve the use of staticcheck as a library inside golangci-lint. [fast: false, auto-fix: false]
unused: Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false]

and when I run golangci-lint run myfile.go I do not get any errors.

However, when I open myfile.go in nvim I get

image

It looks like this diagnostic is coming from revive, which isn't enabled when I run golangci-lint from the command line.

Question: how do I make go.nvim use only the linters I have configured for golangci-lint by default, or at least disable revive?

ray-x commented 1 month ago

The diagnostics come from

  1. golangci-lint, it configure with
    null_ls = {
    golangci_lint = {
      -- disable = {'errcheck', 'staticcheck'}, -- linters to disable empty by default
      -- enable = {'govet', 'ineffassign','revive', 'gosimple'}, -- linters to enable; empty by default
    },
    },
  2. gopls please set lsp_cfg . Please check go/lsp.lua
vegerot commented 1 month ago

@ray-x thank you! Do I need null_ls to configure it? This is my current config https://github.com/vegerot/dotfiles/blob/c69dd185b82ca955d99d556eea76472059a49add/.config/nvim/init.vim#L257-L296

ray-x commented 1 month ago

no, if you did not install null-ls, that means golangci-lint was not used as lsp diagnostics source. You can change lsp_cfg the default setting is : https://github.com/ray-x/go.nvim/blob/e66c3240d26936428cd0f320dc5ffa1eb01538b8/lua/go/gopls.lua#L346-L362

vegerot commented 1 month ago

Thank you! I'm silly, I thought the diagnostic was coming from revive but it was coming from ST1003. tysm 🙂

Fixed in https://github.com/vegerot/dotfiles/commit/b9d503612aa79ecc2cb2a4ad9532645f3b820b5e