aboutsummaryrefslogtreecommitdiff
path: root/.config/nvim/lua/plugins/eslint.lua
blob: ba74b8ac052125a8d15f31199fd5f9e1327eed32 (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
41
return {
        "mfussenegger/nvim-lint",
        event = { "BufReadPre", "BufNewFile" },
        config = function()
                local lint = require("lint")
                local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })
                local eslint = lint.linters.eslint_d

                -- if Eslint error configuration not found : change MasonInstall eslint@version or npm i -g eslint at a specific version
                lint.linters_by_ft = {
                        javascript = { "eslint_d" },
                        typescript = { "eslint_d" },
                        javascriptreact = { "eslint_d" },
                        typescriptreact = { "eslint_d" },
                        svelte = { "eslint_d" },
                        python = { "pylint" },
                }

                eslint.args = {
                        "--no-warn-ignored",
                        "--format",
                        "json",
                        "--stdin",
                        "--stdin-filename",
                        function()
                                return vim.fn.expand("%:p")
                        end,
                }

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

                vim.keymap.set("n", "<leader>l", function()
                        lint.try_lint()
                end, { desc = "Trigger linting for current file" })
        end,
}