|
| 1 | +local lint -- cache for the nvim-lint package |
1 | 2 | ---@type LazySpec |
2 | 3 | return { |
3 | 4 | "mfussenegger/nvim-lint", |
4 | 5 | event = "User AstroFile", |
5 | 6 | dependencies = { "williamboman/mason.nvim" }, |
6 | 7 | specs = { |
7 | 8 | { "jay-babu/mason-null-ls.nvim", optional = true, opts = { methods = { diagnostics = false } } }, |
| 9 | + { |
| 10 | + "AstroNvim/astrocore", |
| 11 | + ---@param opts AstroCoreOpts |
| 12 | + opts = function(_, opts) |
| 13 | + local timer = (vim.uv or vim.loop).new_timer() |
| 14 | + if not opts.autocmds then opts.autocmds = {} end |
| 15 | + opts.autocmds.auto_lint = { |
| 16 | + { |
| 17 | + event = { "BufWritePost", "BufReadPost", "InsertLeave", "TextChanged" }, |
| 18 | + desc = "Automatically lint with nvim-lint", |
| 19 | + callback = function() |
| 20 | + -- only run autocommand when nvim-lint is loaded |
| 21 | + if lint then |
| 22 | + timer:start(100, 0, function() |
| 23 | + timer:stop() |
| 24 | + vim.schedule(lint.try_lint) |
| 25 | + end) |
| 26 | + end |
| 27 | + end, |
| 28 | + }, |
| 29 | + } |
| 30 | + end, |
| 31 | + }, |
8 | 32 | }, |
9 | 33 | opts = {}, |
10 | 34 | config = function(_, opts) |
11 | | - local lint, astrocore = require "lint", require "astrocore" |
12 | | - |
| 35 | + local astrocore = require "astrocore" |
| 36 | + lint = require "lint" |
13 | 37 | lint.linters_by_ft = opts.linters_by_ft or {} |
14 | 38 | for name, linter in pairs(opts.linters or {}) do |
15 | 39 | local base = lint.linters[name] |
@@ -39,17 +63,6 @@ return { |
39 | 63 | return linters |
40 | 64 | end) |
41 | 65 |
|
42 | | - lint.try_lint() -- start linter immediately |
43 | | - local timer = vim.loop.new_timer() |
44 | | - vim.api.nvim_create_autocmd({ "BufWritePost", "BufReadPost", "InsertLeave", "TextChanged" }, { |
45 | | - group = vim.api.nvim_create_augroup("auto_lint", { clear = true }), |
46 | | - desc = "Automatically try linting", |
47 | | - callback = function() |
48 | | - timer:start(100, 0, function() |
49 | | - timer:stop() |
50 | | - vim.schedule(lint.try_lint) |
51 | | - end) |
52 | | - end, |
53 | | - }) |
| 66 | + lint.try_lint() |
54 | 67 | end, |
55 | 68 | } |
0 commit comments