|
1 | | -*guard.nvim.txt* For NVIM v0.8.0 Last change: 2026 January 18 |
| 1 | +*guard.nvim.txt* For NVIM v0.8.0 Last change: 2026 January 31 |
2 | 2 |
|
3 | 3 | ============================================================================== |
4 | 4 | Table of Contents *guard.nvim-table-of-contents* |
@@ -637,6 +637,43 @@ That’s what the attributes field does, it extracts them from the json table: |
637 | 637 | Et voilà! |
638 | 638 |
|
639 | 639 |
|
| 640 | +SIGNATURES FOR CUSTOM LINTER FUNCTIONS ~ |
| 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 | + |
| 651 | +- `prev_lines` — buffer content (string) |
| 652 | +- `result` — linter output (string) |
| 653 | +- `bufnr` — target buffer number |
| 654 | +- `fname` — absolute file path |
| 655 | +- `cwd` — working directory |
| 656 | + |
| 657 | +Use `fname` and `cwd` when linters output relative paths (e.g., `terraform |
| 658 | +validate` on a directory returns diagnostics for all files). |
| 659 | + |
| 660 | +**Example** — filtering `terraform validate` by current file: |
| 661 | + |
| 662 | +>lua |
| 663 | + parse = function(result, bufnr, fname, cwd) |
| 664 | + local current = fname:sub(#cwd + 2) -- +2 to include '/' |
| 665 | + local decoded = vim.json.decode(result) |
| 666 | + |
| 667 | + for _, d in ipairs(decoded.diagnostics or {}) do |
| 668 | + -- terraform returns relative filenames; match against current |
| 669 | + if d.range and d.range.filename == current then |
| 670 | + -- add to diagnostics... |
| 671 | + end |
| 672 | + end |
| 673 | + end |
| 674 | +< |
| 675 | + |
| 676 | + |
640 | 677 | TAKE ADVANTAGE OF AUTOCMD EVENTS*guard.nvim-advanced-tips-take-advantage-of-autocmd-events* |
641 | 678 |
|
642 | 679 | Guard exposes a `GuardFmt` user event that you can use. It is called both |
|
0 commit comments