mfussenegger / nvim-lint

An asynchronous linter plugin for Neovim complementary to the built-in Language Server Protocol support.
GNU General Public License v3.0
1.94k stars 204 forks source link

feat: add configuration of global (`*`) and fallback (`_`) linters #549

Closed mehalter closed 7 months ago

mehalter commented 7 months ago

This adds the ability to provide both global and fallback linters which play nicely with the filetype resolution. I also added a couple tests to make sure they get applied correctly.

mfussenegger commented 7 months ago

Thanks but the way to add fallback linter is to add additional try_lint calls: https://github.com/mfussenegger/nvim-lint/issues/355#issuecomment-1759203127

mehalter commented 7 months ago

Okie dokie. This is how I currently do it as well. I noticed that this code seems to be duplicated basically in most configurations I see that use nvim-lint which seems like it would be a good candidate to include upstream. Also because it would enable much better support for using the _resolve_linter_by_ft function for building statusline entities rathern than using get_running since that is not the most useful if I want to see a list of linters that are configured to run in the buffer. Totally understand if you don't want to support this out of the box though!

fresh2dev commented 4 months ago

Found this out PR due to my own confusion, assuming that nvim-lint could be configured like conform.vim.

This PR enables specifying both global linters and/or a fallback linters. The workaround in #355 only makes it possible to specify global linters.

mehalter commented 4 months ago

@fresh2dev you can leverage the fact that Lua is pretty loose and do this by overriding the internal Lua API in nvim-lint. Here is an example that is similar to how I'm doing this now in my personal configuration:

local lint = require "lint"

local orig_resolve_linter_by_ft = lint._resolve_linter_by_ft
lint._resolve_linter_by_ft = function(...)
  local linters = orig_resolve_linter_by_ft(...)
  if not next(linters) then linters = lint.linters_by_ft["_"] end -- add fallback linters
  vim.list_extend(linters, lint.linters_by_ft["*"]) -- add global linters

  return linters
end

Hopefully there are no breaking changes to this _resolve_linter_by_ft function 😅

fresh2dev commented 4 months ago

Awesome; thank you!