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.77k stars 191 forks source link

Lint on save/change #540

Closed tomhampshire closed 4 months ago

tomhampshire commented 4 months ago

Some linters (e.g. mypy, pylint) are very slow, however, it is useful to have linting messages from these whilst coding. With null-ls, it was possible to specify when linters were run (e.g. onsave only, on exit insert mode, etc). Is this possible with nvim-lint?

tomhampshire commented 4 months ago

Cross-post with https://github.com/LazyVim/LazyVim/issues/2589 as there may be a mechanism that will help

EricDriussi commented 4 months ago

I might be missing something here, but the readme shows how to configure an autocmd to run the linter (which I'm guessing would provide the behavior you want?):

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

You could change BufWritePost to whatever event you like or even filter by filetypes with pattern = something which might be useful if struggling with slow linters.

Hope that helps!

tomhampshire commented 4 months ago

Hi - thanks for the suggestion. Where I don't see where this would work is (please correct me if I'm wrong), for example, I want to run ruff (a fast Python linter) on InsertLeave and mypy/pylint (both slow linters) on BufWritePost and BufReadPost

EricDriussi commented 4 months ago

Oh my bad I did not understand you correctly! Unfortunately I can't think of a way to tell the plugin what lint to run on what event, sorry. That being said I'm not a maintainer or anything, I was just passing by. Maybe someone more clever than me can think of something!

mfussenegger commented 4 months ago

example, I want to run ruff (a fast Python linter) on InsertLeave and mypy/pylint (both slow linters) on BufWritePost and BufReadPost

You can setup different autocmds which call try_lint with different linter names

tomhampshire commented 3 months ago

Great - thanks! This would be good information for the readme