clerk/internal/linter/rule_missing_commodity.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 | // 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 (m *MissingCommodity) 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.Commodity == "" { |
| 22 | finds = append(finds, Find{ |
| 23 | Code: m.ID(), |
| 24 | Severity: m.Severity(), |
| 25 | Message: "amount missing commodity", |
| 26 | Span: posting.Amount.Span, |
| 27 | }) |
| 28 | } |
| 29 | } |
| 30 | return finds |
| 31 | } |