repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
neovim/lua/bugabinga/lint.lua
Rawlocal puk = require 'std.puk'
local auto = require 'std.auto'
puk.defer 'lint' (function(lint)
local linters_by_ft = {
lua = { 'selene' },
sh = { 'shellcheck', 'dotenv_linter' },
systemd = { 'systemd-analyze' },
editorconfig = { 'editorconfig-checker' },
yaml = { 'yq' },
}
for k, v in pairs(linters_by_ft) do
lint.linters[k] = v
end
local timer = vim.uv.new_timer()
local DEBOUNCE_MS = 500
local try_lint = function()
local bufnr = vim.api.nvim_get_current_buf()
if timer then
timer:stop()
timer:start(DEBOUNCE_MS, 0,
vim.schedule_wrap(function()
if vim.api.nvim_buf_is_valid(bufnr) then
vim.api.nvim_buf_call(bufnr, function() lint.try_lint(nil, { ignore_errors = true }) end)
end
end))
end
end
auto 'Lint' {
description = 'Attempt linting current file',
events = 'BufWritePost',
command = try_lint,
}
end)