all repos

clerk @ 1b9e6e1f8922a34b89b80ea1c5b55997326c3aa5

missing tooling for ledger/hledger

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