-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
906cd00
commit ad0fe35
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
return { | ||
cmd = "hledger", | ||
stdin = true, | ||
args = {"check", "-s", "-f", "-"}, | ||
stream = "stderr", | ||
ignore_exitcode = true, | ||
parser = function(output) | ||
--- hledger currently outputs at most one error. | ||
---@type vim.Diagnostic[] | ||
local result = {} | ||
local pattern = "hledger: Error: %-:(%d+):(.*)" | ||
local lnum, msg = output:match(pattern) | ||
if lnum and (tonumber(lnum) or 0) > 0 then | ||
table.insert(result, { | ||
message = msg, | ||
col = 0, | ||
lnum = tonumber(lnum) - 1, | ||
severity = vim.diagnostic.severity.ERROR, | ||
source = "hledger" | ||
}) | ||
end | ||
return result | ||
end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
describe("hledger", function() | ||
local parser = require("lint.linters.hledger").parser | ||
it("no diagnostics on empty output", function() | ||
assert.are.same({}, parser("")) | ||
end) | ||
|
||
it("returns error diagnostic on error output", function() | ||
-- editorconfig-checker-disable | ||
local msg = [[ | ||
| 2024-08-10 * payment | ||
| revenue:dev:customer -1.234,00 EUR | ||
14 | assets:receivable:customer 1.234,00 EUR | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Strict account checking is enabled, and | ||
account "assets:receivable:customer" has not been declared. | ||
Consider adding an account directive. Examples: | ||
account assets:receivable:customer | ||
account assets:receivable:customer ; type:A ; (L,E,R,X,C,V) | ||
]] | ||
-- editorconfig-checker-enable | ||
local output = "hledger: Error: -:14:" .. msg | ||
local expected = { | ||
{ | ||
message = msg, | ||
col = 0, | ||
lnum = 13, | ||
severity = vim.diagnostic.severity.ERROR, | ||
source = "hledger" | ||
}, | ||
} | ||
assert.are.same(expected, parser(output)) | ||
end) | ||
end) |