all repos

clerk @ 624171a

missing tooling for ledger/hledger

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

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