all repos

clerk @ e12aa47

missing tooling for ledger/hledger

clerk/internal/linter/rule_omitted_precision.go (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
feat: config (#6), 1 month ago
1
package linter
2
3
import "olexsmir.xyz/clerk/internal/analyzer"
4
5
const OmittedPrecisionID RuleID = "omitted-precision"
6
7
// OmittedPrecision flags amounts with insufficient decimal precision (<2 digits).
8
type OmittedPrecision struct{}
9
10
func (OmittedPrecision) ID() RuleID { return OmittedPrecisionID }
11
func (o *OmittedPrecision) CheckJournal(an *analyzer.Analysis) []Find {
12
	var finds []Find
13
	for _, txn := range an.Transactions {
14
		for _, posting := range txn.Postings {
15
			if posting.Amount == nil {
16
				continue
17
			}
18
			if posting.Amount.QuantityFmt.Precision < 2 {
19
				finds = append(finds, Find{
20
					Code:    o.ID(),
21
					Message: "amount has insufficient precision",
22
					Span:    posting.Amount.Span,
23
				})
24
			}
25
		}
26
	}
27
	return finds
28
}