You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
localcurrent=fname:sub(#cwd+2) -- +2 to include '/'
207
+
localdecoded=vim.json.decode(result)
208
+
209
+
for_, dinipairs(decoded.diagnosticsor {}) do
210
+
-- terraform returns relative filenames; match against current
211
+
ifd.rangeandd.range.filename==currentthen
212
+
-- add to diagnostics...
213
+
end
214
+
end
215
+
end
216
+
```
217
+
183
218
## Take advantage of autocmd events
184
219
185
220
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