Skip to content

Commit 5c961bc

Browse files
committed
docs: Add linter signatures and terraform example
1 parent cc011d8 commit 5c961bc

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

doc/guard.nvim.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,42 @@ That’s what the attributes field does, it extracts them from the json table:
637637
Et voilà!
638638

639639

640+
SIGNATURES FOR CUSTOM LINTER FUNCTIONS *guard.nvim-linter-signatures*
641+
642+
When writing custom lint logic, `fn` and `parse` receive buffer context:
643+
644+
>lua
645+
lint.fn(prev_lines, fname, cwd)
646+
lint.parse(result, bufnr, fname, cwd)
647+
<
648+
649+
Parameters ~
650+
`prev_lines` — buffer content (string)
651+
`result` — linter output (string)
652+
`bufnr` — target buffer number
653+
`fname` — absolute file path
654+
`cwd` — working directory
655+
656+
Use `fname` and `cwd` when linters output relative paths (e.g.,
657+
`terraform validate` on a directory returns diagnostics for all files).
658+
659+
Filtering `terraform validate` by current file:
660+
661+
>lua
662+
parse = function(result, bufnr, fname, cwd)
663+
local current = fname:sub(#cwd + 2) -- +2 to include '/'
664+
local decoded = vim.json.decode(result)
665+
666+
for _, d in ipairs(decoded.diagnostics or {}) do
667+
-- terraform returns relative filenames; match against current
668+
if d.range and d.range.filename == current then
669+
-- add to diagnostics...
670+
end
671+
end
672+
end
673+
<
674+
675+
640676
TAKE ADVANTAGE OF AUTOCMD EVENTS*guard.nvim-advanced-tips-take-advantage-of-autocmd-events*
641677

642678
Guard exposes a `GuardFmt` user event that you can use. It is called both

0 commit comments

Comments
 (0)