clerk/internal/linter/rule_duplicated_account.go (view raw)
| 1 | package linter |
| 2 | |
| 3 | import "olexsmir.xyz/clerk/journal/ast" |
| 4 | |
| 5 | // DuplicatedAccount flags account declarations that appear more than once. |
| 6 | type DuplicatedAccount struct{} |
| 7 | |
| 8 | func (DuplicatedAccount) ID() RuleID { return "duplicated-account" } |
| 9 | func (DuplicatedAccount) Severity() Severity { return SeverityWarning } |
| 10 | func (d *DuplicatedAccount) CheckJournal(j *ast.Journal) []Find { |
| 11 | var finds []Find |
| 12 | seen := make(map[string]bool) |
| 13 | |
| 14 | for _, entry := range j.Entries { |
| 15 | ad, ok := entry.(*ast.AccountDirective) |
| 16 | if !ok { |
| 17 | continue |
| 18 | } |
| 19 | |
| 20 | name := ad.Account.String() |
| 21 | if seen[name] { |
| 22 | finds = append(finds, Find{ |
| 23 | Code: d.ID(), |
| 24 | Severity: d.Severity(), |
| 25 | Message: "duplicated account declaration: " + name, |
| 26 | Span: ad.Account.Span, |
| 27 | }) |
| 28 | } |
| 29 | seen[name] = true |
| 30 | } |
| 31 | return finds |
| 32 | } |