all repos

clerk @ 17e6766

missing tooling for ledger/hledger

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

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
feat: config (#6), 1 month ago
1
package linter
2
3
import (
4
	"fmt"
5
6
	"olexsmir.xyz/clerk/internal/analyzer"
7
)
8
9
const DuplicatedAccountID RuleID = "duplicated-account"
10
11
// DuplicatedAccount flags account declarations that appear more than once.
12
type DuplicatedAccount struct{}
13
14
func (DuplicatedAccount) ID() RuleID { return DuplicatedAccountID }
15
func (d *DuplicatedAccount) CheckJournal(an *analyzer.Analysis) []Find {
16
	var finds []Find
17
	for _, info := range an.Accounts {
18
		if len(info.Directives) <= 1 {
19
			continue
20
		}
21
		for _, ad := range info.Directives {
22
			finds = append(finds, Find{
23
				Code:    d.ID(),
24
				Message: fmt.Sprintf("duplicated account declaration: %s", ad.Account.String()),
25
				Span:    ad.Account.Span,
26
			})
27
		}
28
	}
29
	return finds
30
}