Skip to content

Commit 2c63eca

Browse files
committed
docs: Add linter signatures and terraform example
1 parent cc011d8 commit 2c63eca

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

ADVANCED.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,41 @@ Et voilà!
180180

181181
![image](https://github.com/xiaoshihou514/guard.nvim/assets/108414369/f9137b5a-ae69-494f-9f5b-b6044ae63c86)
182182

183+
### Signatures for custom linter functions
184+
185+
When writing custom lint logic, `fn` and `parse` receive buffer context:
186+
187+
```lua
188+
lint.fn(prev_lines, fname, cwd)
189+
lint.parse(result, bufnr, fname, cwd)
190+
```
191+
192+
**Parameters:**
193+
194+
- `prev_lines` — buffer content (string)
195+
- `result` — linter output (string)
196+
- `bufnr` — target buffer number
197+
- `fname` — absolute file path
198+
- `cwd` — working directory
199+
200+
Use `fname` and `cwd` when linters output relative paths (e.g., `terraform validate` on a directory returns diagnostics for all files).
201+
202+
**Example** — filtering `terraform validate` by current file:
203+
204+
```lua
205+
parse = function(result, bufnr, fname, cwd)
206+
local current = fname:sub(#cwd + 2) -- +2 to include '/'
207+
local decoded = vim.json.decode(result)
208+
209+
for _, d in ipairs(decoded.diagnostics or {}) do
210+
-- terraform returns relative filenames; match against current
211+
if d.range and d.range.filename == current then
212+
-- add to diagnostics...
213+
end
214+
end
215+
end
216+
```
217+
183218
## Take advantage of autocmd events
184219

185220
Guard exposes a `GuardFmt` user event that you can use. It is called both before formatting starts and after it is completely done. To differentiate between pre-format and post-format calls, a `data` table is passed.

0 commit comments

Comments
 (0)