summaryrefslogtreecommitdiff
path: root/lua/plugins/linter.lua
blob: c804d1c9c9ba7c7bf38c40b31a2d6b6a81d506b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
return {
    {
        "nvim-lint",
        event = { "BufReadPre", "BufNewFile" },
        for_cats = "core.general",
        after = function()
            local lint = require("lint")

            lint.linters_by_ft = {
                python = { "ruff" },
                go = { "golangcilint" },
                rust = { "clippy" },
                c = { "clangtidy" },
                cpp = { "clangtidy" },
                java = { "checkstyle" },
                cmake = { "cmakelint" },
                javascript = { "eslint_d" },
                typescript = { "eslint_d" },
            }

            local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })

            vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost" }, {
                group = lint_augroup,
                callback = function()
                    lint.try_lint(nil, { ignore_errors = true })
                end,
            })

            vim.api.nvim_create_autocmd({ "InsertLeave" }, {
                group = lint_augroup,
                callback = function()
                    if vim.bo.filetype ~= "rust" then
                        lint.try_lint(nil, { ignore_errors = true })
                    end
                end,
            })
        end,
    },
}