Closed mehalter closed 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
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!
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.
@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 😅
Awesome; thank you!
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.