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
36 changes: 36 additions & 0 deletions doc/guard.nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,42 @@ That’s what the attributes field does, it extracts them from the json table:
Et voilà!


SIGNATURES FOR CUSTOM LINTER FUNCTIONS *guard.nvim-linter-signatures*

When writing custom lint logic, `fn` and `parse` receive buffer context:

>lua
lint.fn(prev_lines, fname, cwd)
lint.parse(result, bufnr, fname, cwd)
<

Parameters ~
`prev_lines` — buffer content (string)
`result` — linter output (string)
`bufnr` — target buffer number
`fname` — absolute file path
`cwd` — working directory

Use `fname` and `cwd` when linters output relative paths (e.g.,
`terraform validate` on a directory returns diagnostics for all files).

Filtering `terraform validate` by current file:

>lua
parse = function(result, bufnr, fname, cwd)
local current = fname:sub(#cwd + 2) -- +2 to include '/'
local decoded = vim.json.decode(result)

for _, d in ipairs(decoded.diagnostics or {}) do
-- terraform returns relative filenames; match against current
if d.range and d.range.filename == current then
-- add to diagnostics...
end
end
end
<


TAKE ADVANTAGE OF AUTOCMD EVENTS*guard.nvim-advanced-tips-take-advantage-of-autocmd-events*

Guard exposes a `GuardFmt` user event that you can use. It is called both
Expand Down
6 changes: 3 additions & 3 deletions lua/guard/lint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function M.do_lint_single(buf, config)
end

if #data > 0 then
results = lint.parse(data, buf)
results = lint.parse(data, buf, fname, cwd)
end

vim.schedule(function()
Expand All @@ -117,9 +117,9 @@ function M.do_lint_single(buf, config)
end)
end)
else
data = lint.fn(prev_lines)
data = lint.fn(prev_lines, fname, cwd)
if #data > 0 then
results = lint.parse(data, buf)
results = lint.parse(data, buf, fname, cwd)
end

vim.schedule(function()
Expand Down