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

Is there a way to toggle a particular linter on and off #553

Closed M-Xue closed 6 months ago

M-Xue commented 6 months ago

I want to add a spell check linter that I can toggle on and off with a keymap. Is there anyway to programatically disable and enable a linter using nvim-lint?

Maybe I could make a persistent state in my nvim config and toggle this value on and off but I need a way to disable/enable this linter based on the value of the state in my autocmd.

mfussenegger commented 6 months ago

You can modify the linters_by_ft table in a keymap if you want to stop running those linters. To learn how to hide/show the results read the vim.diagnostic help page

youngtuotuo commented 6 months ago

For those need a toggle way,

return {
  "mfussenegger/nvim-lint",
  ft = { "python" },
  dependencies = {
    "williamboman/mason.nvim"
  },
  config = function()
    require("lint").linters_by_ft = {
      python = { "ruff" },
    }
    local lint = false
    local toggle_lint = function()
      if lint == true then
        lint = false
        vim.diagnostic.reset(nil, 0)
      else
        lint = true
        require("lint").try_lint()
      end

    end
    vim.keymap.set({ "n" }, "<M-l>", toggle_lint, { noremap = true, desc = "Lint"})
  end,
}
pidgeon777 commented 5 months ago

Am I wrong or this will reset all of the diagnostic for that buffer, and not only the nvim-lint one?