Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/lint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ M.try_lint({names?}, {opts?}) *lint.try_lint*


Parameters: ~
{names?} (string|string[]) name of the linter
{opts?} ({cwd?:string,ignore_errors?:boolean}) options
{names?} (string|string[]) name of the linter
{opts?} ({cwd?:string,ignore_errors?:boolean,stdin_only?:boolean}) options


M.get_namespace({name}) *lint.get_namespace*
Expand Down
27 changes: 16 additions & 11 deletions lua/lint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ M.linters_by_ft = {
--- If no names are given, it runs the linters configured in `linters_by_ft`
---
---@param names? string|string[] name of the linter
---@param opts? {cwd?: string, ignore_errors?: boolean} options
---@param opts? {cwd?: string, ignore_errors?: boolean, stdin_only?: boolean} options
function M.try_lint(names, opts)
assert(
vim.diagnostic,
Expand Down Expand Up @@ -82,16 +82,21 @@ function M.try_lint(names, opts)
local running_procs = running_procs_by_buf[bufnr] or {}
for _, linter_name in pairs(names) do
local linter = lookup_linter(linter_name)
local proc = running_procs[linter.name]
if proc then
proc:cancel()
end
running_procs[linter.name] = nil
local ok, lintproc_or_error = pcall(M.lint, linter, opts)
if ok then
running_procs[linter.name] = lintproc_or_error
elseif not opts.ignore_errors then
notify(lintproc_or_error --[[@as string]], vim.log.levels.WARN)
if not opts.stdin_only or linter.stdin then
local proc = running_procs[linter.name]
if proc then
proc:cancel()
end
running_procs[linter.name] = nil
local ok, lintproc_or_error = pcall(M.lint, linter, {
cwd = opts.cwd,
ignore_errors = opts.ignore_errors,
})
if ok then
running_procs[linter.name] = lintproc_or_error
elseif not opts.ignore_errors then
notify(lintproc_or_error --[[@as string]], vim.log.levels.WARN)
end
end
end
running_procs_by_buf[bufnr] = running_procs
Expand Down
Loading