clerk/internal/linter/rule_omitted_precision.go (view raw)
Oleksandr Smirnov
Oleksandr Smirnov
olexsmir@gmail.com linter: remove Description() method, 1 month ago
olexsmir@gmail.com linter: remove Description() method, 1 month ago
| 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 (o *OmittedPrecision) CheckEntry(entry ast.Entry) []Find { |
| 11 | txn, ok := entry.(*ast.Transaction) |
| 12 | if !ok || (txn.Postings != nil && len(txn.Postings) == 0) { |
| 13 | return nil |
| 14 | } |
| 15 | |
| 16 | var finds []Find |
| 17 | for _, posting := range txn.Postings { |
| 18 | if posting.Amount == nil { |
| 19 | continue |
| 20 | } |
| 21 | if posting.Amount.QuantityFmt.Precision < 2 { |
| 22 | finds = append(finds, Find{ |
| 23 | Code: o.ID(), |
| 24 | Severity: o.Severity(), |
| 25 | Message: "amount has insufficient precision", |
| 26 | Span: posting.Amount.Span, |
| 27 | }) |
| 28 | } |
| 29 | } |
| 30 | return finds |
| 31 | } |