5 files changed,
43 insertions(+),
3 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-06-10 21:52:35 +0300
Authored at:
2026-06-10 21:13:45 +0300
Change ID:
ylwwxqtpntukqvlnunqqukxroloylopy
Parent:
56a4631
M
internal/linter/linter_test.go
··· 9 9 ) 10 10 11 11 var tests = map[string][]Rule{ 12 - "correct": Rules, 13 - "empty-postings": {&EmptyPostings{}}, 14 - "parse-error": {&ParseError{}}, 12 + "correct": Rules, 13 + "empty-postings": {&EmptyPostings{}}, 14 + "parse-error": {&ParseError{}}, 15 + "omitted-precision": {&OmittedPrecision{}}, 15 16 } 16 17 17 18 func TestLinter(t *testing.T) {
A
internal/linter/rule_omitted_precision.go
··· 1 +package linter 2 + 3 +import "olexsmir.xyz/clerk/journal/ast" 4 + 5 +// OmittedPrecision flags amounts with insufficient decimal precision (<2 digits). 6 +type OmittedPrecision struct{} 7 + 8 +func (OmittedPrecision) ID() RuleID { return "omitted-precision" } 9 +func (OmittedPrecision) Severity() Severity { return SeverityWarning } 10 +func (OmittedPrecision) Description() string { return "amount has insufficient precision" } 11 +func (o *OmittedPrecision) 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.QuantityFmt.Precision < 2 { 23 + finds = append(finds, Find{ 24 + Code: o.ID(), 25 + Severity: o.Severity(), 26 + Message: o.Description(), 27 + Span: posting.Amount.Span, 28 + }) 29 + } 30 + } 31 + return finds 32 +}
A
internal/linter/testdata/omitted-precision.golden
··· 1 +omitted-precision.journal:2:9: omitted-precision: amount has insufficient precision 2 +omitted-precision.journal:4:9: omitted-precision: amount has insufficient precision
A
internal/linter/testdata/omitted-precision.input
··· 1 +2026-06-10 * asdf 2 + qwer 1 UIO 3 + asdf 1.00 ASD 4 + zxcv 2 UIO