| skipped 9 lines |
10 | 10 | | }, |
11 | 11 | | config = function(_, opts) |
12 | 12 | | local lint = require "lint" |
| 13 | + | |
13 | 14 | | lint.linters_by_ft = opts.linters_by_ft |
| 15 | + | for name, linter in pairs(opts.linters or {}) do |
| 16 | + | lint.linters[name] = (type(linter) == "table" and type(lint.linters[name]) == "table") |
| 17 | + | and vim.tbl_deep_extend("force", lint.linters[name], linter) |
| 18 | + | or linter |
| 19 | + | end |
14 | 20 | | |
15 | | - | lint.try_lint() -- start linter immediately |
| 21 | + | local function try_lint() |
| 22 | + | local names = lint._resolve_linter_by_ft(vim.bo.filetype) |
| 23 | + | |
| 24 | + | -- Add fallback linters and global linters. |
| 25 | + | if #names == 0 then names = lint.linters_by_ft["_"] or {} end |
| 26 | + | vim.list_extend(names, lint.linters_by_ft["*"] or {}) |
| 27 | + | |
| 28 | + | -- Filter out linters that don't exist or don't match the condition. |
| 29 | + | local ctx = { filename = vim.api.nvim_buf_get_name(0) } |
| 30 | + | ctx.dirname = vim.fn.fnamemodify(ctx.filename, ":h") |
| 31 | + | names = vim.tbl_filter(function(name) |
| 32 | + | local linter = lint.linters[name] |
| 33 | + | return linter |
| 34 | + | and vim.fn.executable(linter.cmd) == 1 |
| 35 | + | and not (type(linter) == "table" and linter.condition and not linter.condition(ctx)) |
| 36 | + | end, names) |
| 37 | + | |
| 38 | + | lint.try_lint(names) |
| 39 | + | end |
| 40 | + | |
| 41 | + | try_lint() -- start linter immediately |
16 | 42 | | local timer = vim.loop.new_timer() |
17 | 43 | | vim.api.nvim_create_autocmd({ "BufWritePost", "BufReadPost", "InsertLeave", "TextChanged" }, { |
18 | 44 | | group = vim.api.nvim_create_augroup("auto_lint", { clear = true }), |
| skipped 1 lines |
20 | 46 | | callback = function() |
21 | 47 | | timer:start(100, 0, function() |
22 | 48 | | timer:stop() |
23 | | - | vim.schedule(lint.try_lint) |
| 49 | + | vim.schedule(try_lint) |
24 | 50 | | end) |
25 | 51 | | end, |
26 | 52 | | }) |
| skipped 3 lines |