From c2ff69bfe9a9b0849525d29c85b79acc3f5e82cf Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Wed, 4 Feb 2026 01:18:17 -0500 Subject: [PATCH] feat(lint): add stderr and ignore_exit_code options Some linters (e.g., cpplint) output to stderr and exit non-zero when lint issues are found, which guard treats as a failure. This adds two options to handle such tools: - `stderr`: capture stderr instead of stdout - `ignore_exit_code`: don't treat non-zero exit as error Example usage: ```lua ft('cpp'):lint({ cmd = 'cpplint', fname = true, stderr = true, ignore_exit_code = true, parse = ..., }) ``` --- lua/guard/_meta.lua | 2 ++ lua/guard/lint.lua | 6 +++--- lua/guard/util.lua | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lua/guard/_meta.lua b/lua/guard/_meta.lua index 5c75c6d..5007747 100644 --- a/lua/guard/_meta.lua +++ b/lua/guard/_meta.lua @@ -28,6 +28,8 @@ ---@field env table? ---@field timeout integer? ---@field health function? +---@field stderr boolean? +---@field ignore_exit_code boolean? ---@alias LintConfig LintConfigTable|fun(): LintConfigTable diff --git a/lua/guard/lint.lua b/lua/guard/lint.lua index 66071af..d99da11 100644 --- a/lua/guard/lint.lua +++ b/lua/guard/lint.lua @@ -12,7 +12,7 @@ local custom_ns = {} ---@async ---@param cmd string[] ---@param cwd string ----@param config {env: table?, timeout: integer?} +---@param config {env: table?, timeout: integer?, stderr: boolean?, ignore_exit_code: boolean?} ---@param input string|string[] ---@return string output ---@return {code: integer, stderr: string, cmd: string}? error @@ -31,7 +31,7 @@ local function exec_linter(cmd, cwd, config, input) handle:write(nil) end) - if result.code ~= 0 and #result.stderr > 0 then + if not config.ignore_exit_code and result.code ~= 0 and #result.stderr > 0 then return '', { code = result.code, stderr = result.stderr, @@ -39,7 +39,7 @@ local function exec_linter(cmd, cwd, config, input) } end - return result.stdout, nil + return config.stderr and result.stderr or result.stdout, nil end ---@param buf number? diff --git a/lua/guard/util.lua b/lua/guard/util.lua index 457b5ee..f83dab0 100644 --- a/lua/guard/util.lua +++ b/lua/guard/util.lua @@ -176,6 +176,8 @@ function M.toolcopy(c) timeout = c.timeout, parse = c.parse, health = c.health, + stderr = c.stderr, + ignore_exit_code = c.ignore_exit_code, } end