clerk/internal/linter/rule_omitted_precision.go (view raw)
| 1 | package linter |
| 2 | |
| 3 | import "olexsmir.xyz/clerk/internal/analyzer" |
| 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 (o *OmittedPrecision) CheckJournal(an *analyzer.Analysis) []Find { |
| 11 | var finds []Find |
| 12 | for _, txn := range an.Transactions { |
| 13 | for _, posting := range txn.Postings { |
| 14 | if posting.Amount == nil { |
| 15 | continue |
| 16 | } |
| 17 | if posting.Amount.QuantityFmt.Precision < 2 { |
| 18 | finds = append(finds, Find{ |
| 19 | Code: o.ID(), |
| 20 | Severity: o.Severity(), |
| 21 | Message: "amount has insufficient precision", |
| 22 | Span: posting.Amount.Span, |
| 23 | }) |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | return finds |
| 28 | } |