Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[help] golangci-lint not showing any diagnostics #690

Open
scottenock opened this issue Oct 25, 2024 · 4 comments
Open

[help] golangci-lint not showing any diagnostics #690

scottenock opened this issue Oct 25, 2024 · 4 comments

Comments

@scottenock
Copy link

Hi there, I'm trying to configure golangci-lint but I can't for the life of me figure out what's wrong 🙈

plugins:

return {
  {
    "stevearc/conform.nvim",
    event = 'BufWritePre', -- uncomment for format on save
    opts = require "configs.conform",
  },

  -- These are some examples, uncomment them if you want to see them work!
  {
    "neovim/nvim-lspconfig",
    event = { "BufReadPre", "BufNewFile" },
    config = function()
      require("nvchad.configs.lspconfig").defaults()
      require "configs.lspconfig"
    end,
  },

  {
    "mfussenegger/nvim-lint",
    event = { "BufReadPre", "BufNewFile" },
    config = function()
      require "configs.lint"
    end,
  },
}

configs.lint.lua:

local lint = require("lint")

lint.linters_by_ft = {
  go = { "golangcilint" }
}

vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
  callback = function()
    lint.try_lint()
  end,
})

vim.keymap.set("n", "<leader>li", function()
  lint.try_lint()
end, { desc = "Trigger linting for current file" })

vim.api.nvim_create_user_command("LintInfo", function()
  local filetype = vim.bo.filetype
  local linters = require("lint").linters_by_ft[filetype]

  if linters then
    print("Linters for " .. filetype .. ": " .. table.concat(linters, ", "))
  else
    print("No linters configured for filetype: " .. filetype)
  end
end, {})

I have verified that running golangci-lint from the command line I get a bunch of linting errors but inside nvim none of these appear 🤔

Appreciate any help regarding this 🙏

version installed: golangci-lint has version 1.61.0 built with go1.23.1 from a1d6c56 on 2024-09-09T14:33:19Z

@dzolt-4chain
Copy link

I've got the same problem. It shows diagnostic errors but inside error message and I cannot cycle through them

image

@dzolt-4chain
Copy link

I've managed to remove these errors by renaming my lint file from .golangci.yml to golangci-lint.yml. Please see @scottenock if thats your case

@scottenock
Copy link
Author

Thanks for the suggestion @dzolt-4chain but this didn't end up working for me :(

@AtomicMegaNerd
Copy link

I too am having issues, as the autocmd is not firing (ignore my custom loader code is just fires off vim.notify events for any plugins I cannot load):

return {
	"mfussenegger/nvim-lint",
	config = function()
		local utils = require("amn.utils")
		local lint = utils.do_import("lint")
		if not lint then
			return
		end

		lint.linters_by_ft = {
			go = { "golangcilint" },
			markdown = { "markdownlint" },
		}

		vim.api.nvim_create_autocmd("BufWritePost", {
			callback = function()
				lint.try_lint()
			end,
		})
	end,
}

However if I run the following manually in command mode while a buffer is open golangci-lint linter runs fine:

lua require("lint").try_lint()

The linter also is in the path and runs fine from the CLI.

Additionally, the Markdown linter is triggering using the autocmd which is why I am somewhat confused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants