Skip to content

Commit

Permalink
Add hledger
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed Aug 10, 2024
1 parent 906cd00 commit ad0fe35
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Other dedicated linters that are built-in are:
| [glslc][glslc] | `glslc` |
| [Golangci-lint][16] | `golangcilint` |
| [hadolint][28] | `hadolint` |
| [hledger][hledger] | `hledger` |
| [hlint][32] | `hlint` |
| [htmlhint][htmlhint] | `htmlhint` |
| [HTML Tidy][12] | `tidy` |
Expand Down Expand Up @@ -541,3 +542,4 @@ busted tests/
[ameba]: https://github.com/crystal-ameba/ameba
[eugene]: https://github.com/kaaveland/eugene
[clippy]: https://github.com/rust-lang/rust-clippy
[hledger]: https://hledger.org/
24 changes: 24 additions & 0 deletions lua/lint/linters/hledger.lua
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
}
35 changes: 35 additions & 0 deletions tests/hledger_spec.lua
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)

0 comments on commit ad0fe35

Please sign in to comment.