all repos

clerk @ ab4f6083f493cb5911c86ae5f723d4519f7d52da

missing tooling for ledger/hledger

clerk/internal/linter/rule_duplicated_commodity.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 DuplicatedCommodityID RuleID = "duplicated-commodity"
10
11
// DuplicatedCommodity flags commodity declarations that appear more than once.
12
type DuplicatedCommodity struct{}
13
14
func (DuplicatedCommodity) ID() RuleID { return DuplicatedCommodityID }
15
func (d *DuplicatedCommodity) CheckJournal(an *analyzer.Analysis) []Find {
16
	var finds []Find
17
	for sym, info := range an.Commodities {
18
		if len(info.Directives) <= 1 {
19
			continue
20
		}
21
		for _, cd := range info.Directives {
22
			finds = append(finds, Find{
23
				Code:    d.ID(),
24
				Message: fmt.Sprintf("duplicated commodity declaration: %s", sym),
25
				Span:    cd.Span,
26
			})
27
		}
28
	}
29
	return finds
30
}