5 files changed,
47 insertions(+),
0 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-06-10 21:52:35 +0300
Authored at:
2026-06-10 21:39:54 +0300
Change ID:
oszvyzrrwyullqqltwommvmqsllupmku
Parent:
974dc2d
A
internal/linter/rule_missing_commodity.go
··· 1 +package linter 2 + 3 +import "olexsmir.xyz/clerk/journal/ast" 4 + 5 +// MissingCommodity flags amounts with a missing commodity. 6 +type MissingCommodity struct{} 7 + 8 +func (MissingCommodity) ID() RuleID { return "missing-commodity" } 9 +func (MissingCommodity) Severity() Severity { return SeverityWarning } 10 +func (MissingCommodity) Description() string { return "amount missing commodity" } 11 +func (m *MissingCommodity) CheckEntry(entry ast.Entry) []Find { 12 + txn, ok := entry.(*ast.Transaction) 13 + if !ok || (txn.Postings != nil && len(txn.Postings) == 0) { 14 + return nil 15 + } 16 + 17 + var finds []Find 18 + for _, posting := range txn.Postings { 19 + if posting.Amount == nil { 20 + continue 21 + } 22 + if posting.Amount.Commodity == "" { 23 + finds = append(finds, Find{ 24 + Code: m.ID(), 25 + Severity: m.Severity(), 26 + Message: m.Description(), 27 + Span: posting.Amount.Span, 28 + }) 29 + } 30 + } 31 + return finds 32 +}
A
internal/linter/testdata/missing-commodity.golden
··· 1 +missing-commodity.journal:2:21: missing-commodity: amount missing commodity 2 +missing-commodity.journal:10:21: missing-commodity: amount missing commodity